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(only_element_named = nil) ⇒ 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
Element definitions with given name(s).
- #element_names_from_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 from not folded elements.
Instance Method Details
#available_element_definitions(only_element_named = nil) ⇒ 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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/alchemy/page/page_elements.rb', line 121 def available_element_definitions(only_element_named = nil) @_element_definitions ||= if only_element_named definition = Element.definition_by_name(only_element_named) element_definitions_by_name(definition['nestable_elements']) else element_definitions end return [] if @_element_definitions.blank? @_existing_element_names = elements.not_trashed.pluck(:name) delete_unique_element_definitions! delete_outnumbered_element_definitions! @_element_definitions end |
#available_element_names ⇒ Object
All names of elements that can actually be placed on current page.
140 141 142 |
# File 'app/models/alchemy/page/page_elements.rb', line 140 def available_element_names @_available_element_names ||= available_element_definitions.map { |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]
170 171 172 |
# File 'app/models/alchemy/page/page_elements.rb', line 170 def element_definition_names element_names_from_definition | element_names_from_cell_definitions end |
#element_definitions ⇒ Object
All element definitions defined for page’s page layout
Warning: Since elements can be unique or limited in number, it is more safe to ask for available_element_definitions
149 150 151 |
# File 'app/models/alchemy/page/page_elements.rb', line 149 def element_definitions @_element_definitions ||= element_definitions_by_name(element_definition_names) end |
#element_definitions_by_name(names) ⇒ Array
Element definitions with given name(s)
181 182 183 184 185 186 187 188 189 |
# File 'app/models/alchemy/page/page_elements.rb', line 181 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_definition ⇒ Object
212 213 214 |
# File 'app/models/alchemy/page/page_elements.rb', line 212 def element_names_from_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]
199 200 201 |
# File 'app/models/alchemy/page/page_elements.rb', line 199 def feed_elements elements.available.named(definition['feed_elements']) end |
#find_elements(options = {}, show_non_public = false) ⇒ ActiveRecord::Relation Also known as: find_selected_elements
Finds elements of page.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/alchemy/page/page_elements.rb', line 83 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 from not folded elements
205 206 207 208 209 210 |
# File 'app/models/alchemy/page/page_elements.rb', line 205 def richtext_contents_ids descendent_contents .where(Element.table_name => {folded: false}) .select(&:has_tinymce?) .collect(&:id) end |