Sha256: d8e303b50be9e95bbe6accc75bb3755b3d8d5e35ecf02612285108d54c82e68b

Contents?: true

Size: 902 Bytes

Versions: 4

Compression:

Stored size: 902 Bytes

Contents

class Breadcrumbs
  module Render
    class List < Base # :nodoc: all

      attr_reader :list_style

      # @overload
      def initialize(*)
        super
        @list_style = options.delete(:tag) || :ul
      end

      # @overload
      def default_options
        super.merge(:tag => :ul)
      end

      # @overload
      def render
        tag(list_style, options) do
          html = ""
          size = breadcrumbs.size

          breadcrumbs.each_with_index do |item, i|
            html << render_item(item, i, size)
          end

          html
        end
      end

      def render_item(item, i, size)
        css = []
        css << "first" if i == 0
        css << "last" if i == size - 1
        css << "item-#{i}"

        text, url, options = *item
        text = wrap_item(url, escape(text), options)
        tag(:li, text, :class => css.join(" "))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bsm-breadcrumbs-0.5.2 lib/breadcrumbs/render/list.rb
bsm-breadcrumbs-0.5.1 lib/breadcrumbs/render/list.rb
bsm-breadcrumbs-0.5.0 lib/breadcrumbs/render/list.rb
bsm-breadcrumbs-0.4.0 lib/breadcrumbs/render/list.rb