Module: Locomotive::Liquid::Tags::PathHelper

Included in:
LinkTo, PathTo
Defined in:
lib/locomotive/liquid/tags/path_helper.rb

Constant Summary collapse

Syntax =
/(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/

Instance Method Summary collapse

Instance Method Details

#initialize(tag_name, markup, tokens, context) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/locomotive/liquid/tags/path_helper.rb', line 8

def initialize(tag_name, markup, tokens, context)
  if markup =~ Syntax
    @handle = $1
    @options = {}
    markup.scan(::Liquid::TagAttributes) do |key, value|
      @options[key] = value
    end
  else
    self.wrong_syntax!
  end

  super
end

#render_path(context, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/locomotive/liquid/tags/path_helper.rb', line 22

def render_path(context, &block)
  site  = context.registers[:site]

  if page = self.retrieve_page_from_handle(site, context)
    path = self.public_page_fullpath(site, page)

    if block_given?
      block.call page, path
    else
      path
    end
  else
    '' # no page found
  end
end