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_page? ⇒ Boolean
Returns true if the page cache control headers should be set.
-
#cache_version ⇒ Object
Returns the version string that’s taken for Rails’ recycable cache key.
-
#definition ⇒ Object
Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.
- #editor_roles ⇒ Object
-
#expiration_time ⇒ Object
Cache-Control max-age duration in seconds.
- #folded?(user_id) ⇒ Boolean
-
#has_limited_editors? ⇒ Boolean
Returns an Array of Alchemy roles which are able to edit this template.
-
#last_modified_at ⇒ Object
Returns the timestamp that the page was last modified at, regardless of through publishing or editing page, or through a change of related objects through ingredients.
-
#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
Determines if this page has a public version and this version is public.
- #rootpage? ⇒ Boolean
-
#scheduled? ⇒ Boolean
Determines if this page has a public version and this version is scheduled.
-
#status ⇒ Object
Returns a Hash describing the status of the Page.
-
#status_message(status_type) ⇒ Object
Returns the long translated status message for given status type.
-
#status_title(status_type) ⇒ Object
Returns the sort translated status title for given status type.
Instance Method Details
#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.
171 172 173 174 175 |
# File 'app/models/alchemy/page/page_natures.rb', line 171 def cache_page? return false if !public? || restricted? definition.cache != false && definition.searchresults != true end |
#cache_version ⇒ Object
Returns the version string that’s taken for Rails’ recycable cache key.
131 132 133 |
# File 'app/models/alchemy/page/page_natures.rb', line 131 def cache_version last_modified_at&.to_s end |
#definition ⇒ Object
Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.
107 108 109 110 111 112 113 114 |
# File 'app/models/alchemy/page/page_natures.rb', line 107 def definition definition = PageDefinition.get(page_layout) if definition.nil? Logger.warn "Page definition for '#{page_layout}' not found. Please check page_layouts.yml file." return PageDefinition.new end definition end |
#editor_roles ⇒ Object
69 70 71 72 73 |
# File 'app/models/alchemy/page/page_natures.rb', line 69 def editor_roles return unless has_limited_editors? definition.editable_by end |
#expiration_time ⇒ Object
Cache-Control max-age duration in seconds.
You can set this via the ‘ALCHEMY_PAGE_CACHE_MAX_AGE` environment variable, in the `Alchemy.config.page_cache_max_age` configuration option, or in the pages definition in `config/alchemy/page_layouts.yml` file.
Defaults to 600 seconds.
31 32 33 34 35 36 37 38 39 |
# File 'app/models/alchemy/page/page_natures.rb', line 31 def expiration_time return 0 unless cache_page? if definition.cache.to_s.match?(/\d+/) definition.cache.to_i else Alchemy.config.page_cache.max_age end end |
#folded?(user_id) ⇒ Boolean
45 46 47 48 49 50 51 52 53 |
# File 'app/models/alchemy/page/page_natures.rb', line 45 def folded?(user_id) return unless Alchemy.config.user_class < ActiveRecord::Base if folded_pages.loaded? folded_pages.any? { |p| p.folded && p.user_id == user_id } else folded_pages.where(user_id: user_id, folded: true).any? end 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
65 66 67 |
# File 'app/models/alchemy/page/page_natures.rb', line 65 def has_limited_editors? definition.editable_by.present? end |
#last_modified_at ⇒ Object
Returns the timestamp that the page was last modified at, regardless of through publishing or editing page, or through a change of related objects through ingredients. Respects the public version not changing if editing a preview.
In preview mode, it will take the draft version’s updated_at timestamp. In public mode, it will take the public version’s updated_at timestamp.
142 143 144 145 |
# File 'app/models/alchemy/page/page_natures.rb', line 142 def last_modified_at relevant_page_version = (Current.preview_page == self) ? draft_version : public_version relevant_page_version&.updated_at 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.
119 120 121 |
# File 'app/models/alchemy/page/page_natures.rb', line 119 def layout_display_name Alchemy.t(page_layout, scope: "page_layout_names") end |
#layout_partial_name ⇒ Object
Returns the name for the layout partial
125 126 127 |
# File 'app/models/alchemy/page/page_natures.rb', line 125 def layout_partial_name page_layout.parameterize.underscore end |
#locked? ⇒ Boolean
True if page locked_at timestamp and locked_by id are set
76 77 78 |
# File 'app/models/alchemy/page/page_natures.rb', line 76 def locked? locked_by? && locked_at? end |
#public? ⇒ Boolean
Determines if this page has a public version and this version is public.
12 13 14 |
# File 'app/models/alchemy/page/page_natures.rb', line 12 def public? language.public? && !!public_version&.public? end |
#rootpage? ⇒ Boolean
41 42 43 |
# File 'app/models/alchemy/page/page_natures.rb', line 41 def rootpage? !new_record? && parent_id.blank? end |
#scheduled? ⇒ Boolean
Determines if this page has a public version and this version is scheduled.
20 21 22 |
# File 'app/models/alchemy/page/page_natures.rb', line 20 def scheduled? !!public_version&.scheduled? end |
#status ⇒ Object
Returns a Hash describing the status of the Page.
82 83 84 85 86 87 88 |
# File 'app/models/alchemy/page/page_natures.rb', line 82 def status { public: public?, locked: locked?, restricted: restricted? } end |