crummy 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +13 -17
- data/VERSION +1 -1
- data/lib/crummy/action_controller.rb +26 -3
- data/lib/crummy/standard_renderer.rb +0 -2
- metadata +19 -39
data/README.textile
CHANGED
@@ -6,29 +6,21 @@ Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
|
|
6
6
|
|
7
7
|
h2. Install
|
8
8
|
|
9
|
-
|
9
|
+
Simply add the dependency to your Gemfile:
|
10
10
|
|
11
11
|
<pre>
|
12
12
|
<code>
|
13
|
-
gem
|
13
|
+
gem "crummy", "~> 1.3"
|
14
14
|
</code>
|
15
15
|
</pre>
|
16
16
|
|
17
|
-
|
17
|
+
h3. Rails 2
|
18
18
|
|
19
|
-
|
20
|
-
<code>
|
21
|
-
gem install crummy
|
22
|
-
</code>
|
23
|
-
</pre>
|
24
|
-
|
25
|
-
h3. Rails 3 / Bundler.
|
26
|
-
|
27
|
-
Simply add gem dependency to your Gemfile:
|
19
|
+
In your terminal, write:
|
28
20
|
|
29
21
|
<pre>
|
30
22
|
<code>
|
31
|
-
gem
|
23
|
+
gem install crummy
|
32
24
|
</code>
|
33
25
|
</pre>
|
34
26
|
|
@@ -48,6 +40,9 @@ In your controllers you may add_crumb either like a before_filter or within a me
|
|
48
40
|
before_filter :load_comment, :only => "show"
|
49
41
|
add_crumb :comment, :only => "show"
|
50
42
|
|
43
|
+
# Example for nested routes:
|
44
|
+
add_crumb(:document) { [:account, :document] }
|
45
|
+
|
51
46
|
def show
|
52
47
|
add_crumb @business.display_name, @business
|
53
48
|
end
|
@@ -99,13 +94,12 @@ h3. Examples
|
|
99
94
|
render_crumbs :format => :html_list #=> <ul class="" id=""><li class=""><a href="/">Home</a></li><li class=""><a href="/">Businesses</a></li></ul>
|
100
95
|
</code>
|
101
96
|
</pre>
|
102
|
-
A crumb with a nil link will
|
97
|
+
A crumb with a nil argument for the link will output an unlinked crumb.
|
98
|
+
|
103
99
|
With :format => :html_list you can specify additional params: :active_li_class, :li_class, :ul_class, :ul_id
|
104
100
|
|
105
101
|
h2. Notes
|
106
102
|
|
107
|
-
The variable set is set to @_crumbs as to not conflict with your code.
|
108
|
-
|
109
103
|
h2. Todo
|
110
104
|
|
111
105
|
* Port over rspecs from project to plugin (Fully tested in a project)
|
@@ -124,5 +118,7 @@ h2. Credits
|
|
124
118
|
* "Kamil K. Lemański":http://kml.jogger.pl
|
125
119
|
* "Brian Cobb":http://bcobb.net/
|
126
120
|
* "Kir Shatrov":http://shatrov.tk/
|
121
|
+
* "sugilog":http://github.com/sugilog
|
122
|
+
* "Trond Arve Nordheim":http://github.com/tanordheim
|
127
123
|
|
128
|
-
*Copyright (c) 2011 Zach Inglis, released under the MIT license*
|
124
|
+
*Copyright (c) 2008-2011 Zach Inglis, released under the MIT license*
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3
|
@@ -4,6 +4,7 @@ module Crummy
|
|
4
4
|
# Add a crumb to the crumbs array.
|
5
5
|
#
|
6
6
|
# add_crumb("Home", "/")
|
7
|
+
# add_crumb(lambda { |instance| instance.business_name }, "/")
|
7
8
|
# add_crumb("Business") { |instance| instance.business_path }
|
8
9
|
#
|
9
10
|
# Works like a before_filter so +:only+ and +except+ both work.
|
@@ -15,18 +16,36 @@ module Crummy
|
|
15
16
|
before_filter(options) do |instance|
|
16
17
|
url = yield instance if block_given?
|
17
18
|
url = instance.send url if url.is_a? Symbol
|
19
|
+
|
20
|
+
if url.present?
|
21
|
+
if url.kind_of? Enumerable
|
22
|
+
url.map! do |name|
|
23
|
+
name.is_a?(Symbol) ? instance.instance_variable_get("@#{name}") : name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
url = instance.send :url_for, url unless url.is_a? String
|
27
|
+
end
|
28
|
+
|
29
|
+
# Get the return value of the name if its a proc.
|
30
|
+
transformed_name = name.is_a?(Proc) ? name.call(instance) : name
|
18
31
|
|
19
|
-
_record = instance.instance_variable_get("@#{
|
32
|
+
_record = instance.instance_variable_get("@#{transformed_name}")
|
20
33
|
if _record and _record.respond_to? :to_param
|
21
|
-
instance.add_crumb(_record.to_s, instance.url_for(_record))
|
34
|
+
instance.add_crumb(_record.to_s, url || instance.url_for(_record))
|
22
35
|
else
|
23
|
-
instance.add_crumb(
|
36
|
+
instance.add_crumb(transformed_name, url)
|
24
37
|
end
|
25
38
|
|
26
39
|
# FIXME: url = instance.url_for(name) if name.respond_to?("to_param") && url.nil?
|
27
40
|
# FIXME: Add ||= for the name, url above
|
28
41
|
end
|
29
42
|
end
|
43
|
+
|
44
|
+
def clear_crumbs
|
45
|
+
before_filter do |instance|
|
46
|
+
instance.clear_crumbs
|
47
|
+
end
|
48
|
+
end
|
30
49
|
end
|
31
50
|
|
32
51
|
module InstanceMethods
|
@@ -39,6 +58,10 @@ module Crummy
|
|
39
58
|
crumbs.push [name, url]
|
40
59
|
end
|
41
60
|
|
61
|
+
def clear_crumbs
|
62
|
+
crumbs.clear
|
63
|
+
end
|
64
|
+
|
42
65
|
# Lists the crumbs as an array
|
43
66
|
def crumbs
|
44
67
|
get_or_set_ivar "@_crumbs", []
|
@@ -39,7 +39,6 @@ module Crummy
|
|
39
39
|
crumb_string = crumbs.collect do |crumb|
|
40
40
|
crumb_to_html crumb, options[:links]
|
41
41
|
end * options[:separator]
|
42
|
-
crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
|
43
42
|
crumb_string
|
44
43
|
when :html_list
|
45
44
|
# In html_list format there are no separator, but may be
|
@@ -53,7 +52,6 @@ module Crummy
|
|
53
52
|
crumb_to_html_list crumb, options[:links], options[:li_class], options[:active_li_class]
|
54
53
|
end * options[:separator]
|
55
54
|
crumb_string = "<ul class=\"#{options[:ul_class]}\" id=\"#{options[:ul_id]}\">" + crumb_string + "</ul>"
|
56
|
-
crumb_string = crumb_string.html_safe if crumb_string.respond_to?(:html_safe)
|
57
55
|
crumb_string
|
58
56
|
when :xml
|
59
57
|
crumbs.collect do |crumb|
|
metadata
CHANGED
@@ -1,32 +1,23 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: crummy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.3'
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: "1.2"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Zach Inglis
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-04-20 00:00:00 +01:00
|
18
|
-
default_executable:
|
12
|
+
date: 2011-04-20 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Crummy is a simple and tasty way to add breadcrumbs to your Rails applications.
|
22
15
|
email: zach+crummy@londonmade.co.uk
|
23
16
|
executables: []
|
24
|
-
|
25
17
|
extensions: []
|
26
|
-
|
27
|
-
extra_rdoc_files:
|
18
|
+
extra_rdoc_files:
|
28
19
|
- README.textile
|
29
|
-
files:
|
20
|
+
files:
|
30
21
|
- .gitignore
|
31
22
|
- MIT-LICENSE
|
32
23
|
- README.textile
|
@@ -39,39 +30,28 @@ files:
|
|
39
30
|
- lib/crummy/railtie.rb
|
40
31
|
- lib/crummy/standard_renderer.rb
|
41
32
|
- tasks/crummy_tasks.rake
|
42
|
-
has_rdoc: true
|
43
33
|
homepage: http://github.com/zachinglis/crummy
|
44
34
|
licenses: []
|
45
|
-
|
46
35
|
post_install_message:
|
47
36
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
37
|
+
require_paths:
|
50
38
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
40
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
46
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
69
51
|
requirements: []
|
70
|
-
|
71
52
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
53
|
+
rubygems_version: 1.8.11
|
73
54
|
signing_key:
|
74
55
|
specification_version: 3
|
75
56
|
summary: Tasty breadcrumbs!
|
76
57
|
test_files: []
|
77
|
-
|