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)


25
26
27
# File 'lib/nanoc/helpers/tagging.rb', line 25

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

Parameters:

  • tag (String)
  • base_url (String)

Returns:

  • (String)


33
34
35
# File 'lib/nanoc/helpers/tagging.rb', line 33

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) (defaults to: nil)
  • none_text (String) (defaults to: '(none)')
  • separator (String) (defaults to: ', ')

Returns:

  • (String)


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

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