crumble 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -76,6 +76,33 @@ If you don't want to specify any URL method at all, just use :current, it'll jus
76
76
 
77
77
  crumb :search, 'Search (Keywords: #{params[:q]})', :current
78
78
 
79
+ Internationalization usage
80
+
81
+ For example, if you want to localize your menu, define a new breadcrumbs node in your .yml file with all the keys for your elements.
82
+ # config/locales/en.yml
83
+ en:
84
+ breadcrumbs:
85
+ homepage: Homepage
86
+ profile: Your Profile
87
+ profile_dynamic: Hi {{name}}
88
+
89
+ # config/locales/es.yml
90
+ es:
91
+ breadcrumbs:
92
+ homepage: Homepage
93
+ profile: Tu perfil
94
+ profile_dynamic: Hola {{name}}
95
+
96
+ Then you can define the title of your crum as:
97
+
98
+ crumb :profile, nil, :account_url
99
+
100
+ Crumble find your locale for the scope "breadcrumbs.#{crumb.name}"
101
+
102
+ If you want to make the I18n title content dynamic, just use a hash with the same key as the i18n param and with a hash value that will be interpolate to @user.name in this case:
103
+
104
+ crumb :profile_dynamic, {:name => {:user => :name}}, :account_url
105
+
79
106
  You can base trails on conditions using :unless and :if. Both need to point to a method that exists in the context of the view.
80
107
 
81
108
  trail :home, :index, [:root], :unless => :logged_in?
@@ -122,9 +149,14 @@ Future
122
149
 
123
150
  If you think something's missing, let me know at <meyer@paperplanes.de>, or even better, send patches, including tests.
124
151
 
152
+ Contributors
153
+ ===========
154
+
155
+ * Paco Guzmán (i18n support)
156
+
125
157
  License
126
158
  =======
127
159
 
128
160
  MIT
129
161
 
130
- (c) 2009 [Mathias Meyer](http://www.paperplanes.de)
162
+ (c) 2009 [Mathias Meyer](http://www.paperplanes.de)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -15,9 +15,9 @@ module BreadcrumbsHelper
15
15
  trail.each do |crummy|
16
16
  crumb = Breadcrumb.instance.crumbs[crummy]
17
17
  if not Breadcrumb.instance.last_crumb_linked? and crummy == trail.last
18
- breadcrumb_trail << eval(%Q{"#{crumb.title}"})
18
+ breadcrumb_trail << eval(%Q{"#{assemble_crumb_title(crumb)}"})
19
19
  else
20
- breadcrumb_trail << link_to(eval(%Q{"#{crumb.title}"}), fetch_crumb_url(crumb))
20
+ breadcrumb_trail << link_to(eval(%Q{"#{assemble_crumb_title(crumb)}"}), fetch_crumb_url(crumb))
21
21
  end
22
22
  end
23
23
  breadcrumb_trail.join(Breadcrumb.instance.delimiter)
@@ -86,4 +86,18 @@ module BreadcrumbsHelper
86
86
  end
87
87
  result
88
88
  end
89
+
90
+ def assemble_crumb_title(crumb)
91
+ if crumb.title.is_a?(Hash) # We expect the name of the parameters with the code to evaluate
92
+ i18n_params = {}
93
+ crumb.title.each_pair do |key, value|
94
+ i18n_params[key] = instance_eval("@#{assemble_crumb_url_parameter(value).join(".")}")
95
+ end
96
+ I18n.t(crumb.name, {:scope => "breadcrumbs"}.merge!(i18n_params))
97
+ elsif crumb.title.nil?
98
+ I18n.t(crumb.name, :scope => "breadcrumbs")
99
+ else
100
+ crumb.title
101
+ end
102
+ end
89
103
  end
@@ -28,6 +28,56 @@ describe BreadcrumbsHelper do
28
28
  describe "when getting the breadcrumbs" do
29
29
  before(:each) do
30
30
  end
31
+
32
+ describe "i18n support" do
33
+ it "should get the title from I18n based in the crumb name" do
34
+ I18n.backend.store_translations(:en, {:breadcrumbs => {:profile => "Your Profile"}})
35
+ Breadcrumb.configure do
36
+ crumb :profile, nil, :user_url, :user
37
+ trail :accounts, :edit, [:profile]
38
+ end
39
+ params[:controller] = 'accounts'
40
+ params[:action] = 'edit'
41
+ crumbs.should == %Q{<a href="http://test.host/f/jonathan">Your Profile</a>}
42
+ end
43
+
44
+ it "should get the title from I18n based in the crumb name in the last crumb when the option was specified" do
45
+ I18n.backend.store_translations(:en, {:breadcrumbs => {:profile => "Your Profile"}})
46
+ Breadcrumb.configure do
47
+ crumb :profile, nil, :user_url, :user
48
+ trail :accounts, :edit, [:profile]
49
+ dont_link_last_crumb
50
+ end
51
+ params[:controller] = 'accounts'
52
+ params[:action] = 'edit'
53
+ crumbs.should == %Q{Your Profile}
54
+ end
55
+
56
+ describe "i18n parameters" do
57
+ it "should be able to interpolate parameters in a hash" do
58
+ I18n.backend.store_translations(:en, {:breadcrumbs => {:profile => "Your Profile - {{login}}"}})
59
+ Breadcrumb.configure do
60
+ crumb :profile, {:login => {:user => :login}}, :user_url, :user
61
+ trail :accounts, :edit, [:profile]
62
+ end
63
+
64
+ params[:controller] = 'accounts'
65
+ params[:action] = 'edit'
66
+ crumbs.should == %Q{<a href="http://test.host/f/jonathan">Your Profile - jonathan</a>}
67
+ end
68
+ end
69
+
70
+ it "should use title instead I18n.t message" do
71
+ I18n.backend.store_translations(:en, {:breadcrumbs => {:profile => "Your Profile"}})
72
+ Breadcrumb.configure do
73
+ crumb :profile, 'Your Profile', :user_url, :user
74
+ trail :accounts, :edit, [:profile]
75
+ end
76
+ params[:controller] = 'accounts'
77
+ params[:action] = 'edit'
78
+ crumbs.should == %Q{<a href="http://test.host/f/jonathan">Your Profile</a>}
79
+ end
80
+ end
31
81
 
32
82
  it "should calculate the urls in the breadcrumbs" do
33
83
  Breadcrumb.configure do
@@ -104,6 +154,23 @@ describe BreadcrumbsHelper do
104
154
  params[:q] = 'google'
105
155
  crumbs.should == %Q{<a href="http://test.host/search?q=google&amp;country=Germany">Search</a>}
106
156
  end
157
+
158
+ it "should add multiple parameters to the url not need to test the order" do
159
+ Breadcrumb.configure do
160
+ crumb :search, "Search", :search_url, :params => [:q, :country]
161
+ trail :search, :new, [:search]
162
+ end
163
+
164
+ params[:controller] = 'search'
165
+ params[:action] = 'new'
166
+ params[:country] = 'Germany'
167
+ params[:q] = 'google'
168
+
169
+ params_array = URI.parse(crumbs[/.*href=[\"'](.*)[\"']/,1]).query.split(/=|(&amp;)/)
170
+ %w(q google country Germany).each do |key|
171
+ params_array.should include(key)
172
+ end
173
+ end
107
174
 
108
175
  it "should eval single quoted title strings and interpolate them" do
109
176
  Breadcrumb.configure do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crumble
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 +01:00
12
+ date: 2010-01-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15