Module: Occams::CmsHelper
- Defined in:
- app/helpers/occams/cms_helper.rb
Instance Method Summary collapse
-
#cms_fragment_content(identifier, page = @cms_page) ⇒ Object
Raw content of a page fragment.
-
#cms_fragment_render(identifier, page = @cms_page) ⇒ Object
Same as cms_fragment_content but with cms tags expanded and rendered.
- #cms_site_detect ⇒ Object
-
#cms_snippet_content(identifier, cms_site = @cms_site) ⇒ Object
Raw content of a snippet.
-
#cms_snippet_render(identifier, cms_site = @cms_site) ⇒ Object
Same as cms_snippet_content but cms tags will be expanded.
- #occams_paginate(collection) ⇒ Object
Instance Method Details
#cms_fragment_content(identifier, page = @cms_page) ⇒ Object
Raw content of a page fragment. This is how you get content from unrenderable tags like meta, render: false} Example:
cms_fragment_content(:left_column, CmsPage.first)
cms_fragment_content(:left_column) # if @cms_page is present
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/occams/cms_helper.rb', line 10 def cms_fragment_content(identifier, page = @cms_page) frag = page&.fragments&.detect { |f| f.identifier == identifier.to_s } return '' unless frag case frag.tag when 'date', 'datetime' frag.datetime when 'checkbox' frag.boolean when 'file', 'files' frag. else frag.content end end |
#cms_fragment_render(identifier, page = @cms_page) ⇒ Object
Same as cms_fragment_content but with cms tags expanded and rendered. Use it only if you know you got more stuff in the fragment content other than text because this is a potentially expensive call.
29 30 31 32 33 34 35 |
# File 'app/helpers/occams/cms_helper.rb', line 29 def cms_fragment_render(identifier, page = @cms_page) node = page.fragment_nodes.detect { |n| n.identifier == identifier.to_s } return '' unless node node.renderable = true render inline: page.render([node]) end |
#cms_site_detect ⇒ Object
59 60 61 62 63 |
# File 'app/helpers/occams/cms_helper.rb', line 59 def cms_site_detect host = request.host_with_port.downcase path = request.fullpath Occams::Cms::Site.find_site(host, path) end |
#cms_snippet_content(identifier, cms_site = @cms_site) ⇒ Object
Raw content of a snippet. Example:
cms_snippet_content(:my_snippet)
40 41 42 43 44 45 46 |
# File 'app/helpers/occams/cms_helper.rb', line 40 def cms_snippet_content(identifier, cms_site = @cms_site) cms_site ||= cms_site_detect snippet = cms_site&.snippets&.find_by_identifier(identifier) return '' unless snippet snippet.content end |
#cms_snippet_render(identifier, cms_site = @cms_site) ⇒ Object
Same as cms_snippet_content but cms tags will be expanded. Note that there is no page context, so snippet cannot contain fragment tags.
50 51 52 53 54 55 56 57 |
# File 'app/helpers/occams/cms_helper.rb', line 50 def cms_snippet_render(identifier, cms_site = @cms_site) cms_site ||= cms_site_detect snippet = cms_site&.snippets&.find_by_identifier(identifier) return '' unless snippet r = Occams::Content::Renderer.new(snippet) render inline: r.render(r.nodes(r.tokenize(snippet.content))) end |
#occams_paginate(collection) ⇒ Object
65 66 67 68 69 |
# File 'app/helpers/occams/cms_helper.rb', line 65 def occams_paginate(collection) return unless collection paginate collection, theme: 'occams' if defined?(Kaminari) end |