Module: Nanoc3::Helpers::Tagging
- Includes:
- HTMLEscape
- Defined in:
- lib/nanoc3/helpers/tagging.rb
Overview
Provides 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.
Instance Method Summary (collapse)
-
- (Array) items_with_tag(tag)
Find all items with the given tag.
-
- (String) link_for_tag(tag, base_url)
Returns a link to to the specified tag.
-
- (String) tags_for(item, params = {})
Returns a formatted list of tags for the given item as a string.
Methods included from HTMLEscape
Instance Method Details
- (Array) items_with_tag(tag)
Find all items with the given tag.
50 51 52 |
# File 'lib/nanoc3/helpers/tagging.rb', line 50 def items_with_tag(tag) @items.select { |i| (i[:tags] || []).include?(tag) } end |
- (String) link_for_tag(tag, base_url)
Returns a link to to the specified tag. The link is marked up using the
rel-tag microformat. The href attribute of the link will be HTML-
escaped, as will the content of the a element.
and numbers (no spaces, slashes, or other special characters).
construct the link URL. This URL must have a trailing slash.
65 66 67 |
# File 'lib/nanoc3/helpers/tagging.rb', line 65 def link_for_tag(tag, base_url) %[<a href="#{h base_url}#{h tag}" rel="tag">#{h tag}</a>] end |
- (String) tags_for(item, params = {})
Returns a formatted list of tags for the given item as a string. The tags will be linked using the #link<em>for</em>tag function; the HTML-escaping rules for #link<em>for</em>tag apply here as well.
to which the tag will be appended to construct the link URL. This URL must have a trailing slash.
the item has no tags
tags
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nanoc3/helpers/tagging.rb', line 33 def (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 |