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_keyObject

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.



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

def cache_key
  if Page.current_preview == self
    "alchemy/pages/#{id}-#{updated_at}"
  else
    "alchemy/pages/#{id}-#{published_at}"
  end
end

#contains_feed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/alchemy/page/page_natures.rb', line 24

def contains_feed?
  definition["feed"]
end

#controller_and_actionObject



37
38
39
40
41
42
43
44
# File 'app/models/alchemy/page/page_natures.rb', line 37

def controller_and_action
  if self.has_controller?
    {
      controller: self.layout_description["controller"].gsub(/(^\b)/, "/#{$1}"),
      action: self.layout_description["action"]
    }
  end
end

#definitionObject Also known as: layout_description

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



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

def definition
  return {} if self.systempage?
  description = PageLayout.get(self.page_layout)
  if description.nil?
    log_warning "Page layout description for `#{self.page_layout}` not found. Please check `page_layouts.yml` file."
    return {}
  end
  description
end

#folded?(user_id) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Returns:

  • (Boolean)


33
34
35
# File 'app/models/alchemy/page/page_natures.rb', line 33

def has_controller?
  !PageLayout.get(self.page_layout).nil? && !PageLayout.get(self.page_layout)["controller"].blank?
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.



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

def layout_display_name
  I18n.t(self.page_layout, :scope => :page_layout_names)
end

#layout_partial_nameObject

Returns the name for the layout partial



86
87
88
# File 'app/models/alchemy/page/page_natures.rb', line 86

def layout_partial_name
  page_layout.parameterize.underscore
end

#published_atObject

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.



109
110
111
# File 'app/models/alchemy/page/page_natures.rb', line 109

def published_at
  read_attribute(:published_at) || updated_at
end

#redirects_to_external?Boolean

Returns true or false if the pages layout_description for config/alchemy/page_layouts.yml contains redirects_to_external: true

Returns:

  • (Boolean)


29
30
31
# File 'app/models/alchemy/page/page_natures.rb', line 29

def redirects_to_external?
  !!definition["redirects_to_external"]
end

#rootpage?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/alchemy/page/page_natures.rb', line 10

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

#statusObject

Returns a Hash describing the status of the Page.



48
49
50
51
52
53
54
55
# File 'app/models/alchemy/page/page_natures.rb', line 48

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

#status_title(status_type) ⇒ Object

Returns the translated status for given status type.

Parameters:

  • status_type (Symbol)


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

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

#systempage?Boolean

Returns:

  • (Boolean)


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

def systempage?
  return true if Page.root.nil?
  rootpage? || (self.parent_id == Page.root.id && !self.language_root?)
end

#taggable?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/models/alchemy/page/page_natures.rb', line 6

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