Class: Locomotive::PagePresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/locomotive/page_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#__ability, #__depth

Instance Method Summary collapse

Methods inherited from BasePresenter

#_id, #ability?, #after_initialize, #errors, #formatted_time, getters_or_setters_to_hash, getters_to_hash, #html_view?, #include_errors?, setters_to_hash, #site, #true

Methods included from Presentable

#after_initialize, #as_json, #attributes=, #getters, #initialize, #property_options, #setters

Instance Method Details

#as_json_for_html_viewObject

custom as_json ##



77
78
79
# File 'app/presenters/locomotive/page_presenter.rb', line 77

def as_json_for_html_view
  self.as_json(self.getters - %w(raw_template))
end

#editable_elementsObject



57
58
59
# File 'app/presenters/locomotive/page_presenter.rb', line 57

def editable_elements
  self.__source.enabled_editable_elements.map(&:as_json)
end

#editable_elements=(elements) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/presenters/locomotive/page_presenter.rb', line 61

def editable_elements=(elements)
  self.__source.force_serialize_template # initialize the default editable_elements

  elements.each do |attributes|
    block, slug = attributes.delete(:block), attributes.delete(:slug)

    block = nil if block.blank? # change empty string in block to nil

    if element = self.__source.find_editable_element(block, slug)
      element.from_presenter(attributes)
    end
  end
end

#escaped_raw_templateObject

other getters / setters ##



41
42
43
# File 'app/presenters/locomotive/page_presenter.rb', line 41

def escaped_raw_template
  h(self.__source.raw_template)
end

#localized_fullpathsObject



45
46
47
48
49
50
51
# File 'app/presenters/locomotive/page_presenter.rb', line 45

def localized_fullpaths
  {}.tap do |hash|
    self.site.locales.each do |locale|
      hash[locale] = self.site.localized_page_fullpath(self.__source, locale)
    end
  end
end

#parent_fullpath=(fullpath) ⇒ Object



53
54
55
# File 'app/presenters/locomotive/page_presenter.rb', line 53

def parent_fullpath=(fullpath)
  self.__source.parent = self.site.pages.where(fullpath: fullpath).first
end

#titleObject

properties / collections ##



6
# File 'app/presenters/locomotive/page_presenter.rb', line 6

properties  :title, :slug