Sha256: 43e96dbeeb694240ae3edf8a9e6ae07002e237f4b2ed54efc33586a95d2b8e96

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Snipp
  module ActionViewExtension

    # = breadcrumb [ :root, :seach, :item } ], s: "/"
    # @params paths
    # @params options
    def breadcrumb paths, options = {}
      sepalator = " #{options.delete(:sepalator)||options.delete(:s)||'>'} "
      sepalator << '<div itemprop="child" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">'

      i18n_options = options.merge({ scope: [:views, :breadcrumb] })

      bc = []
      paths.each do |e|
        if e.is_a?(Hash)
          body = content_tag :span, e[:label], itemprop: :title
          bc.push link_to body, e[:path], itemprop: :url
        else
          body = content_tag :span, I18n.t(e, i18n_options), itemprop: :title
          bc.push link_to body, send("#{e}_path", options), itemprop: :url
        end 
      end
      code = '<nav class="breadcrumb" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">'
      code << bc.join(sepalator)

      (paths.size - 1).times do
        code << '</div>'
      end
      code << '</nav>'

      return code.html_safe
    end 

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snipp-0.0.2 lib/snipp/helpers/action_view_extension.rb