Module: Nanoc3::Helpers::Tagging

Nanoc3::Helpers::Tagging provides some support for managing tags added to items. To add tags to items, set the tags attribute to an array of tags that should be applied to the item. For example:

  tags: [ 'foo', 'bar', 'baz' ]

To activate this helper, include it, like this:

  include Nanoc3::Helpers::Tagging

Public Visibility

Public Instance Method Summary

#items_with_tag(tag)

Returns all items with the given tag.

#link_for_tag(tag, base_url)

Returns a link to to the specified tag.

#tags_for(item, params = {})

Returns a formatted list of tags for the given item as a string.

Public Instance Method Details

items_with_tag

public items_with_tag(tag)

Returns all items with the given tag.

[View source]


40
41
42
# File 'lib/nanoc3/helpers/tagging.rb', line 40

def items_with_tag(tag)
  @items.select { |i| (i[:tags] || []).include?(tag) }
end

link_for_tag

tags_for

public tags_for(item, params = {})

Returns a formatted list of tags for the given item as a string. Several parameters allow customization:

:base_url:The URL to which the tag will be appended to construct the link URL. This URL must have a trailing slash. Defaults to "http://technorati.com/tag/".
:none_text:The text to display when the item has no tags. Defaults to "(none)".
:separator:The separator to put between tags. Defaults to ", ".
[View source]


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nanoc3/helpers/tagging.rb', line 27

def tags_for(item, params={})
  base_url  = params[:base_url]  || 'http://technorati.com/tag/'
  none_text = params[:none_text] || '(none)'
  separator = params[:separator] || ', '

  if item[:tags].nil? or item[:tags].empty?
    none_text
  else
    item[:tags].map { |tag| link_for_tag(tag, base_url) }.join(separator)
  end
end
Generated on Sunday, August 09 2009 at 01:43:06 PM by YARD 0.2.3.2 (ruby-1.8.7).