bsm-breadcrumbs 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -12
- data/bsm-breadcrumbs.gemspec +3 -3
- data/lib/breadcrumbs.rb +49 -4
- data/lib/breadcrumbs/version.rb +2 -2
- data/test/breadcrumbs_test.rb +15 -3
- data/test/resources/en.yml +12 -0
- data/test/test_helper.rb +26 -10
- metadata +6 -6
- data/test/resources/pt.yml +0 -6
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,31 +2,31 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
abstract (1.0.0)
|
5
|
-
actionpack (3.0.
|
6
|
-
activemodel (= 3.0.
|
7
|
-
activesupport (= 3.0.
|
5
|
+
actionpack (3.0.3)
|
6
|
+
activemodel (= 3.0.3)
|
7
|
+
activesupport (= 3.0.3)
|
8
8
|
builder (~> 2.1.2)
|
9
9
|
erubis (~> 2.6.6)
|
10
|
-
i18n (~> 0.4
|
10
|
+
i18n (~> 0.4)
|
11
11
|
rack (~> 1.2.1)
|
12
|
-
rack-mount (~> 0.6.
|
13
|
-
rack-test (~> 0.5.
|
12
|
+
rack-mount (~> 0.6.13)
|
13
|
+
rack-test (~> 0.5.6)
|
14
14
|
tzinfo (~> 0.3.23)
|
15
|
-
activemodel (3.0.
|
16
|
-
activesupport (= 3.0.
|
15
|
+
activemodel (3.0.3)
|
16
|
+
activesupport (= 3.0.3)
|
17
17
|
builder (~> 2.1.2)
|
18
|
-
i18n (~> 0.4
|
19
|
-
activesupport (3.0.
|
18
|
+
i18n (~> 0.4)
|
19
|
+
activesupport (3.0.3)
|
20
20
|
builder (2.1.2)
|
21
21
|
erubis (2.6.6)
|
22
22
|
abstract (>= 1.0.0)
|
23
|
-
i18n (0.
|
23
|
+
i18n (0.5.0)
|
24
24
|
rack (1.2.1)
|
25
25
|
rack-mount (0.6.13)
|
26
26
|
rack (>= 1.0.0)
|
27
27
|
rack-test (0.5.6)
|
28
28
|
rack (>= 1.0)
|
29
|
-
test-unit (2.1.
|
29
|
+
test-unit (2.1.2)
|
30
30
|
tzinfo (0.3.23)
|
31
31
|
|
32
32
|
PLATFORMS
|
@@ -34,4 +34,5 @@ PLATFORMS
|
|
34
34
|
|
35
35
|
DEPENDENCIES
|
36
36
|
actionpack (~> 3.0.0)
|
37
|
+
activemodel (~> 3.0.0)
|
37
38
|
test-unit
|
data/bsm-breadcrumbs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bsm-breadcrumbs}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nando Vieira", "Dimitrij Denissenko"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-13}
|
13
13
|
s.description = %q{Breadcrumbs is a simple plugin that adds a `breadcrumbs` object to controllers and views.}
|
14
14
|
s.email = %q{dimitrij@blacksquaremedia.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/breadcrumbs/render/ordered_list.rb",
|
33
33
|
"lib/breadcrumbs/version.rb",
|
34
34
|
"test/breadcrumbs_test.rb",
|
35
|
-
"test/resources/
|
35
|
+
"test/resources/en.yml",
|
36
36
|
"test/test_helper.rb"
|
37
37
|
]
|
38
38
|
s.homepage = %q{http://github.com/bsm/breadcrumbs}
|
data/lib/breadcrumbs.rb
CHANGED
@@ -5,10 +5,10 @@ class Breadcrumbs < Array
|
|
5
5
|
autoload :Render, "breadcrumbs/render"
|
6
6
|
autoload :Version, "breadcrumbs/version"
|
7
7
|
|
8
|
-
|
8
|
+
attr_reader :controller
|
9
9
|
|
10
10
|
def initialize(controller) # :nodoc:
|
11
|
-
|
11
|
+
@controller = controller
|
12
12
|
super([])
|
13
13
|
end
|
14
14
|
|
@@ -27,9 +27,41 @@ class Breadcrumbs < Array
|
|
27
27
|
url = controller.__send__(:url_for, url) if url
|
28
28
|
push [text.to_s, url, options]
|
29
29
|
end
|
30
|
-
|
31
30
|
alias :<< :add
|
32
31
|
|
32
|
+
# Short-cut for adding breadcrumbs. Examples:
|
33
|
+
#
|
34
|
+
# breadcrumbs.crumb :posts
|
35
|
+
# # => ["Posts", "/posts"]
|
36
|
+
#
|
37
|
+
# breadcrumbs.crumb @post, :comments
|
38
|
+
# # => ["Comments", "/posts/123/comments"]
|
39
|
+
#
|
40
|
+
# @user # => #<User name: "Sam">
|
41
|
+
# breadcrumbs.crumb :admin, @account, @user
|
42
|
+
# # => ["Sam", "/admin/accounts/123/users/456"]
|
43
|
+
#
|
44
|
+
# breadcrumbs.crumb @post, :comments, :title => "Our Comments"
|
45
|
+
# # => ["Our Comments", "/posts/123/comments"]
|
46
|
+
#
|
47
|
+
def crumb(*args)
|
48
|
+
options = args.extract_options!
|
49
|
+
|
50
|
+
title = if options[:title]
|
51
|
+
options.delete(:title)
|
52
|
+
else
|
53
|
+
case args.last
|
54
|
+
when String, Symbol
|
55
|
+
infer_model_name_from_symbol(args.last).human(:count => :multiple)
|
56
|
+
else
|
57
|
+
infer_title_from_record(args.last)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
url = args.presence || false
|
61
|
+
|
62
|
+
add title.presence, options.delete(:url) || url, options
|
63
|
+
end
|
64
|
+
|
33
65
|
# Render breadcrumbs using the specified format.
|
34
66
|
# Use HTML lists by default, but can be plain links.
|
35
67
|
#
|
@@ -69,6 +101,19 @@ class Breadcrumbs < Array
|
|
69
101
|
text ||= I18n.t(scope, :default => scope.to_s)
|
70
102
|
text
|
71
103
|
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def infer_model_name_from_symbol(symbol)
|
108
|
+
symbol.to_s.classify.constantize.model_name
|
109
|
+
end
|
110
|
+
|
111
|
+
def infer_title_from_record(record)
|
112
|
+
%w(to_label title_was title name_was name label_was label value_was value to_s).each do |m|
|
113
|
+
return record.send(m) if record.respond_to?(m)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
72
117
|
end
|
73
118
|
|
74
|
-
require "breadcrumbs/action_controller_ext"
|
119
|
+
require "breadcrumbs/action_controller_ext"
|
data/lib/breadcrumbs/version.rb
CHANGED
data/test/breadcrumbs_test.rb
CHANGED
@@ -149,7 +149,7 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
149
149
|
|
150
150
|
items = parse_tag(@breadcrumbs.render).children
|
151
151
|
assert_equal "<span>home</span>", items[0].children.join
|
152
|
-
assert_equal "<span>
|
152
|
+
assert_equal "<span>Our team</span>", items[1].children.join
|
153
153
|
end
|
154
154
|
|
155
155
|
def test_render_internationalized_text_using_default_scope
|
@@ -157,8 +157,8 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
157
157
|
@breadcrumbs.add :people
|
158
158
|
|
159
159
|
items = parse_tag(@breadcrumbs.render).children
|
160
|
-
assert_equal "<span>
|
161
|
-
assert_equal "<span>
|
160
|
+
assert_equal "<span>Home page</span>", items[0].children.join
|
161
|
+
assert_equal "<span>Our team</span>", items[1].children.join
|
162
162
|
end
|
163
163
|
|
164
164
|
def test_render_scope_as_text_for_missing_scope
|
@@ -200,6 +200,18 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
200
200
|
assert_equal "Resources", tag.children.join
|
201
201
|
end
|
202
202
|
|
203
|
+
def test_crumb_shortcuts
|
204
|
+
@breadcrumbs.crumb :users
|
205
|
+
@breadcrumbs.crumb :users, :title => "Custom"
|
206
|
+
@breadcrumbs.crumb :admin, :users
|
207
|
+
@breadcrumbs.crumb :admin, User.new
|
208
|
+
|
209
|
+
assert_equal ["Users", "http://test.host/users", {}], @breadcrumbs[0]
|
210
|
+
assert_equal ["Custom", "http://test.host/users", {}], @breadcrumbs[1]
|
211
|
+
assert_equal ["Users", "http://test.host/admin/users", {}], @breadcrumbs[2]
|
212
|
+
assert_equal ["Sam", "http://test.host/admin/users/123", {}], @breadcrumbs[3]
|
213
|
+
end
|
214
|
+
|
203
215
|
private
|
204
216
|
|
205
217
|
def reject_blanks!(tag)
|
data/test/test_helper.rb
CHANGED
@@ -7,21 +7,37 @@ require 'test/unit'
|
|
7
7
|
require "breadcrumbs"
|
8
8
|
require 'action_controller'
|
9
9
|
require 'action_controller/test_case'
|
10
|
+
require 'active_model/naming'
|
10
11
|
|
11
|
-
I18n.load_path << File.dirname(__FILE__) + "/resources/
|
12
|
-
I18n.locale = :
|
12
|
+
I18n.load_path << File.dirname(__FILE__) + "/resources/en.yml"
|
13
|
+
I18n.locale = :en
|
13
14
|
|
14
15
|
class TestsController < ActionController::Base
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
class UsersController < ActionController::Base
|
19
|
+
end
|
20
|
+
|
21
|
+
module Admin
|
22
|
+
class UsersController < ActionController::Base
|
21
23
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
routes = ActionDispatch::Routing::RouteSet.new
|
27
|
+
routes.draw do
|
28
|
+
resources :tests
|
29
|
+
resources :users
|
30
|
+
namespace :admin do
|
31
|
+
resources :users
|
26
32
|
end
|
27
33
|
end
|
34
|
+
TestsController.send(:include, routes.url_helpers)
|
35
|
+
|
36
|
+
class User
|
37
|
+
extend ActiveModel::Naming
|
38
|
+
extend ActiveModel::Translation
|
39
|
+
|
40
|
+
def to_param; "123" end
|
41
|
+
def name_was; "Sam" end
|
42
|
+
def name; "" end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsm-breadcrumbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nando Vieira
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-12-13 00:00:00 +00:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- lib/breadcrumbs/render/ordered_list.rb
|
61
61
|
- lib/breadcrumbs/version.rb
|
62
62
|
- test/breadcrumbs_test.rb
|
63
|
-
- test/resources/
|
63
|
+
- test/resources/en.yml
|
64
64
|
- test/test_helper.rb
|
65
65
|
has_rdoc: true
|
66
66
|
homepage: http://github.com/bsm/breadcrumbs
|