Module: Locomotive::Steam::Liquid::Tags::Concerns::Path

Included in:
LinkTo, PathTo, RedirectTo
Defined in:
lib/locomotive/steam/liquid/tags/concerns/path.rb

Constant Summary collapse

Syntax =
/(#{::Liquid::QuotedFragment}+)(\s*,.+)?/o

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



10
11
12
# File 'lib/locomotive/steam/liquid/tags/concerns/path.rb', line 10

def handle
  @handle
end

Instance Method Details

#initialize(tag_name, markup, options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# 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

#render_path(context, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/locomotive/steam/liquid/tags/concerns/path.rb', line 24

def render_path(context, &block)
  evaluate_attributes(context)

  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