Module: Nanoc::Helpers::Tagging

Includes:
HTMLEscape
Defined in:
lib/nanoc/helpers/tagging.rb

Overview

Instance Method Summary collapse

Methods included from HTMLEscape

#html_escape

Methods included from Capturing

#capture, #content_for

Instance Method Details

#items_with_tag(tag) ⇒ Array

Parameters:

  • tag (String)

Returns:

  • (Array)


23
24
25
# File 'lib/nanoc/helpers/tagging.rb', line 23

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

Parameters:

  • tag (String)
  • base_url (String)

Returns:

  • (String)


31
32
33
# File 'lib/nanoc/helpers/tagging.rb', line 31

def link_for_tag(tag, base_url)
  %(<a href="#{h base_url}#{h tag}" rel="tag">#{h tag}</a>)
end

#tags_for(item, base_url: nil, none_text: '(none)', separator: ', ') ⇒ String

Parameters:

  • base_url (String)
  • none_text (String)
  • separator (String)

Returns:

  • (String)


12
13
14
15
16
17
18
# File 'lib/nanoc/helpers/tagging.rb', line 12

def tags_for(item, base_url: nil, none_text: '(none)', separator: ', ')
  if item[:tags].nil? || item[:tags].empty?
    none_text
  else
    item[:tags].map { |tag| base_url ? link_for_tag(tag, base_url) : tag }.join(separator)
  end
end