lib/nanoc/toolbox/helpers/tagging_extra.rb
# Returns an Array of links to tags in the item, optionally omits the
# given tags from the selection
#
# @param [Item] item the item from which to extract tags
# @param [Array<String>] omit_tags tags that should be excluded
# @param [Item] options the options for the links to be created
# @option options [String] :tag_pattern ("%%tag%%") The pattern to be replace by the tag name
# @option options [String] :title ("options[:tag_pattern]") The text that will be in the link
# @option options [String] :file_extension (".html") The file extension
# @option options [String] :url_format ("/tags/:tag_pattern:file_extension") The path pattern
#
# @return [Array<String>] An array of html links
#
# @example
#   omited = ['strange_tag']
#   options = { :tag_pattern => "%%TAGNAME%%",
#               :title       => "articles tagged with %%TAGNAME%%",
#               :url_format  => "/tags/tag_%%TAGNAME%%.html"}
#   tag_links_for(item, omited, options) # => ['<a href="/tags/tag_a.html">articles tagged with a</a>', '<a href="/tags/tag_b.html">articles tagged with b</a>']
Returns an Array of links to tags in the item, optionally omits the
given tags from the selection
Returns an Array of links to tags in the item optionally omits the given tags from the selection
def tag_links_for(item, omit_tags=[], options={})
      tags = []
      return tags unless item[:tags]
      options[:tag_pattern]     ||= "%%tag%%"
      options[:title]           ||= options[:tag_pattern]
      options[:file_extension]  ||= ".html"
      options[:url_format]      ||= "/tags/#{options[:tag_pattern]}#{options[:file_extension]}"
      tags = item[:tags] - omit_tags
      tags.map! do |tag|
          title = options[:title].gsub(options[:tag_pattern], tag.downcase)
          url = options[:url_format].gsub(options[:tag_pattern], tag.downcase)
          content_tag('a', title, {:href => url})
      end
    end
def tag_links_for ( item , omit_tags = [ ] , options = { } ) tags = [ ] return tags unless item [ :tags ] options [ :tag_pattern ] ||= "%%tag%%" options [ :title ] ||= options [ :tag_pattern ] options [ :file_extension ] ||= ".html" options [ :url_format ] ||= "/tags/#{options[:tag_pattern]}#{options[:file_extension]}" tags = item [ :tags ] - omit_tags tags . map! do | tag | title = options [ :title ] . gsub ( options [ :tag_pattern ] , tag . downcase ) url = options [ :url_format ] . gsub ( options [ :tag_pattern ] , tag . downcase ) content_tag ( 'a' , title , { :href => url } ) end end
Returns an Array of links to tags in the item, optionally omits the
given tags from the selection
Returns an Array of links to tags in the item optionally omits the given tags from the selection
An array of html links
An array of html links
Array<String>
item
omit_tags
options
:url_format ("/tags/:tag_pattern:file_extension") The path pattern
: url_format ( " / tags / : tag_pattern : file_extension " ) The path pattern
options the options for the links to be created
options the options for the links to be created
example
omited = ['strange_tag'] options = { :tag_pattern => "%%TAGNAME%%", :title => "articles tagged with %%TAGNAME%%", :url_format => "/tags/tag_%%TAGNAME%%.html"} tag_links_for(item, omited, options) # => ['articles tagged with a', 'articles tagged with b']
omited = [ ' strange_tag ' ] options = { : tag_pattern = > " %%TAGNAME%% " : title = > " articles tagged with %%TAGNAME%% " : url_format = > " / tags / tag_%%TAGNAME%% . html " } tag_links_for ( item omited options ) # = > [ ' articles tagged with a ' ' articles tagged with b ' ]