module Locomotive::Steam::Liquid::Tags::Concerns::Path

Constants

Syntax

Attributes

handle[R]

Public Class Methods

new(tag_name, markup, options) click to toggle source
Calls superclass method
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 12
def initialize(tag_name, markup, options)
  super

  if markup =~ Syntax
    @handle, _attributes = $1, $2

    parse_attributes(_attributes)
  else
    self.wrong_syntax!
  end
end

Public Instance Methods

render_path(context, &block) click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 24
def render_path(context, &block)
  evaluate_attributes(context, lax: true)

  set_vars_from_context(context)

  handle = @context[@handle] || @handle

  # is external url?
  if handle =~ Locomotive::Steam::IsHTTP
    handle
  elsif page = self.retrieve_page_drop_from_handle(handle) # return a drop or model?
    # make sure we've got the page/content entry (if templatized)
    # in the right locale
    change_page_locale(locale, page) do
      path = build_fullpath(page)

      block_given? ? block.call(page, path) : path
    end
  else
    '' # no page found
  end
end

Protected Instance Methods

_retrieve_page_drop_from(handle) click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 70
def _retrieve_page_drop_from(handle)
  if page = services.page_finder.by_handle(handle)
    page.to_liquid.tap { |d| d.context = @context }
  end
end
_retrieve_templatized_page_drop_from(drop) click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 76
def _retrieve_templatized_page_drop_from(drop)
  entry = drop.send(:_source)

  if page = repository.template_for(entry, template_slug)
    page.to_liquid.tap { |d| d.context = @context }
  end
end
build_fullpath(page) click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 84
def build_fullpath(page)
  services.url_builder.url_for(page.send(:_source), locale)
end
locale() click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 88
def locale
  attributes[:locale] || @locale
end
repository() click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 53
def repository
  services.repositories.page
end
retrieve_page_drop_from_handle(handle) click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 57
def retrieve_page_drop_from_handle(handle)
  case handle
  when String
    _retrieve_page_drop_from(handle)
  when Locomotive::Steam::Liquid::Drops::ContentEntry
    _retrieve_templatized_page_drop_from(handle)
  when Locomotive::Steam::Liquid::Drops::Page
    handle
  else
    nil
  end
end
services() click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 49
def services
  @context.registers[:services]
end
set_vars_from_context(context) click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 96
def set_vars_from_context(context)
  @context      = context
  @site         = context.registers[:site]
  @locale       = context.registers[:locale]
end
template_slug() click to toggle source
# File lib/locomotive/steam/liquid/tags/concerns/path.rb, line 92
def template_slug
  attributes[:with]
end