Sha256: fc9db7e0fdcf67bed2dcbe72841815183b50a09ae2d073e75c3439a2357364ed
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
require 'jekyll/tags/include' require 'liquid' module GuidesStyle18F class ShouldExpandNavTag < ::Liquid::Tag NAME = 'guides_style_18f_should_expand_nav' ::Liquid::Template.register_tag(NAME, self) attr_reader :parent_reference, :url_reference def initialize(_tag_name, markup, _) references = markup.split(',').map(&:strip) @parent_reference = references.shift @url_reference = references.shift end def render(context) scope = context.scopes.detect { |s| s.member?(url_reference) } parent_url = scope[url_reference] page_url = context['page']['url'] (page_url != parent_url && page_url.start_with?(parent_url)) || ( expand_nav_default(scope, context)) end private def expand_nav_default(scope, context) default = scope[parent_reference]['expand_nav'] default = context['site']['expand_nav'] if default.nil? default.nil? ? false : default end end class PopLastUrlComponent < ::Liquid::Tag NAME = 'guides_style_18f_pop_last_url_component' ::Liquid::Template.register_tag(NAME, self) attr_reader :reference def initialize(_tag_name, markup, _) @reference = markup.strip end def render(context) scope = context.scopes.detect { |s| s.member?(reference) } parent_url = scope[reference] result = File.dirname(parent_url) result == '/' ? result : "#{result}/" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
guides_style_18f-0.1.15 | lib/guides_style_18f/tags.rb |