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

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.

Returns:

  • (Boolean)


144
145
146
147
148
149
# File 'app/models/alchemy/page/page_natures.rb', line 144

def cache_page?
  return false unless caching_enabled?

  page_layout = PageLayout.get(self.page_layout)
  page_layout["cache"] != false && page_layout["searchresults"] != true
end

#cache_versionObject

Returns the version that’s taken for Rails’ recycable cache key.

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.



112
113
114
115
116
117
118
# File 'app/models/alchemy/page/page_natures.rb', line 112

def cache_version
  if Page.current_preview == id
    updated_at.to_s
  else
    published_at.to_s
  end
end

#contains_feed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/alchemy/page/page_natures.rb', line 36

def contains_feed?
  definition["feed"]
end

#definitionObject

Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.



84
85
86
87
88
89
90
91
# File 'app/models/alchemy/page/page_natures.rb', line 84

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_rolesObject



54
55
56
57
58
# File 'app/models/alchemy/page/page_natures.rb', line 54

def editor_roles
  return unless has_limited_editors?

  definition["editable_by"]
end

#expiration_timeObject



16
17
18
# File 'app/models/alchemy/page/page_natures.rb', line 16

def expiration_time
  public_until ? public_until - Time.current : nil
end

#folded?(user_id) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'app/models/alchemy/page/page_natures.rb', line 30

def folded?(user_id)
  return unless Alchemy.user_class < ActiveRecord::Base

  folded_pages.where(user_id: user_id, folded: true).any?
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

Returns:

  • (Boolean)


50
51
52
# File 'app/models/alchemy/page/page_natures.rb', line 50

def has_limited_editors?
  definition["editable_by"].present?
end

#layout_display_nameObject

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.



96
97
98
# File 'app/models/alchemy/page/page_natures.rb', line 96

def layout_display_name
  Alchemy.t(page_layout, scope: "page_layout_names")
end

#layout_partial_nameObject

Returns the name for the layout partial



102
103
104
# File 'app/models/alchemy/page/page_natures.rb', line 102

def layout_partial_name
  page_layout.parameterize.underscore
end

#locked?Boolean

True if page locked_at timestamp and locked_by id are set

Returns:

  • (Boolean)


61
62
63
# File 'app/models/alchemy/page/page_natures.rb', line 61

def locked?
  locked_by? && locked_at?
end

#public?Boolean

Determines if this page has a public version and this version is public.

Returns:

  • (Boolean)

See Also:



12
13
14
# File 'app/models/alchemy/page/page_natures.rb', line 12

def public?
  language.public? && !!public_version&.public?
end

#rootpage?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/alchemy/page/page_natures.rb', line 26

def rootpage?
  !new_record? && parent_id.blank?
end

#statusObject

Returns a Hash describing the status of the Page.



67
68
69
70
71
72
73
# File 'app/models/alchemy/page/page_natures.rb', line 67

def status
  {
    public: public?,
    locked: locked?,
    restricted: restricted?,
  }
end

#status_title(status_type) ⇒ Object

Returns the translated status for given status type.

Parameters:

  • status_type (Symbol)


79
80
81
# File 'app/models/alchemy/page/page_natures.rb', line 79

def status_title(status_type)
  Alchemy.t(status[status_type].to_s, scope: "page_states.#{status_type}")
end

#taggable?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/alchemy/page/page_natures.rb', line 20

def taggable?
  definition["taggable"] == true
end