Module: ActionView::Helpers::TextHelper
- Defined in:
- lib/content_o_matic/text_helper.rb
Instance Method Summary collapse
-
#content_o_matic(slug, options = {}) ⇒ Object
This convenience method automatically plugs into Rails views, however, this module could easily be included in a non-Rails environment.
Instance Method Details
#content_o_matic(slug, options = {}) ⇒ Object
This convenience method automatically plugs into Rails views, however, this module could easily be included in a non-Rails environment.
This method wraps the ContentOMatic.get method with some nice HTML comments to let you know what has been loaded. It also normalizes links in that content by default. See ContentOMatic::Response body for more information on normalizing links.
This method will also, by default, return just the contents of the HTML ‘body’ tag.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/content_o_matic/text_helper.rb', line 15 def content_o_matic(slug, = {}) = {} if .nil? = {:print_comments => true, :html_body => true, :normalize_assets => true}.merge() comments = .delete(:print_comments) html_body = .delete(:html_body) normalize_assets = .delete(:normalize_assets) text = "<!-- Loading Content: '#{slug}' -->\n" if comments begin res = ContentOMatic.get(slug, ) if res.success? if html_body text << res.html_body(normalize_assets) else text << res.body(normalize_assets) end else raise res.exception end rescue Exception => e text << "<!-- Error: #{e.} -->" if comments end text << "\n<!-- Loaded Content: '#{slug}' -->" if comments text end |