Sha256: 18d305cd90080ea7065440cbb35a49195b77ce27b01a999828dc2902b1e58cb4

Contents?: true

Size: 952 Bytes

Versions: 41

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Helpers
  # @see https://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

41 entries across 41 versions & 1 rubygems

Version Path
nanoc-4.12.19 lib/nanoc/helpers/tagging.rb
nanoc-4.12.18 lib/nanoc/helpers/tagging.rb
nanoc-4.12.17 lib/nanoc/helpers/tagging.rb
nanoc-4.12.16 lib/nanoc/helpers/tagging.rb
nanoc-4.12.15 lib/nanoc/helpers/tagging.rb
nanoc-4.12.14 lib/nanoc/helpers/tagging.rb
nanoc-4.12.13 lib/nanoc/helpers/tagging.rb
nanoc-4.12.12 lib/nanoc/helpers/tagging.rb
nanoc-4.12.11 lib/nanoc/helpers/tagging.rb
nanoc-4.12.10 lib/nanoc/helpers/tagging.rb
nanoc-4.12.9 lib/nanoc/helpers/tagging.rb
nanoc-4.12.8 lib/nanoc/helpers/tagging.rb
nanoc-4.12.7 lib/nanoc/helpers/tagging.rb
nanoc-4.12.6 lib/nanoc/helpers/tagging.rb
nanoc-4.12.5 lib/nanoc/helpers/tagging.rb
nanoc-4.12.4 lib/nanoc/helpers/tagging.rb
nanoc-4.12.3 lib/nanoc/helpers/tagging.rb
nanoc-4.12.2 lib/nanoc/helpers/tagging.rb
nanoc-4.12.1 lib/nanoc/helpers/tagging.rb
nanoc-4.12.0 lib/nanoc/helpers/tagging.rb