Class: Jekyll::Categories::CategoryUrlTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Categories::CategoryUrlTag
- Defined in:
- lib/jekyll-categories.rb
Overview
Returns a correctly formatted category url based on site configuration.
Use without arguments to return the url of the category list page.
{% category_url %}
Use with argument to return the url of a specific catogory page. The argument can be either a string or a variable in the current context.
{% category_url category_name %}
{% category_url category_var %}
Instance Method Summary collapse
-
#initialize(tag_name, text, tokens) ⇒ CategoryUrlTag
constructor
A new instance of CategoryUrlTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ CategoryUrlTag
Returns a new instance of CategoryUrlTag.
107 108 109 110 |
# File 'lib/jekyll-categories.rb', line 107 def initialize(tag_name, text, tokens) super @category = text end |
Instance Method Details
#render(context) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/jekyll-categories.rb', line 112 def render(context) base_url = context.registers[:site].config['base-url'] || '/' category_dir = context.registers[:site].config['category_dir'] || 'categories' category = context[@category] || @category.strip.tr(' ', '-').downcase category.empty? ? "#{base_url}#{category_dir}" : "#{base_url}#{category_dir}/#{category}" end |