crummy 1.3.6 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +40 -2
- data/VERSION +1 -1
- data/lib/crummy.rb +41 -2
- data/lib/crummy/standard_renderer.rb +14 -18
- metadata +2 -2
data/README.textile
CHANGED
@@ -10,7 +10,7 @@ Simply add the dependency to your Gemfile:
|
|
10
10
|
|
11
11
|
<pre>
|
12
12
|
<code>
|
13
|
-
gem "crummy", "~> 1.
|
13
|
+
gem "crummy", "~> 1.5.0"
|
14
14
|
</code>
|
15
15
|
</pre>
|
16
16
|
|
@@ -98,6 +98,43 @@ A crumb with a nil argument for the link will output an unlinked crumb.
|
|
98
98
|
|
99
99
|
With :format => :html_list you can specify additional params: :active_li_class, :li_class, :ul_class, :ul_id
|
100
100
|
|
101
|
+
h3. App-wide configuration
|
102
|
+
|
103
|
+
You have the option to pre-configure any of the Crummy options in an application-wide configuration. The options above are available to configure, with the exception of @:separator@, as well as many others.
|
104
|
+
|
105
|
+
The biggest difference is that @:separator@ is not an option. Instead, you have format-specific configuration options: @:html_separator@, @:xml_separator@, and @:html_list_separator@. @:separator@ can still be overridden in the view.
|
106
|
+
|
107
|
+
Insert the following in a file named @config/initializers/crummy.rb@:
|
108
|
+
|
109
|
+
<pre>
|
110
|
+
<code>
|
111
|
+
Crummy.configure do |config|
|
112
|
+
config.format = :xml
|
113
|
+
end
|
114
|
+
</code>
|
115
|
+
</pre>
|
116
|
+
|
117
|
+
Possible parameters for configuration are:
|
118
|
+
|
119
|
+
<pre>
|
120
|
+
<code>
|
121
|
+
:format
|
122
|
+
:links
|
123
|
+
:skip_if_blank
|
124
|
+
:html_separator
|
125
|
+
:xml_separator
|
126
|
+
:html_list_separator
|
127
|
+
:first_class
|
128
|
+
:last_class
|
129
|
+
:ul_id
|
130
|
+
:ul_class
|
131
|
+
:li_class
|
132
|
+
:active_li_class
|
133
|
+
</code>
|
134
|
+
</pre>
|
135
|
+
|
136
|
+
See @lib/crummy.rb@ for a list of these parameters and their defaults.
|
137
|
+
|
101
138
|
h2. Notes
|
102
139
|
|
103
140
|
Test library is at "Crummy Test":https://github.com/zachinglis/crummy-test
|
@@ -120,10 +157,11 @@ h2. Credits
|
|
120
157
|
* "Max Riveiro":http://github.com/kavu
|
121
158
|
* "Kamil K. Lemański":http://kml.jogger.pl
|
122
159
|
* "Brian Cobb":http://bcobb.net/
|
123
|
-
* "Kir Shatrov":http://shatrov.
|
160
|
+
* "Kir Shatrov":http://github.com/shatrov ("Evrone company":http://evrone.com)
|
124
161
|
* "sugilog":http://github.com/sugilog
|
125
162
|
* "Trond Arve Nordheim":http://github.com/tanordheim
|
126
163
|
* "Jan Szumiec":http://github.com/jasiek
|
127
164
|
* "Jeff Browning":http://github.com/jbrowning
|
165
|
+
* "Bill Turner":http://github.com/billturner
|
128
166
|
|
129
167
|
*Copyright (c) 2008-2011 Zach Inglis, released under the MIT license*
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/lib/crummy.rb
CHANGED
@@ -1,10 +1,49 @@
|
|
1
1
|
module Crummy
|
2
|
+
|
3
|
+
def self.configuration
|
4
|
+
@configuration ||= Configuration.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
yield configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :format
|
13
|
+
attr_accessor :links
|
14
|
+
attr_accessor :skip_if_blank
|
15
|
+
attr_accessor :html_separator
|
16
|
+
attr_accessor :xml_separator
|
17
|
+
attr_accessor :html_list_separator
|
18
|
+
attr_accessor :first_class
|
19
|
+
attr_accessor :last_class
|
20
|
+
attr_accessor :ul_id
|
21
|
+
attr_accessor :ul_class
|
22
|
+
attr_accessor :li_class
|
23
|
+
attr_accessor :active_li_class
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@format = :html
|
27
|
+
@html_separator = " » "
|
28
|
+
@xml_separator = "crumb"
|
29
|
+
@html_list_separator = ''
|
30
|
+
@skip_if_blank = true
|
31
|
+
@links = true
|
32
|
+
@first_class = ''
|
33
|
+
@last_class = ''
|
34
|
+
@ul_id = ''
|
35
|
+
@ul_class = ''
|
36
|
+
@li_class = ''
|
37
|
+
@active_li_class = ''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
2
41
|
if defined?(Rails::Railtie)
|
3
42
|
require 'crummy/railtie'
|
4
43
|
else
|
5
44
|
require 'crummy/action_controller'
|
6
45
|
require 'crummy/action_view'
|
7
|
-
ActionController::Base.send :include,
|
46
|
+
ActionController::Base.send :include, Crummy::ControllerMethods
|
8
47
|
ActionView::Base.send :include, Crummy::ViewMethods
|
9
|
-
end
|
48
|
+
end
|
10
49
|
end
|
@@ -27,15 +27,13 @@ module Crummy
|
|
27
27
|
# render_crumbs(" . ") #=> <a href="/">Home</a> . <a href="/businesses">Businesses</a>
|
28
28
|
#
|
29
29
|
def render_crumbs(crumbs, options = {})
|
30
|
-
options[:
|
30
|
+
options[:skip_if_blank] ||= Crummy.configuration.skip_if_blank
|
31
31
|
return '' if options[:skip_if_blank] && crumbs.count < 1
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
options[:
|
37
|
-
options[:first_class] ||= ''
|
38
|
-
options[:last_class] ||= ''
|
32
|
+
options[:format] ||= Crummy.configuration.format
|
33
|
+
options[:separator] ||= Crummy.configuration.send(:"#{options[:format]}_separator")
|
34
|
+
options[:links] ||= Crummy.configuration.links
|
35
|
+
options[:first_class] ||= Crummy.configuration.first_class
|
36
|
+
options[:last_class] ||= Crummy.configuration.last_class
|
39
37
|
|
40
38
|
case options[:format]
|
41
39
|
when :html
|
@@ -44,17 +42,15 @@ module Crummy
|
|
44
42
|
end * options[:separator]
|
45
43
|
crumb_string
|
46
44
|
when :html_list
|
47
|
-
#
|
48
|
-
options[:
|
49
|
-
|
50
|
-
options[:
|
51
|
-
options[:
|
52
|
-
options[:ul_class] = "" if options[:ul_class] == nil
|
53
|
-
options[:ul_id] = "" if options[:ul_id] == nil
|
45
|
+
# Let's set values for special options of html_list format
|
46
|
+
options[:active_li_class] ||= Crummy.configuration.active_li_class
|
47
|
+
options[:li_class] ||= Crummy.configuration.li_class
|
48
|
+
options[:ul_class] ||= Crummy.configuration.ul_class
|
49
|
+
options[:ul_id] ||= Crummy.configuration.ul_id
|
54
50
|
crumb_string = crumbs.collect do |crumb|
|
55
51
|
crumb_to_html_list(crumb, options[:links], options[:li_class], options[:active_li_class], options[:first_class], options[:last_class], (crumb == crumbs.first), (crumb == crumbs.last))
|
56
52
|
end * options[:separator]
|
57
|
-
crumb_string =
|
53
|
+
crumb_string = content_tag(:ul, crumb_string, :class => options[:ul_class], :id => options[:ul_id])
|
58
54
|
crumb_string
|
59
55
|
when :xml
|
60
56
|
crumbs.collect do |crumb|
|
@@ -82,12 +78,12 @@ module Crummy
|
|
82
78
|
html_classes << last_class if is_last
|
83
79
|
html_classes << active_li_class unless url && links
|
84
80
|
html_classes << li_class if !is_first && !is_last && url && links
|
85
|
-
url && links ?
|
81
|
+
content_tag(:li, url && links ? link_to(name, url) : content_tag(:span, name), :class => html_classes.join(' ').strip)
|
86
82
|
end
|
87
83
|
|
88
84
|
def crumb_to_xml(crumb, links, separator, is_first, is_last)
|
89
85
|
name, url = crumb
|
90
|
-
url && links ?
|
86
|
+
content_tag(separator, name, :href => (url && links ? url : nil))
|
91
87
|
end
|
92
88
|
end
|
93
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crummy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-07 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
|
15
15
|
email: zach+crummy@londonmade.co.uk
|