Class: Jekyll::UJPowertools::UrlMatchesTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::UJPowertools::UrlMatchesTag
- Includes:
- VariableResolver
- Defined in:
- lib/tags/urlmatches.rb
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ UrlMatchesTag
constructor
A new instance of UrlMatchesTag.
- #render(context) ⇒ Object
Methods included from VariableResolver
#is_quoted?, #parse_arguments, #parse_options, #resolve_input, #resolve_variable
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ UrlMatchesTag
Returns a new instance of UrlMatchesTag.
10 11 12 13 14 15 16 |
# File 'lib/tags/urlmatches.rb', line 10 def initialize(tag_name, markup, tokens) super # Parse arguments: url, output_if_active args = parse_arguments(markup) @url = args[0] || '' @output = args[1] || 'active' end |
Instance Method Details
#render(context) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tags/urlmatches.rb', line 18 def render(context) # Get the current page URL page_url = context['page']['url'] # Resolve the URL to check (handles both literals and variables) check_url = resolve_input(context, @url, true) # Resolve the output (handles both literals and variables) output = resolve_input(context, @output, true) # Normalize URLs to handle index pages # /about/index.html becomes /about/ # / stays as / normalized_page_url = normalize_url(page_url) normalized_check_url = normalize_url(check_url) # Return output if URLs match, empty string otherwise if normalized_page_url == normalized_check_url output else "" end end |