class Octopress::Ink::Tags::CategoryTag

Public Class Methods

new(tag, input, tokens) click to toggle source
Calls superclass method
# File lib/octopress-ink/tags/category_tag.rb, line 5
def initialize(tag, input, tokens)
  super
  @tag    = tag
  if !input.nil?
    @input  = input.strip
  end
end

Public Instance Methods

item_list?() click to toggle source
# File lib/octopress-ink/tags/category_tag.rb, line 53
def item_list?
  @tag.end_with? '_list'
end
item_name() click to toggle source
# File lib/octopress-ink/tags/category_tag.rb, line 57
def item_name
  @tag.match('tag') ? 'tag' : 'category'
end
item_name_plural() click to toggle source
# File lib/octopress-ink/tags/category_tag.rb, line 61
def item_name_plural
  @tag.match('tag') ? 'tags' : 'categories'
end
item_tags(page) click to toggle source
# File lib/octopress-ink/tags/category_tag.rb, line 31
def item_tags(page)
  items = page[item_name_plural]

  return nil if items.nil? || items.empty?

  items = items.sort.map { |i| item_link(page, i) }.compact.map do |link|
    if item_list?
      link = %Q{<li class="#{item_name}-list-item">#{link}</li>}
    end

    link
  end

  return nil if items.empty?

  if item_list?
    %Q{<ul class="#{item_name}-list">#{items.join}</ul>}
  else
    %Q{<span class="#{item_name}-links">#{items.join(', ')}</span>}
  end
end
render(context) click to toggle source
# File lib/octopress-ink/tags/category_tag.rb, line 13
def render(context)
  @context = context

  # Check to see if post loop is active, otherwise default to current page
  page = context['post'] || context['page']

  tags = Bootstrap.send(@tag)[page['url']]

  if tags.nil?
    if tags = item_tags(page)
      # Cache tags to speed up multiple references for the same post
      Bootstrap.send(@tag)[page['url']] = tags
    end
  end

  tags
end