Sha256: 1e51f86201bdb5131832861194c8bf547eec0f0f9d6aaca25ff340b212e391f4
Contents?: true
Size: 1.37 KB
Versions: 12
Compression:
Stored size: 1.37 KB
Contents
module Locomotive module Wagon module Liquid module Tags class LinkTo < Hybrid Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/ include PathHelper def initialize(tag_name, markup, tokens, options) if markup =~ Syntax @handle = $1 @_options = {} markup.scan(::Liquid::TagAttributes) do |key, value| @_options[key] = value end else raise ::Liquid::SyntaxError.new(options[:locale].t("errors.syntax.link_to"), options[:line]) end super end def render(context) render_path(context) do |page, path| label = label_from_page(page) if @render_as_block context.scopes.last['target'] = page label = super.html_safe end %{<a href="#{path}">#{label}</a>} end end protected def label_from_page(page) ::Locomotive::Mounter.with_locale(@_options['locale']) do if page.templatized? page.content_entry._label else page.title end end end end ::Liquid::Template.register_tag('link_to', LinkTo) end end end end
Version data entries
12 entries across 12 versions & 1 rubygems