Sha256: 1a6a84a8c80cb331c93128fba48863ff4dfb74f5c88078399c7fec7605a03ebc

Contents?: true

Size: 917 Bytes

Versions: 2

Compression:

Stored size: 917 Bytes

Contents

# frozen_string_literal: true

class Breadcrumbs
  module Render
    class Inline < Base # :nodoc: all
      def render
        options = {
          class: "breadcrumbs",
          separator: "&#187;"
        }.merge(default_options)

        html = []
        items = breadcrumbs.items
        size = items.size

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

        separator = tag(:span, options[:separator], class: "separator")

        html.join(" #{separator} ").html_safe
      end

      def render_item(item, i, size)
        text, url, options = *item

        css = [options[:class]].compact
        css << "first" if i.zero?
        css << "last" if i == size - 1
        css << "item-#{i}"

        options[:class] = css.join(" ")
        options[:class].gsub!(/^ *(.*?)$/, '\\1')

        wrap_item(url, text, options)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
breadcrumbs-0.3.0 lib/breadcrumbs/render/inline.rb
breadcrumbs-0.2.0 lib/breadcrumbs/render/inline.rb