Module: Alchemy::Page::PageNatures
- Extended by:
- ActiveSupport::Concern
- Included in:
- Alchemy::Page
- Defined in:
- app/models/alchemy/page/page_natures.rb
Instance Method Summary collapse
-
#cache_key ⇒ Object
Returns the key that’s taken for cache path.
-
#cache_page? ⇒ Boolean
Returns true if the page cache control headers should be set.
- #contains_feed? ⇒ Boolean
-
#controller_and_action ⇒ Object
deprecated
Deprecated.
Please use a menu node with an url pointing to your controller path instead.
-
#definition ⇒ Object
Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.
- #editor_roles ⇒ Object
- #expiration_time ⇒ Object
- #folded?(user_id) ⇒ Boolean
- #has_controller? ⇒ Boolean deprecated Deprecated.
-
#has_limited_editors? ⇒ Boolean
Returns an Array of Alchemy roles which are able to edit this template.
-
#layout_display_name ⇒ Object
Returns translated name of the pages page_layout value.
-
#layout_partial_name ⇒ Object
Returns the name for the layout partial.
-
#locked? ⇒ Boolean
True if page locked_at timestamp and locked_by id are set.
- #public? ⇒ Boolean
-
#published_at ⇒ Object
We use the published_at value for the cache_key.
-
#redirects_to_external? ⇒ Boolean
deprecated
Deprecated.
Please use a menu node with an external url instead.
- #rootpage? ⇒ Boolean
-
#status ⇒ Object
Returns a Hash describing the status of the Page.
-
#status_title(status_type) ⇒ Object
Returns the translated status for given status type.
- #systempage? ⇒ Boolean
- #taggable? ⇒ Boolean
Instance Method Details
#cache_key ⇒ Object
Returns the key that’s taken for cache path.
Uses the published_at
value that’s updated when the user publishes the page.
If the page is the current preview it uses the updated_at value as cache key.
134 135 136 137 138 139 140 |
# File 'app/models/alchemy/page/page_natures.rb', line 134 def cache_key if Page.current_preview == self "alchemy/pages/#{id}-#{updated_at}" else "alchemy/pages/#{id}-#{published_at}" end end |
#cache_page? ⇒ Boolean
Returns true if the page cache control headers should be set.
Disable Alchemy’s page caching globally
# config/alchemy/config.yml
...
cache_pages: false
Disable caching on page layout level
# config/alchemy/page_layouts.yml
- name: contact
cache: false
Note:
This only sets the cache control headers and skips rendering of the page body, if the cache is fresh. This does not disable the fragment caching in the views. So if you don’t want a page and it’s elements to be cached, then be sure to not use <% cache element %> in the views.
175 176 177 178 179 |
# File 'app/models/alchemy/page/page_natures.rb', line 175 def cache_page? return false unless caching_enabled? page_layout = PageLayout.get(self.page_layout) page_layout['cache'] != false && page_layout['searchresults'] != true end |
#contains_feed? ⇒ Boolean
34 35 36 |
# File 'app/models/alchemy/page/page_natures.rb', line 34 def contains_feed? definition["feed"] end |
#controller_and_action ⇒ Object
Please use a menu node with an url pointing to your controller path instead.
76 77 78 79 80 81 82 83 |
# File 'app/models/alchemy/page/page_natures.rb', line 76 def controller_and_action if definition['controller'] { controller: definition["controller"].gsub(/(^\b)/, "/#{$1}"), action: definition["action"] } end end |
#definition ⇒ Object
Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.
106 107 108 109 110 111 112 113 |
# File 'app/models/alchemy/page/page_natures.rb', line 106 def definition definition = PageLayout.get(page_layout) if definition.nil? log_warning "Page definition for `#{page_layout}` not found. Please check `page_layouts.yml` file." return {} end definition end |
#editor_roles ⇒ Object
52 53 54 55 |
# File 'app/models/alchemy/page/page_natures.rb', line 52 def editor_roles return unless has_limited_editors? definition["editable_by"] end |
#expiration_time ⇒ Object
12 13 14 |
# File 'app/models/alchemy/page/page_natures.rb', line 12 def expiration_time public_until? ? public_until - Time.current : nil end |
#folded?(user_id) ⇒ Boolean
29 30 31 32 |
# File 'app/models/alchemy/page/page_natures.rb', line 29 def folded?(user_id) return unless Alchemy.user_class < ActiveRecord::Base folded_pages.where(user_id: user_id, folded: true).any? end |
#has_controller? ⇒ Boolean
65 66 67 |
# File 'app/models/alchemy/page/page_natures.rb', line 65 def has_controller? !PageLayout.get(page_layout).nil? && !PageLayout.get(page_layout)["controller"].blank? end |
#has_limited_editors? ⇒ Boolean
Returns an Array of Alchemy roles which are able to edit this template
# config/alchemy/page_layouts.yml
- name: contact
editable_by:
- freelancer
- admin
48 49 50 |
# File 'app/models/alchemy/page/page_natures.rb', line 48 def has_limited_editors? definition["editable_by"].present? end |
#layout_display_name ⇒ Object
Returns translated name of the pages page_layout value. Page layout names are defined inside the config/alchemy/page_layouts.yml file. Translate the name in your config/locales language yml file.
118 119 120 |
# File 'app/models/alchemy/page/page_natures.rb', line 118 def layout_display_name Alchemy.t(page_layout, scope: 'page_layout_names') end |
#layout_partial_name ⇒ Object
Returns the name for the layout partial
124 125 126 |
# File 'app/models/alchemy/page/page_natures.rb', line 124 def layout_partial_name page_layout.parameterize.underscore end |
#locked? ⇒ Boolean
True if page locked_at timestamp and locked_by id are set
71 72 73 |
# File 'app/models/alchemy/page/page_natures.rb', line 71 def locked? locked_by? && locked_at? end |
#public? ⇒ Boolean
7 8 9 10 |
# File 'app/models/alchemy/page/page_natures.rb', line 7 def public? current_time = Time.current already_public_for?(current_time) && still_public_for?(current_time) end |
#published_at ⇒ Object
We use the published_at value for the cache_key.
If no published_at value is set yet, i.e. because it was never published, we return the updated_at value.
147 148 149 |
# File 'app/models/alchemy/page/page_natures.rb', line 147 def published_at read_attribute(:published_at) || updated_at end |
#redirects_to_external? ⇒ Boolean
Please use a menu node with an external url instead.
Returns true or false if the pages definition for config/alchemy/page_layouts.yml contains redirects_to_external: true
59 60 61 |
# File 'app/models/alchemy/page/page_natures.rb', line 59 def redirects_to_external? !!definition["redirects_to_external"] end |
#rootpage? ⇒ Boolean
20 21 22 |
# File 'app/models/alchemy/page/page_natures.rb', line 20 def rootpage? !new_record? && parent_id.blank? end |
#status ⇒ Object
Returns a Hash describing the status of the Page.
88 89 90 91 92 93 94 95 |
# File 'app/models/alchemy/page/page_natures.rb', line 88 def status { public: public?, visible: visible?, locked: locked?, restricted: restricted? } end |
#status_title(status_type) ⇒ Object
Returns the translated status for given status type.
101 102 103 |
# File 'app/models/alchemy/page/page_natures.rb', line 101 def status_title(status_type) Alchemy.t(status[status_type].to_s, scope: "page_states.#{status_type}") end |
#systempage? ⇒ Boolean
24 25 26 27 |
# File 'app/models/alchemy/page/page_natures.rb', line 24 def systempage? return true if Page.count.zero? rootpage? || (parent_id == Page.root.id && !language_root?) end |
#taggable? ⇒ Boolean
16 17 18 |
# File 'app/models/alchemy/page/page_natures.rb', line 16 def taggable? definition['taggable'] == true end |