Sha256: 519055fa6bae479b40ac01f2e5968e62fb615febf8a64d7c90d2d41f8c85b3f7

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'breadcrumbs_on_rails'

module LayMeOut
  class BreadcrumbBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
    def render
      set_option_defaults
      @elements.collect{ |element| render_element(element) }.join
    end

    private

    def render_element(element)
      translate_element_options_for(element)
      wrap_content content_for(element)
    end

    def wrap_content(content)
      if @options[:tag]
        @context.content_tag(@options[:tag], content)
      else
        content
      end
    end

    def content_for(element)
      if element.path == nil
        compute_name(element)
      else
        @context.link_to(compute_name(element), compute_path(element), element.options)
      end
    end

    def set_option_defaults
      @options.reverse_merge!(:tag => :p)

      # This line is here due to a bug in breadcrumbs_on_rails
      # A pull request has been submitted with a fix: https://github.com/weppos/breadcrumbs_on_rails/pull/46.
      # Once this pull request is merged, this can be removed.
      @elements.first.options[:home] = true if @elements.first
    end

    def translate_element_options_for(element)
      element.options[:class] = "icon-home" if element.options.delete(:home)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lay_me_out-1.2.9 lib/lay_me_out/breadcrumb_builder.rb
lay_me_out-1.2.8 lib/lay_me_out/breadcrumb_builder.rb