Sha256: 42fc948fcb20a9c5917a7354ed3e0762dcd3a6174c565f0d883cfa7ce86f2f00

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

module Twitter
	module Bootstrap
		module For
			module Rails
				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]

						global_text = I18n.t name, scope: scope

						namespace = class_name.underscore.split('/')
						namespace.last.sub!('_controller', '')
						scope += namespace

						I18n.t name, :scope => scope, default: global_text
					end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twitter-bootstrap-for-rails-1.3.4 lib/twitter/bootstrap/for/rails/breadcrumbs.rb
twitter-bootstrap-for-rails-1.3.3 lib/twitter/bootstrap/for/rails/breadcrumbs.rb