Module: ActionView::Helpers::TextHelper

Defined in:
lib/content_o_matic/text_helper.rb

Instance Method Summary collapse

Instance Method Details

#content_o_matic(slug, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/content_o_matic/text_helper.rb', line 5

def content_o_matic(slug, options = {})
  options = {} if options.nil?
  comments = true
  if options.has_key?(:print_comments)
    comments = options.delete(:print_comments)
  end
  text = "<!-- Loading Content: '#{slug}' -->\n" if comments
  begin
    html_body = true
    if options.has_key?(:html_body)
      html_body = options.delete(:html_body)
    end
    res = ContentOMatic.get(slug, options)
    if res.success?
      if html_body
        text << res.html_body
      else
        text << res.body
      end
    else
      raise res.exception
    end
  rescue Exception => e
    text << "<!-- Error: #{e.message} -->" if comments
  end
  text << "\n<!-- Loaded Content: '#{slug}' -->" if comments
  text
end