Sha256: 7c770cfab87dc5ecaf7a70f496f45832ba5934f122fe717b46f70be6c19ba03c

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

class Breadcrumbs
  module Render
    class List < Base # :nodoc: all
      def render
        options = {:class => "breadcrumbs"}.merge(default_options)

        tag(:ul, options) do
          html = ""
          items = breadcrumbs.items
          size = items.size

          items.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 = CGI.escapeHTML(text)
        text = tag(:a, text, options.merge(:href => url)) if url

        tag(:li, text, :class => css.join(" "))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
breadcrumbs-0.1.3 lib/breadcrumbs/render/list.rb
breadcrumbs-0.1.2 lib/breadcrumbs/render/list.rb
breadcrumbs-0.1.1 lib/breadcrumbs/render/list.rb