Sha256: a1b78f05433e34d49709f96e3b5b8ae2a4e34dfaa934f16f202ccfd339f66b6d

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

module Twitter
  module Bootstrap
    module Breadcrumbs
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods
        def add_breadcrumb(name, url = '', options = {})
          options.merge! :klass => self.name
          before_filter options do |controller|
            controller.send :add_breadcrumb, name, url, options
          end
        end
      end

      protected

      def add_breadcrumb(name, url = '', options = {})
        @breadcrumbs ||= []

        class_name = options.delete(:klass) || self.class.name

        if name.is_a? Symbol
          if url.blank?
            url_helper = :"#{name}_path"
            url = url_helper if respond_to?(url_helper)
          end

          name = translate_breadcrumb name, class_name
        end

        unless name.is_a? String
          url = polymorphic_path name if url.blank?
          name = name.to_s
        end

        url = eval(url.to_s) if url.is_a?(Symbol) && url =~ /_path|_url|@/

        @breadcrumbs << {:name => name, :url => url, :options => options}
      end

      def translate_breadcrumb(name, class_name)
        scope = [:breadcrumbs]
        namespace = class_name.underscore.split('/')
        namespace.last.sub!('_controller', '')
        scope += namespace

        I18n.t name, :scope => scope
      end

      def render_breadcrumbs(divider = '/')
        s = render :partial => 'twitter-bootstrap/breadcrumbs', :locals => {:divider => divider}
        s.first
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
twitter-bootstrap-rails-3.2.1.rc1 lib/twitter/bootstrap/rails/breadcrumbs.rb
twitter-bootstrap-rails-3.2.0 lib/twitter/bootstrap/rails/breadcrumbs.rb
devbootsrap-0.0.7 lib/twitter/bootstrap/rails/breadcrumbs.rb
devbootsrap-0.0.6 lib/twitter/bootstrap/rails/breadcrumbs.rb
devbootsrap-0.0.5 lib/twitter/bootstrap/rails/breadcrumbs.rb
devbootsrap-0.0.4 lib/twitter/bootstrap/rails/breadcrumbs.rb
devbootsrap-0.0.3 lib/twitter/bootstrap/rails/breadcrumbs.rb