Sha256: 8719547c95682dc9120b2673c002c1e9eeb44efee0698d1f27ed09fab4a36f67

Contents?: true

Size: 920 Bytes

Versions: 37

Compression:

Stored size: 920 Bytes

Contents

module Nanoc::Helpers
  # @see http://nanoc.ws/doc/reference/helpers/#tagging
  module Tagging
    require 'nanoc/helpers/html_escape'
    include Nanoc::Helpers::HTMLEscape

    # @param [String] base_url
    # @param [String] none_text
    # @param [String] separator
    #
    # @return [String]
    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

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

    # @param [String] tag
    # @param [String] base_url
    #
    # @return [String]
    def link_for_tag(tag, base_url)
      %(<a href="#{h base_url}#{h tag}" rel="tag">#{h tag}</a>)
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/helpers/tagging.rb
nanoc-4.7.8 lib/nanoc/helpers/tagging.rb
nanoc-4.7.7 lib/nanoc/helpers/tagging.rb
nanoc-4.7.6 lib/nanoc/helpers/tagging.rb
nanoc-4.7.5 lib/nanoc/helpers/tagging.rb
nanoc-4.7.4 lib/nanoc/helpers/tagging.rb
nanoc-4.7.3 lib/nanoc/helpers/tagging.rb
nanoc-4.7.2 lib/nanoc/helpers/tagging.rb
nanoc-4.7.1 lib/nanoc/helpers/tagging.rb
nanoc-4.7.0 lib/nanoc/helpers/tagging.rb
nanoc-4.6.4 lib/nanoc/helpers/tagging.rb
nanoc-4.6.3 lib/nanoc/helpers/tagging.rb
nanoc-4.6.2 lib/nanoc/helpers/tagging.rb
nanoc-4.6.1 lib/nanoc/helpers/tagging.rb
nanoc-4.6.0 lib/nanoc/helpers/tagging.rb
nanoc-4.5.4 lib/nanoc/helpers/tagging.rb
nanoc-4.5.3 lib/nanoc/helpers/tagging.rb
nanoc-4.5.2 lib/nanoc/helpers/tagging.rb
nanoc-4.5.1 lib/nanoc/helpers/tagging.rb
nanoc-4.5.0 lib/nanoc/helpers/tagging.rb