Class: Som::Liquid::Tags::ImprovedLinkTo

Inherits:
Locomotive::Steam::Liquid::Tags::Hybrid
  • Object
show all
Includes:
Locomotive::Steam::Liquid::Tags::Concerns::I18nPage, Locomotive::Steam::Liquid::Tags::Concerns::Path
Defined in:
lib/som/liquid/tags/improved_link_to.rb

Constant Summary collapse

Syntax =
/(#{::Liquid::VariableSignature}+)/o

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ ImprovedLinkTo

Returns a new instance of ImprovedLinkTo.



13
14
15
16
17
# File 'lib/som/liquid/tags/improved_link_to.rb', line 13

def initialize(tag_name, markup, options)
  markup =~ Syntax
  self.set_options(markup, options)
  super
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



11
12
13
# File 'lib/som/liquid/tags/improved_link_to.rb', line 11

def current_page
  @current_page
end

Instance Method Details

#render(context) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/som/liquid/tags/improved_link_to.rb', line 19

def render(context)
  self.current_page = context.registers[:page]

  render_path(context) do |page, path|
    label = label_from_page(page)

    if render_as_block?
      context.stack do
        context.scopes.last['target'] = page
        label = super.html_safe
      end
    end

    tag_attributes = build_tag_attributes(page)
    %{<a #{tag_attributes} href="#{path}">#{label}</a>}
  end
end