Module: Alchemy::Page::PageElements
- Extended by:
- ActiveSupport::Concern
- Included in:
- Alchemy::Page
- Defined in:
- app/models/alchemy/page/page_elements.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#available_element_definitions ⇒ Object
All available element definitions that can actually be placed on current page.
-
#available_element_names ⇒ Object
All names of elements that can actually be placed on current page.
-
#element_definition_names ⇒ Object
All names of elements that are defined in the corresponding page and cell definition.
-
#element_definitions ⇒ Object
All element definitions defined for page’s page layout.
-
#element_definitions_by_name(names) ⇒ Array
Returns Element definitions with given name(s).
- #element_names_from_cell_definition ⇒ Object
- #element_names_from_page_definition ⇒ Object
-
#feed_elements ⇒ Object
Returns all elements that should be feeded via rss.
-
#find_elements(options = {}, show_non_public = false) ⇒ ActiveRecord::Relation
(also: #find_selected_elements)
Finds elements of page.
-
#richtext_contents_ids ⇒ Object
Returns an array of all EssenceRichtext contents ids.
Instance Method Details
#available_element_definitions ⇒ Object
All available element definitions that can actually be placed on current page.
It extracts all definitions that are unique or limited and already on page.
Example of unique element:
- name: headline
unique: true
contents:
- name: headline
type: EssenceText
Example of limited element:
- name: article
amount: 2
contents:
- name: text
type: EssenceRichtext
69 70 71 72 73 74 75 76 |
# File 'app/models/alchemy/page/page_elements.rb', line 69 def available_element_definitions @elements_for_layout ||= element_definitions return [] if @elements_for_layout.blank? @page_element_names = elements.not_trashed.pluck(:name) delete_unique_element_definitions! delete_outnumbered_element_definitions! @elements_for_layout end |
#available_element_names ⇒ Object
All names of elements that can actually be placed on current page.
80 81 82 |
# File 'app/models/alchemy/page/page_elements.rb', line 80 def available_element_names available_element_definitions.collect { |e| e['name'] } end |
#element_definition_names ⇒ Object
All names of elements that are defined in the corresponding page and cell definition.
Assign elements to a page in config/alchemy/page_layouts.yml
and/or config/alchemy/cells.yml
file.
Example of page_layouts.yml:
- name: contact
cells: [right_column]
elements: [headline, contactform]
Example of cells.yml:
- name: right_column
elements: [teaser]
107 108 109 |
# File 'app/models/alchemy/page/page_elements.rb', line 107 def element_definition_names element_names_from_page_definition | element_names_from_cell_definition end |
#element_definitions ⇒ Object
All element definitions defined for page’s page layout
86 87 88 |
# File 'app/models/alchemy/page/page_elements.rb', line 86 def element_definitions element_definitions_by_name(element_definition_names) end |
#element_definitions_by_name(names) ⇒ Array
Returns Element definitions with given name(s)
126 127 128 129 130 131 132 133 |
# File 'app/models/alchemy/page/page_elements.rb', line 126 def element_definitions_by_name(names) return [] if names.blank? if names.to_s == "all" Element.definitions else Element.definitions.select { |e| names.include? e['name'] } end end |
#element_names_from_cell_definition ⇒ Object
115 116 117 |
# File 'app/models/alchemy/page/page_elements.rb', line 115 def element_names_from_cell_definition cell_definitions.map { |d| d['elements'] }.flatten end |
#element_names_from_page_definition ⇒ Object
111 112 113 |
# File 'app/models/alchemy/page/page_elements.rb', line 111 def element_names_from_page_definition definition['elements'] || [] end |
#feed_elements ⇒ Object
Returns all elements that should be feeded via rss.
Define feedable elements in your page_layouts.yml
:
- name: news
feed: true
feed_elements: [element_name, element_2_name]
183 184 185 |
# File 'app/models/alchemy/page/page_elements.rb', line 183 def feed_elements elements.named(definition['feed_elements']) end |
#find_elements(options = {}, show_non_public = false) ⇒ ActiveRecord::Relation Also known as: find_selected_elements
Finds elements of page.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/alchemy/page/page_elements.rb', line 157 def find_elements( = {}, show_non_public = false) elements = elements_from_cell_or_self([:from_cell]) if [:only].present? elements = elements.named([:only]) elsif [:except].present? elements = elements.excluded([:except]) end if [:reverse_sort] || [:reverse] elements = elements.reverse_order end elements = elements.offset([:offset]).limit([:count]) if [:random] elements = elements.order("RAND()") end show_non_public ? elements : elements.published end |
#richtext_contents_ids ⇒ Object
Returns an array of all EssenceRichtext contents ids
189 190 191 |
# File 'app/models/alchemy/page/page_elements.rb', line 189 def richtext_contents_ids contents.essence_richtexts.pluck("#{Content.table_name}.id") end |