breadcrumbs 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -0
- data/lib/breadcrumbs.rb +23 -7
- data/lib/breadcrumbs/render.rb +8 -3
- data/lib/breadcrumbs/render/base.rb +9 -0
- data/lib/breadcrumbs/render/inline.rb +1 -7
- data/lib/breadcrumbs/render/list.rb +6 -7
- data/lib/breadcrumbs/render/ordered_list.rb +9 -0
- data/lib/breadcrumbs/version.rb +1 -1
- data/test/breadcrumbs_test.rb +8 -0
- data/test/test_helper.rb +2 -0
- metadata +18 -5
data/README.rdoc
CHANGED
@@ -52,6 +52,19 @@ You can set your own separator:
|
|
52
52
|
You are here: <%= breadcrumbs.render(:format => :inline, :separator => '|') %>
|
53
53
|
</p>
|
54
54
|
|
55
|
+
You can also define your own formatter. Just create a class that implements a +render+ instance
|
56
|
+
method and you're good to go.
|
57
|
+
|
58
|
+
class Breadcrumbs::Render::Dl
|
59
|
+
def render
|
60
|
+
# return breadcrumbs wrapped in a <DL> tag
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
To use your new format, just provide the <tt>:format</tt> option.
|
65
|
+
|
66
|
+
breadcrumbs.render(:format => :dl)
|
67
|
+
|
55
68
|
=== I18n
|
56
69
|
|
57
70
|
Breadcrumbs is integrated with I18n. You can set translations like:
|
data/lib/breadcrumbs.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "i18n" unless defined?(I18n)
|
2
2
|
require "breadcrumbs/render"
|
3
3
|
require "breadcrumbs/action_controller_ext" if defined?(ActionController)
|
4
|
+
require "active_support/inflector"
|
4
5
|
|
5
6
|
class Breadcrumbs
|
6
7
|
attr_accessor :items
|
@@ -24,6 +25,8 @@ class Breadcrumbs
|
|
24
25
|
items << [text.to_s, url, options]
|
25
26
|
end
|
26
27
|
|
28
|
+
alias :<< :add
|
29
|
+
|
27
30
|
# Render breadcrumbs using the specified format.
|
28
31
|
# Use HTML lists by default, but can be plain links.
|
29
32
|
#
|
@@ -35,15 +38,28 @@ class Breadcrumbs
|
|
35
38
|
# breadcrumbs.render(:id => "breadcrumbs")
|
36
39
|
# breadcrumbs.render(:class => "breadcrumbs")
|
37
40
|
#
|
41
|
+
# You can also define your own formatter. Just create a class that implements a +render+ instance
|
42
|
+
# method and you're good to go.
|
43
|
+
#
|
44
|
+
# class Breadcrumbs::Render::Dl
|
45
|
+
# def render
|
46
|
+
# # return breadcrumbs wrapped in a <DL> tag
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# To use your new format, just provide the <tt>:format</tt> option.
|
51
|
+
#
|
52
|
+
# breadcrumbs.render(:format => :dl)
|
53
|
+
#
|
38
54
|
def render(options = {})
|
39
|
-
|
40
|
-
Breadcrumbs::Render::Inline.new(self, options).render
|
41
|
-
else
|
42
|
-
Breadcrumbs::Render::List.new(self, options).render
|
43
|
-
end
|
44
|
-
end
|
55
|
+
options[:format] ||= :list
|
45
56
|
|
46
|
-
|
57
|
+
klass_name = options[:format].to_s.classify
|
58
|
+
klass = Breadcrumbs::Render.const_get(klass_name)
|
59
|
+
html = klass.new(self, options).render
|
60
|
+
|
61
|
+
html.respond_to?(:html_safe) ? html.html_safe : html
|
62
|
+
end
|
47
63
|
|
48
64
|
def translate(scope) # :nodoc:
|
49
65
|
text = I18n.t(scope, :scope => :breadcrumbs, :raise => true) rescue nil
|
data/lib/breadcrumbs/render.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class Breadcrumbs
|
2
|
+
module Render
|
3
|
+
autoload :Base, "breadcrumbs/render/base"
|
4
|
+
autoload :Inline, "breadcrumbs/render/inline"
|
5
|
+
autoload :List, "breadcrumbs/render/list"
|
6
|
+
autoload :OrderedList, "breadcrumbs/render/ordered_list"
|
7
|
+
end
|
8
|
+
end
|
@@ -26,6 +26,15 @@ class Breadcrumbs
|
|
26
26
|
|
27
27
|
%[<#{name}#{attrs}>#{content}</#{name}>]
|
28
28
|
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def wrap_item(url, text, options)
|
32
|
+
if url
|
33
|
+
tag(:a, text, options.merge(:href => url))
|
34
|
+
else
|
35
|
+
tag(:span, text, options)
|
36
|
+
end
|
37
|
+
end
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
@@ -29,13 +29,7 @@ class Breadcrumbs
|
|
29
29
|
options[:class] << " #{css.join(" ")}"
|
30
30
|
options[:class].gsub!(/^ *(.*?)$/, '\\1')
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
if url
|
35
|
-
text = tag(:a, text, options.merge(:href => url))
|
36
|
-
else
|
37
|
-
text = tag(:span, text, options)
|
38
|
-
end
|
32
|
+
wrap_item(url, CGI.escapeHTML(text), options)
|
39
33
|
end
|
40
34
|
end
|
41
35
|
end
|
@@ -3,12 +3,9 @@ class Breadcrumbs
|
|
3
3
|
class List < Base # :nodoc: all
|
4
4
|
def render
|
5
5
|
options = {
|
6
|
-
:class => "breadcrumbs"
|
7
|
-
:format => :list
|
6
|
+
:class => "breadcrumbs"
|
8
7
|
}.merge(default_options)
|
9
8
|
|
10
|
-
list_style = options[:format] == :list ? :ul : :ol
|
11
|
-
|
12
9
|
tag(list_style, options) do
|
13
10
|
html = ""
|
14
11
|
items = breadcrumbs.items
|
@@ -22,6 +19,10 @@ class Breadcrumbs
|
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
22
|
+
def list_style
|
23
|
+
:ul
|
24
|
+
end
|
25
|
+
|
25
26
|
def render_item(item, i, size)
|
26
27
|
css = []
|
27
28
|
css << "first" if i == 0
|
@@ -29,9 +30,7 @@ class Breadcrumbs
|
|
29
30
|
css << "item-#{i}"
|
30
31
|
|
31
32
|
text, url, options = *item
|
32
|
-
text = CGI.escapeHTML(text)
|
33
|
-
text = tag(:a, text, options.merge(:href => url)) if url
|
34
|
-
|
33
|
+
text = wrap_item(url, CGI.escapeHTML(text), options)
|
35
34
|
tag(:li, text, :class => css.join(" "))
|
36
35
|
end
|
37
36
|
end
|
data/lib/breadcrumbs/version.rb
CHANGED
data/test/breadcrumbs_test.rb
CHANGED
@@ -6,6 +6,13 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
6
6
|
@inline = Breadcrumbs::Render::Inline.new(@breadcrumbs)
|
7
7
|
end
|
8
8
|
|
9
|
+
def test_return_safe_html
|
10
|
+
html_mock = mock
|
11
|
+
html_mock.expects(:html_safe).once
|
12
|
+
Breadcrumbs::Render::List.any_instance.stubs(:render).returns(html_mock)
|
13
|
+
@breadcrumbs.render(:format => :list)
|
14
|
+
end
|
15
|
+
|
9
16
|
def test_add_item
|
10
17
|
@breadcrumbs.add "Home"
|
11
18
|
assert_equal 1, @breadcrumbs.items.count
|
@@ -86,6 +93,7 @@ class BreadcrumbsTest < Test::Unit::TestCase
|
|
86
93
|
assert_equal "last item-2", items[2]["class"]
|
87
94
|
assert_equal "People", items[2].inner_text
|
88
95
|
assert_nil items[2].at("a")
|
96
|
+
assert_not_nil items[2].at("span")
|
89
97
|
end
|
90
98
|
|
91
99
|
def test_render_inline
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breadcrumbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Nando Vieira
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-26 00:00:00 -03:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -29,6 +35,7 @@ files:
|
|
29
35
|
- lib/breadcrumbs/render/base.rb
|
30
36
|
- lib/breadcrumbs/render/inline.rb
|
31
37
|
- lib/breadcrumbs/render/list.rb
|
38
|
+
- lib/breadcrumbs/render/ordered_list.rb
|
32
39
|
- lib/breadcrumbs/version.rb
|
33
40
|
- test/breadcrumbs_test.rb
|
34
41
|
- test/resources/pt.yml
|
@@ -43,21 +50,27 @@ rdoc_options:
|
|
43
50
|
require_paths:
|
44
51
|
- lib
|
45
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
46
54
|
requirements:
|
47
55
|
- - ">="
|
48
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
49
60
|
version: "0"
|
50
|
-
version:
|
51
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
52
63
|
requirements:
|
53
64
|
- - ">="
|
54
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
55
69
|
version: "0"
|
56
|
-
version:
|
57
70
|
requirements: []
|
58
71
|
|
59
72
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.7
|
61
74
|
signing_key:
|
62
75
|
specification_version: 3
|
63
76
|
summary: Breadcrumbs is a simple plugin that adds a `breadcrumbs` object to controllers and views.
|