Module: Locomotive::PagesHelper
- Defined in:
- app/helpers/locomotive/pages_helper.rb
Instance Method Summary collapse
- #add_children_to_options(page, list) ⇒ Object
- #css_for_page(page) ⇒ Object
- #display_page_layouts? ⇒ Boolean
- #options_for_page_cache_strategy ⇒ Object
- #options_for_page_layouts ⇒ Object
- #options_for_page_redirect_type ⇒ Object
- #options_for_page_response_type ⇒ Object
- #options_for_target_klass_name ⇒ Object
-
#page_main_template_path(page) ⇒ String
Give the path to the template of the page for the main locale ONLY IF the user does not already edit the page in the main locale.
- #page_response_type_to_string(page) ⇒ Object
- #page_toggler(page) ⇒ Object
- #parent_pages_options ⇒ Object
Instance Method Details
#add_children_to_options(page, list) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/locomotive/pages_helper.rb', line 29 def (page, list) return list if page.parent_ids.include?(@page.id) || page == @page offset = '- ' * (page.depth || 0) * 2 list << ["#{offset}#{page.title}", page.id] page.children.each { |child| (child, list) } list end |
#css_for_page(page) ⇒ Object
4 5 6 7 8 9 |
# File 'app/helpers/locomotive/pages_helper.rb', line 4 def css_for_page(page) %w(index not_found templatized redirect unpublished).inject([]) do |memo, state| memo << state.dasherize if page.send(:"#{state}?") memo end.join(' ') end |
#display_page_layouts? ⇒ Boolean
39 40 41 42 |
# File 'app/helpers/locomotive/pages_helper.rb', line 39 def display_page_layouts? ((@page.persisted? && @page.allow_layout?) || !@page.persisted?) && !current_site.pages.layouts.empty? end |
#options_for_page_cache_strategy ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/locomotive/pages_helper.rb', line 58 def [ [t('.cache_strategy.none'), 'none'], [t('.cache_strategy.simple'), 'simple'], [t('.cache_strategy.hour'), 1.hour.to_s], [t('.cache_strategy.day'), 1.day.to_s], [t('.cache_strategy.week'), 1.week.to_s], [t('.cache_strategy.month'), 1.month.to_s] ] end |
#options_for_page_layouts ⇒ Object
44 45 46 47 48 49 |
# File 'app/helpers/locomotive/pages_helper.rb', line 44 def layouts = current_site.pages.layouts.map do |_layout| [_layout.title, _layout._id] end [[t('.no_layout'), nil]] + layouts end |
#options_for_page_redirect_type ⇒ Object
78 79 80 81 82 83 |
# File 'app/helpers/locomotive/pages_helper.rb', line 78 def [ [t('.redirect_type.permanent'), 301], [t('.redirect_type.temporary'), 302] ] end |
#options_for_page_response_type ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/helpers/locomotive/pages_helper.rb', line 69 def [ ['HTML', 'text/html'], ['RSS', 'application/rss+xml'], ['XML', 'text/xml'], ['JSON', 'application/json'] ] end |
#options_for_target_klass_name ⇒ Object
51 52 53 54 55 56 |
# File 'app/helpers/locomotive/pages_helper.rb', line 51 def base_models = current_site.content_types.map do |type| [type.name.humanize, type.klass_with_custom_fields(:entries)] end base_models + Locomotive.config.models_for_templatization.map { |name| [name.underscore.humanize, name] } end |
#page_main_template_path(page) ⇒ String
Give the path to the template of the page for the main locale ONLY IF the user does not already edit the page in the main locale.
96 97 98 99 100 101 102 |
# File 'app/helpers/locomotive/pages_helper.rb', line 96 def page_main_template_path(page) if not_the_default_current_locale? page_path(page, content_locale: current_site.default_locale, format: :json) else nil end end |
#page_response_type_to_string(page) ⇒ Object
85 86 87 |
# File 'app/helpers/locomotive/pages_helper.rb', line 85 def page_response_type_to_string(page) .detect { |t| t.last == page.response_type }.try(:first) || '—' end |
#page_toggler(page) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/locomotive/pages_helper.rb', line 11 def page_toggler(page) icon_class = ["folder-#{page._id}"] != 'none' ? 'icon-caret-down' : 'icon-caret-right' content_tag :i, '', class: "#{icon_class} toggler", data: { open: 'icon-caret-down', closed: 'icon-caret-right' } end |
#parent_pages_options ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/helpers/locomotive/pages_helper.rb', line 21 def [].tap do |list| root = Locomotive::Page.quick_tree(current_site).first (root, list) end end |