Module: ContentItem

Included in:
Blog, Page, Posting
Defined in:
lib/content_items/content_item.rb

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)

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)
  options = [
             :hard_wrap, :filter_html, :filter_styles, :autolink,
             :no_intraemphasis, :fenced_code, :gh_blockcode
            ]
  doc = Nokogiri::HTML(Redcarpet.new(txt, *options).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 normalized_tags_with_weight(resource)
  max_weight = resource.tags_with_weight.map{|t,w| w}.max{ |a,b| a.round <=> b.round }
  resource.tags_with_weight.map do |tag,weight|
    [tag, (8/max_weight*weight).round]
  end
end