Class: PufferPages::Backends::PagePart
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PufferPages::Backends::PagePart
- Includes:
- ActiveUUID::UUID, Mixins::Importable, Mixins::Renderable, Mixins::Translatable
- Defined in:
- lib/puffer_pages/backends/models/page_part.rb
Direct Known Subclasses
Instance Method Summary collapse
- #additional_render_options ⇒ Object
- #ancestors ⇒ Object
- #defaultize_attributes ⇒ Object
- #handle(*args) ⇒ Object
- #i18n_defaults ⇒ Object
- #i18n_scope ⇒ Object
- #main? ⇒ Boolean
- #parent ⇒ Object
- #render(*args) ⇒ Object
- #self_and_ancestors ⇒ Object
Methods included from Mixins::Renderable
Instance Method Details
#additional_render_options ⇒ Object
49 50 51 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 49 def { environment: { processed: self } } end |
#ancestors ⇒ Object
31 32 33 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 31 def ancestors page.ancestors_page_parts.where(name: name) end |
#defaultize_attributes ⇒ Object
19 20 21 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 19 def defaultize_attributes self.handler ||= 'html' end |
#handle(*args) ⇒ Object
44 45 46 47 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 44 def handle *args _, context = *args PufferPages::Handlers.process handler || 'html', self, context end |
#i18n_defaults ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 57 def i18n_defaults page.segments.inject([]) do |memo, element| memo.push (memo.last || []).dup.push(element) end.unshift([]).inject([]) do |memo, segments| memo.unshift i18n_scope_for(segments) memo.unshift i18n_scope_for(segments, :page_parts, name) end end |
#i18n_scope ⇒ Object
53 54 55 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 53 def i18n_scope i18n_scope_for page.segments, :page_parts, name end |
#main? ⇒ Boolean
23 24 25 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 23 def main? name == PufferPages.primary_page_part_name end |
#parent ⇒ Object
27 28 29 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 27 def parent ancestors.first end |
#render(*args) ⇒ Object
39 40 41 42 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 39 def render *args _, context = *args render_template body, context, end |
#self_and_ancestors ⇒ Object
35 36 37 |
# File 'lib/puffer_pages/backends/models/page_part.rb', line 35 def self_and_ancestors page.self_and_ancestors_page_parts.where(name: name) end |