Module: DmCms::PagesHelper
- Defined in:
- app/helpers/dm_cms/pages_helper.rb
Overview
Handles building the different content streams for a page
Instance Method Summary collapse
-
#allow_page_in_menu?(page) ⇒ Boolean
return true if the page should be allowed to be dislpayed in a menu ——————————————————————————.
-
#content_by_name(name) ⇒ Object
Given the name of a container, queries for all content items for that container within the given page.
-
#content_by_name?(name) ⇒ Boolean
Given the name of a container, check if any content is available ——————————————————————————.
-
#main_menu(options = {}) ⇒ Object
Generates a simple multi-level page menu including children ——————————————————————————.
-
#main_menu_select(options = {}) ⇒ Object
——————————————————————————.
-
#menu_from_pages(pages, options = {}) ⇒ Object
——————————————————————————.
-
#menu_from_pages_bs3(pages, options = {}) ⇒ Object
Creates a standard Bootstrap 3 version of a main menu ——————————————————————————.
-
#page_link(page, text = nil, options = {}) ⇒ Object
return a link to the page’s slug, with the passed in link text ——————————————————————————.
-
#page_url(slug, locale = DmCore::Language.locale) ⇒ Object
Easy way to get a page url slug can either be a string, or a CmsPage object ——————————————————————————.
-
#render_content_item(content_item) ⇒ Object
——————————————————————————.
-
#snippet(slug) ⇒ Object
——————————————————————————.
-
#snippet?(slug) ⇒ Boolean
——————————————————————————.
Instance Method Details
#allow_page_in_menu?(page) ⇒ Boolean
return true if the page should be allowed to be dislpayed in a menu
137 138 139 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 137 def (page) page.present? && (page.is_published? || is_admin?) && (page) && !page..blank? end |
#content_by_name(name) ⇒ Object
Given the name of a container, queries for all content items for that container within the given page.
15 16 17 18 19 20 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 15 def content_by_name( name ) unless @current_page.nil? items = @current_page.cms_contentitems.where(container: name) render :partial => (items.nil? ? 'not_found' : 'content_fragment'), :collection => items end end |
#content_by_name?(name) ⇒ Boolean
Given the name of a container, check if any content is available
24 25 26 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 24 def content_by_name?(name) (@current_page.nil? || @current_page.cms_contentitems.where(container: name).count == 0) ? false : true end |
#main_menu(options = {}) ⇒ Object
Generates a simple multi-level page menu including children
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 67 def ( = {}) return '' if (root = CmsPage.roots[0]).nil? = '' [:ul] = '' [:ul] += "class='#{options[:class]}' " unless [:class].blank? [:ul] += "id='#{options[:id]}' " unless [:id].blank? [:include_root] = root if [:include_home] [:active_class] ||= 'current' children = root.subtree.includes(:translations).arrange(order: :row_order).to_a[0][1] , = ([:type] == :bs3 ? (children, ) : (children, )) return .html_safe end |
#main_menu_select(options = {}) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 142 def ( = {}) return '' if (root = CmsPage.roots[0]).nil? [:id] ||= '' [:class] ||= '' [:include_root] = root if [:include_home] pages = root.subtree.includes(:translations).arrange(order: :row_order).to_a[0][1] = "<select id='#{options[:id]}' class='#{options[:class]}'>" += "<option value='' selected='selected'>#{nls(:main_menu_select_prompt)}</option>" if [:include_home] += "<option value='#{dm_cms.showpage_url(root.slug)}'>#{root.menutitle}</option>" end pages.each do |page, children| if (page) += "<option value='#{dm_cms.showpage_url(page.slug)}'>#{page.menutitle}</option>" end end += "</select>" return .html_safe end |
#menu_from_pages(pages, options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 82 def (pages, = {}) [:ul] ||= '' = '' active_found = false if (root = [:include_root]) active = (current_page?(root) ? [:active_class] : nil) active_found ||= !active.nil? += content_tag :li, page_link(root), class: active end pages.each do |page, children| if (page) , = (children.empty? ? '' : (children, active_class: [:active_class])) active = ( || current_page?(page) ? [:active_class] : nil) active_found ||= !active.nil? += content_tag(:li, class: active) do page_link(page) + .html_safe end end end return (.blank? ? '' : "<ul #{options[:ul]}>#{menu_str}</ul>"), active_found end |
#menu_from_pages_bs3(pages, options = {}) ⇒ Object
Creates a standard Bootstrap 3 version of a main menu
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 107 def (pages, = {}) [:ul] ||= '' = '' active_found = false if (root = [:include_root]) active = (current_page?(root) ? [:active_class] : nil) active_found ||= !active.nil? += content_tag :li, page_link(root), class: active end pages.each do |page, children| if (page) , = (children.empty? ? '' : (children, ul: 'class="dropdown-menu"', active_class: [:active_class])) active = ( || current_page?(page) ? [:active_class] : nil) active_found ||= !active.nil? if !.blank? += content_tag(:li, class: ['dropdown', active].join(' ')) do page_link(page, ''.html_safe + page. + ' <b class="caret"></b>'.html_safe, class: 'dropdown-toggle', data: {toggle: 'dropdown'}) + .html_safe end else += content_tag :li, page_link(page), class: active end end end return (.blank? ? '' : "<ul #{options[:ul]}>#{menu_str}</ul>"), active_found end |
#page_link(page, text = nil, options = {}) ⇒ Object
return a link to the page’s slug, with the passed in link text
164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 164 def page_link(page, text = nil, = {}) text ||= page. case page.pagetype when 'link' link_to text, page.link || dm_cms.showpage_url(page.slug), when 'link-new-window' link_to text, page.link || dm_cms.showpage_url(page.slug), .merge(target: '_blank') else link_to text, dm_cms.showpage_url(page.slug), end end |
#page_url(slug, locale = DmCore::Language.locale) ⇒ Object
Easy way to get a page url slug can either be a string, or a CmsPage object
8 9 10 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 8 def page_url(slug, locale = DmCore::Language.locale) showpage_url(:locale => locale, :slug => (slug.kind_of?(CmsPage) ? slug.slug : slug)) end |
#render_content_item(content_item) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 44 def render_content_item(content_item) if content_item.content.blank? content = '' else # --- process content type liquid_params = content_item.to_liquid liquid_params.reverse_merge!(current_user.to_liquid) if current_user case content_item.itemtype.downcase when 'textile' content = liquidize_textile(content_item.content, liquid_params) when 'markdown' content = liquidize_markdown(content_item.content, liquid_params) when 'html' content = liquidize_html(content_item.content, liquid_params) else content = '' end end return content end |
#snippet(slug) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 29 def snippet(slug) cms_snippet = CmsSnippet.find_by_slug(slug) if cms_snippet render :partial => 'dm_cms/pages/snippet_fragment', locals: {snippet_fragment: cms_snippet} else render text: 'Snippet not found' end end |
#snippet?(slug) ⇒ Boolean
39 40 41 |
# File 'app/helpers/dm_cms/pages_helper.rb', line 39 def snippet?(slug) CmsSnippet.where(slug: slug).count == 0 ? false : true end |