Module: ContentItem
Overview
The ContentItem-class within this module can be used to make any model in your application to be ‘blogabble’. Just derive from ContentItems::ContentItem
Defined Under Namespace
Modules: ClassMethods
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) markdown(txt)
Render :txt as markdown with Redcarpet.
-
- (Object) normalized_tags_with_weight(resource)
normalize tags.
Class Method Details
+ (Object) included(base)
5 6 7 |
# File 'lib/content_items/content_item.rb', line 5 def self.included(base) base.extend ContentItem::ClassMethods end |
Instance Method Details
- (Object) markdown(txt)
Render :txt as markdown with Redcarpet
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/content_items/content_item.rb', line 12 def markdown(txt) = [ :hard_wrap, :filter_html, :filter_styles, :autolink, :no_intraemphasis, :fenced_code, :gh_blockcode ] doc = Nokogiri::HTML(Redcarpet.new(txt, *).to_html) doc.search("//pre[@lang]").each do |pre| pre.replace Albino.colorize(pre.text.rstrip, pre[:lang]) end doc.xpath('//body').to_s.gsub(/<\/?body>/,"").html_safe end |
- (Object) normalized_tags_with_weight(resource)
normalize tags
25 26 27 28 29 30 |
# File 'lib/content_items/content_item.rb', line 25 def (resource) max_weight = resource..map{|t,w| w}.max{ |a,b| a.round <=> b.round } resource..map do |tag,weight| [tag, (8/max_weight*weight).round] end end |