class Locomotive::Steam::Liquid::Drops::Page

Public Instance Methods

breadcrumbs() click to toggle source
children() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 45
def children
  @children ||= liquify(*repository.children_of(@_source))
end
content_type() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 49
def content_type
  if @_source.templatized?
    # content_type can be either the slug of a content type or a content type
    content_type = content_type_repository.find(@_source.content_type_id)
    ContentEntryCollection.new(content_type)
  else
    nil
  end
end
editable_elements() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 59
def editable_elements
  @editable_elements_hash ||= build_editable_elements_hash
end
original_slug() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 26
def original_slug
  @_source.slug
end
original_title() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 22
def original_title
  @_source.title
end
parent() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 30
def parent
  @parent ||= repository.parent_of(@_source).to_liquid
end
slug() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 17
def slug
  slug = @_source.templatized? ? @context['entry'].try(:_slug).try(:singularize) : nil
  slug || @_source.slug
end
title() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 12
def title
  title =  @_source.templatized? ? @context['entry'].try(:_label) : nil
  title || @_source.title
end

Private Instance Methods

_build_default_editable_elements_hash(hash) click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 83
def _build_default_editable_elements_hash(hash)
  (@context.registers[:default_editable_content] || []).each do |key, content|
    keys = key.split('/')
    _build_editable_elements_hashes(hash, keys, keys.pop, content)
  end
end
_build_editable_elements_hash(hash) click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 90
def _build_editable_elements_hash(hash)
  (repository.editable_elements_of(@_source) || []).each do |el|
    keys = el.block.try(:split, '/').try(:compact) || []

    # decorate the el instance which is localized because
    # el.content returns a I18nField.
    content = editable_element_content(el)

    _build_editable_elements_hashes(hash, keys, el.slug, content)
  end
end
_build_editable_elements_hashes(hash, keys, slug, content) click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 108
def _build_editable_elements_hashes(hash, keys, slug, content)
  last_hash = hash

  # go the last hash
  keys.each do |key|
    safe_key  = key.parameterize.underscore
    last_hash = (last_hash[safe_key] ||= {})
  end

  last_hash[slug.parameterize.underscore] = content
end
build_editable_elements_hash() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 73
def build_editable_elements_hash
  {}.tap do |hash|
    # default content from the template itself
    _build_default_editable_elements_hash(hash)

    # content updated by the users
    _build_editable_elements_hash(hash)
  end
end
content_type_repository() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 69
def content_type_repository
  @context.registers[:services].repositories.content_type
end
editable_element_content(element) click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 102
def editable_element_content(element)
  Locomotive::Steam::Decorators::I18nDecorator.new(element,
    @_source.__locale__,
    @_source.__default_locale__).content
end
repository() click to toggle source
# File lib/locomotive/steam/liquid/drops/page.rb, line 65
def repository
  @context.registers[:services].repositories.page
end