Sha256: 2e15a51fc81c1402ed04fe65da3d74829142dc170187f7f36bb65a7400963a71

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

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

      module ClassMethods
        def add_breadcrumb(name, url, options = {})
          class_name = self.name
          before_filter options do |controller|
            name = controller.send :translate_breadcrumb, name, class_name if name.is_a?(Symbol)
            controller.send :add_breadcrumb, name, url
          end
        end
      end

      protected

      def add_breadcrumb(name, url = '', options = {})
        @breadcrumbs ||= []
        name = translate_breadcrumb(name, self.class.name) if name.is_a?(Symbol)
        url = eval(url.to_s) if 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

10 entries across 10 versions & 2 rubygems

Version Path
twitter-bootstrap3-rails-3.2.7.1 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap3-rails-3.2.7 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.8 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.7 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.6 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.5 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.4 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.3 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.1 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb
twitter-bootstrap-rails-2.2.0 lib/twitter/bootstrap/rails/twitter-bootstrap-breadcrumbs.rb