Class: PufferPages::Backends::PagePart

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveUUID::UUID, Mixins::Importable, Mixins::Renderable, Mixins::Translatable
Defined in:
lib/puffer_pages/backends/models/page_part.rb

Direct Known Subclasses

PagePart

Instance Method Summary collapse

Methods included from Mixins::Renderable

#template

Instance Method Details

#additional_render_optionsObject



49
50
51
# File 'lib/puffer_pages/backends/models/page_part.rb', line 49

def additional_render_options
  { environment: { processed: self } }
end

#ancestorsObject



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_attributesObject



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 = normalize_render_options *args
  PufferPages::Handlers.process handler || 'html', self, context
end

#i18n_defaultsObject



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_scopeObject



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/puffer_pages/backends/models/page_part.rb', line 23

def main?
  name == PufferPages.primary_page_part_name
end

#parentObject



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 = normalize_render_options *args
  render_template body, context, additional_render_options
end

#self_and_ancestorsObject



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