ariane 0.0.2 → 0.0.3
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/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +16 -1
- data/Rakefile +5 -0
- data/ariane.gemspec +1 -0
- data/lib/ariane.rb +60 -0
- data/lib/ariane/breadcrumb.rb +44 -2
- data/lib/ariane/crumb.rb +13 -2
- data/lib/ariane/rails/controller_helper.rb +1 -0
- data/lib/ariane/rails/view_helper.rb +1 -0
- data/lib/ariane/render/base.rb +21 -2
- data/lib/ariane/render/html.rb +97 -0
- data/lib/ariane/render/html_list.rb +91 -2
- data/lib/ariane/version.rb +2 -1
- data/spec/ariane/breadcrumb_spec.rb +16 -17
- data/spec/ariane/crumb_spec.rb +36 -18
- data/spec/ariane/render/html_list_spec.rb +4 -0
- metadata +21 -8
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.0.3
|
4
|
+
|
5
|
+
* FIX: The HTMLList divider is now rendered correctly (@PatrickMa)
|
6
|
+
* FIX: #2 A Crumb should be able to store random data
|
7
|
+
* IMPROVED: Most of the code is now documented
|
8
|
+
* IMPROVED: The tests are now using subject (@PatrickMa)
|
9
|
+
|
3
10
|
## 0.0.2
|
4
11
|
|
5
12
|
* FIX: HTML#link and HTMLLink#link return a non html safe string when return
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
# Ariane
|
1
|
+
# Ariane [](http://travis-ci.org/simonc/ariane)
|
2
2
|
|
3
3
|
Ariane is a flexible breadcrumb system for Rails. And it's fully compatible with
|
4
4
|
the [Twitter Bootstrap](http://twitter.github.com/bootstrap/) !
|
5
5
|
|
6
|
+
It works perfectly with Rails 3 and allows to use I18n.
|
7
|
+
|
6
8
|
## Installation
|
7
9
|
|
8
10
|
Add the following line to your `Gemfile`:
|
@@ -11,6 +13,10 @@ Add the following line to your `Gemfile`:
|
|
11
13
|
gem 'ariane'
|
12
14
|
```
|
13
15
|
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
bundle
|
19
|
+
|
14
20
|
## Requirements
|
15
21
|
|
16
22
|
* Ruby >= 1.9.x
|
@@ -179,6 +185,15 @@ You'll obtain the following HTML:
|
|
179
185
|
You can create a complete renderer, simply take a look at
|
180
186
|
`lib/ariane/render/html.rb` for a complete example implementation.
|
181
187
|
|
188
|
+
### I18n
|
189
|
+
|
190
|
+
Since Ariane is used in before filters or in the views, it supports
|
191
|
+
I18n out of the box.
|
192
|
+
|
193
|
+
``` ruby
|
194
|
+
ariane.add t('home'), root_path
|
195
|
+
```
|
196
|
+
|
182
197
|
## Boring legal stuff
|
183
198
|
|
184
199
|
Copyright (c) 2012, Simon COURTOIS
|
data/Rakefile
CHANGED
data/ariane.gemspec
CHANGED
data/lib/ariane.rb
CHANGED
@@ -9,39 +9,99 @@ module Ariane
|
|
9
9
|
class << self
|
10
10
|
attr_accessor :request
|
11
11
|
|
12
|
+
# Public: Provides a simple way to access Ariane configuration.
|
13
|
+
#
|
14
|
+
# Yields self.
|
15
|
+
#
|
16
|
+
# Examples
|
17
|
+
#
|
18
|
+
# Ariane.configure do |config|
|
19
|
+
# config.default_renderer = SomeRendererClass
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# Returns nothing.
|
12
23
|
def configure
|
13
24
|
yield self
|
14
25
|
end
|
15
26
|
|
27
|
+
# Internal: Sets the request environment.
|
28
|
+
#
|
29
|
+
# If the :breadcrumb key is not present in the environment, it will be set
|
30
|
+
# to a new instance of Breadcrumb.
|
31
|
+
#
|
32
|
+
# Returns nothing.
|
16
33
|
def request_env=(environment)
|
17
34
|
@request_env = environment
|
18
35
|
@request_env[:breadcrumb] ||= Breadcrumb.new
|
19
36
|
end
|
20
37
|
|
38
|
+
# Internal: Gets the request environment.
|
39
|
+
#
|
40
|
+
# Returns a Hash containing the request environment.
|
21
41
|
def request_env
|
22
42
|
@request_env if defined?(@request_env)
|
23
43
|
end
|
24
44
|
|
45
|
+
# Internal: Gets the request id.
|
46
|
+
#
|
47
|
+
# Returns the current request id.
|
25
48
|
def request
|
26
49
|
@request_id if defined? @request_id
|
27
50
|
end
|
28
51
|
|
52
|
+
# Internal: Sets the request id.
|
53
|
+
#
|
54
|
+
# request_id - The request id.
|
55
|
+
#
|
56
|
+
# Returns nothing.
|
29
57
|
def request=(request_id)
|
30
58
|
@request_id = request_id
|
31
59
|
end
|
32
60
|
|
61
|
+
# Internal: Gets the Breadcrumb.
|
62
|
+
#
|
63
|
+
# Returns a Breadcrumb.
|
33
64
|
def breadcrumb
|
34
65
|
@request_env[:breadcrumb]
|
35
66
|
end
|
36
67
|
|
68
|
+
# Internal: Sets the Breadcrumb.
|
69
|
+
#
|
70
|
+
# Returns nothing.
|
37
71
|
def breadcrumb=(breadcrumb)
|
38
72
|
@request_env[:breadcrumb] = breadcrumb
|
39
73
|
end
|
40
74
|
|
75
|
+
# Public: Returns the default renderer used by Ariane.
|
76
|
+
#
|
77
|
+
# If the default renderer hasn't been set yeat, it will be set
|
78
|
+
# as a new Ariane::Render::HTMLList instance.
|
79
|
+
#
|
80
|
+
# Examples
|
81
|
+
#
|
82
|
+
# Ariane.default_renderer
|
83
|
+
# # => #<Ariane::Render::HTMLList ...>
|
84
|
+
#
|
85
|
+
# Returns the default renderer.
|
41
86
|
def default_renderer
|
42
87
|
@default_renderer ||= Ariane::Render::HTMLList.new
|
43
88
|
end
|
44
89
|
|
90
|
+
# Public: Sets the default renderer used by Ariane.
|
91
|
+
#
|
92
|
+
# renderer - An instance or a class that will be used as default renderer
|
93
|
+
# by Ariane. If a class is given the default renderer will be set
|
94
|
+
# to a new instance of this class.
|
95
|
+
#
|
96
|
+
# Examples
|
97
|
+
#
|
98
|
+
# Ariane.default_renderer = SomeRendererClass.new
|
99
|
+
#
|
100
|
+
# Ariane.default_renderer = SomeRendererClass
|
101
|
+
# Ariane.default_renderer
|
102
|
+
# # => #<SomeRendererClass ...>
|
103
|
+
#
|
104
|
+
# Returns the default renderer.
|
45
105
|
def default_renderer=(renderer)
|
46
106
|
@default_renderer = renderer.is_a?(Class) ? renderer.new : renderer
|
47
107
|
end
|
data/lib/ariane/breadcrumb.rb
CHANGED
@@ -1,17 +1,59 @@
|
|
1
1
|
require 'ariane/crumb'
|
2
2
|
|
3
3
|
module Ariane
|
4
|
+
# Internal: The Breadcrumb class is used to interact with the crumbs list.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# ariane.add 'Home', root_path
|
9
|
+
#
|
10
|
+
# ariane.render
|
4
11
|
class Breadcrumb
|
12
|
+
# Internal: Returns the list of crumbs.
|
13
|
+
#
|
14
|
+
# Examples
|
15
|
+
#
|
16
|
+
# ariane.crumbs
|
17
|
+
# # => [#<Crumb ...>, ...]
|
18
|
+
#
|
19
|
+
# Returns an Array containing a list of Crumb objects.
|
5
20
|
def crumbs
|
6
21
|
@crumbs ||= []
|
7
22
|
end
|
8
23
|
|
9
|
-
|
10
|
-
|
24
|
+
# Public: Add a Crumb to the crumbs list.
|
25
|
+
#
|
26
|
+
# args - Any arguments that can be passed to Crumb#initialize.
|
27
|
+
#
|
28
|
+
# Yields the new Crumb before it is added to the list.
|
29
|
+
#
|
30
|
+
# Examples
|
31
|
+
#
|
32
|
+
# ariane.add 'Home', root_path
|
33
|
+
# ariane.add 'Other'
|
34
|
+
# ariane.add 'Foo', root_path, :foo => :bar
|
35
|
+
#
|
36
|
+
# Returns nothing.
|
37
|
+
def add(*args)
|
38
|
+
new_crumb = Crumb.new(*args)
|
11
39
|
yield new_crumb if block_given?
|
12
40
|
crumbs << new_crumb
|
13
41
|
end
|
14
42
|
|
43
|
+
# Public: Renders the breadcrumb.
|
44
|
+
#
|
45
|
+
# If no renderer is provided, Ariane's default_renderer will be used.
|
46
|
+
#
|
47
|
+
# renderer - An instance or a class that will be used to render the
|
48
|
+
# breadcrumb. If a class is given the renderer will be set
|
49
|
+
# to a new instance of this class (default: nil).
|
50
|
+
#
|
51
|
+
# Examples
|
52
|
+
#
|
53
|
+
# ariane.render
|
54
|
+
# ariane.render(SomeRendererClass)
|
55
|
+
#
|
56
|
+
# Returns a String representing the breadcrumb.
|
15
57
|
def render(renderer=nil)
|
16
58
|
renderer ||= Ariane.default_renderer
|
17
59
|
renderer = renderer.new if renderer.is_a?(Class)
|
data/lib/ariane/crumb.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
|
3
3
|
module Ariane
|
4
|
+
# Internal: Stores the data related to a single crumb.
|
4
5
|
class Crumb
|
5
|
-
|
6
|
+
# Public: Gets/Sets the String data of the crumb.
|
7
|
+
# Public: Gets/Sets the String text of the crumb.
|
8
|
+
# Public: Gets/Sets the String url of the crumb.
|
9
|
+
attr_accessor :data, :text, :url
|
6
10
|
|
7
|
-
|
11
|
+
# Internal: Initialize a Crumb.
|
12
|
+
#
|
13
|
+
# text - A String representing the text of the crumb (default: '').
|
14
|
+
# url - A String representing the url of the crumb (default: nil).
|
15
|
+
# data - A Hash used to store any data that can be used by renderers
|
16
|
+
# (default: {}).
|
17
|
+
def initialize(text='', url=nil, data={})
|
8
18
|
@text = text
|
9
19
|
@url = url
|
20
|
+
@data = data
|
10
21
|
end
|
11
22
|
end
|
12
23
|
end
|
data/lib/ariane/render/base.rb
CHANGED
@@ -1,23 +1,42 @@
|
|
1
1
|
module Ariane
|
2
2
|
module Render
|
3
3
|
|
4
|
+
# Internal: Base renderer from which every renderer inherits.
|
4
5
|
class Base
|
6
|
+
# Internal: Gets/Sets the Hash options.
|
5
7
|
attr_accessor :options
|
6
8
|
|
9
|
+
# Public: Initialize a Base renderer.
|
10
|
+
#
|
11
|
+
# options - A Hash containing options for the renderer (default: {}):
|
12
|
+
# :divider - The String divider used to separate crumbs
|
13
|
+
# (default: Base#divider).
|
7
14
|
def initialize(options={})
|
8
15
|
@options = {
|
9
|
-
divider:
|
16
|
+
divider: ' / '
|
10
17
|
}.merge(options)
|
11
18
|
end
|
12
19
|
|
20
|
+
# Internal: Renders the breadcrumbs.
|
21
|
+
#
|
22
|
+
# This method MUST be overridden by any renderer inheriting from Base.
|
23
|
+
#
|
24
|
+
# crumbs - An Array containing a list of Crumb objects composing the
|
25
|
+
# breadcrumb.
|
26
|
+
#
|
27
|
+
# Returns nothing.
|
28
|
+
# Raises RuntimeError everytime.
|
13
29
|
def render(crumbs)
|
14
30
|
raise 'the render method is not implemented in your Ariane renderer'
|
15
31
|
end
|
16
32
|
|
33
|
+
# Public: Returns the divider used to separate crumbs.
|
34
|
+
#
|
35
|
+
# Returns the String ' / '.
|
17
36
|
def divider
|
18
37
|
' / '
|
19
38
|
end
|
20
39
|
end
|
21
40
|
|
22
41
|
end
|
23
|
-
end
|
42
|
+
end
|
data/lib/ariane/render/html.rb
CHANGED
@@ -4,13 +4,37 @@ require 'action_view'
|
|
4
4
|
module Ariane
|
5
5
|
module Render
|
6
6
|
|
7
|
+
# Public: HTML renderer.
|
8
|
+
#
|
9
|
+
# Displays the breadcrumb as follows:
|
10
|
+
#
|
11
|
+
# <p class="breadcrumb">
|
12
|
+
# <a href="/">Home</a> / Other
|
13
|
+
# </p>
|
14
|
+
#
|
7
15
|
class HTML < Base
|
8
16
|
include ActionView::Helpers::TagHelper
|
9
17
|
include ActionView::Helpers::UrlHelper
|
10
18
|
include ActionView::Helpers::OutputSafetyHelper
|
11
19
|
|
20
|
+
# Public: Gets/Sets the String output_buffer.
|
12
21
|
attr_accessor :output_buffer
|
13
22
|
|
23
|
+
# Public: Initialize an HTML renderer.
|
24
|
+
#
|
25
|
+
# options - A Hash containing options for the renderer (default: {}):
|
26
|
+
# :active_class - The String class used for active Crumb when
|
27
|
+
# rendered as a link (default: 'active').
|
28
|
+
# :divider - The String divider used to separate crumbs
|
29
|
+
# (default: Base#divider).
|
30
|
+
# :link_active - A Boolean telling if the active Crumb should
|
31
|
+
# be rendered as a link (default: false).
|
32
|
+
# :link_class - The String html class for each link
|
33
|
+
# (default: nil).
|
34
|
+
# :list_class - The String html class used for the crumbs list
|
35
|
+
# container (default: 'breadcrumb').
|
36
|
+
# :list_id - The String html id used for the crumbs list
|
37
|
+
# container (default: nil).
|
14
38
|
def initialize(options={})
|
15
39
|
options = {
|
16
40
|
active_class: 'active',
|
@@ -23,16 +47,51 @@ module Ariane
|
|
23
47
|
super(options)
|
24
48
|
end
|
25
49
|
|
50
|
+
# Public: Renders the breadcrumb.
|
51
|
+
#
|
52
|
+
# crumbs - An Array containing a list of Crumb objects composing the
|
53
|
+
# breadcrumb.
|
54
|
+
#
|
55
|
+
# Examples
|
56
|
+
#
|
57
|
+
# html.render(crumbs)
|
58
|
+
# # => "<p class=\"breadcrumb\"><a href=\"/\">Home</a> / Other</p>"
|
59
|
+
#
|
60
|
+
# Returns an html safe String representing the breadcrumb to print.
|
26
61
|
def render(crumbs)
|
27
62
|
list(crumbs).html_safe
|
28
63
|
end
|
29
64
|
|
65
|
+
# Public: Defines the breadcrumb container.
|
66
|
+
#
|
67
|
+
# crumbs - An Array containing a list of Crumb objects composing the
|
68
|
+
# breadcrumb.
|
69
|
+
#
|
70
|
+
# Examples
|
71
|
+
#
|
72
|
+
# html.list(crumbs)
|
73
|
+
# # => "<p class=\"breadcrumb\"> ... </p>"
|
74
|
+
# # The String returned cannot be considered as html safe.
|
75
|
+
#
|
76
|
+
# Returns a non html safe String representing the breadcrumb.
|
30
77
|
def list(crumbs)
|
31
78
|
content_tag(:p, id: options[:list_id], class: options[:list_class]) do
|
32
79
|
raw items(crumbs)
|
33
80
|
end
|
34
81
|
end
|
35
82
|
|
83
|
+
# Public: Returns the rendered list of breadcrumb items.
|
84
|
+
#
|
85
|
+
# crumbs - An Array containing a list of Crumb objects composing the
|
86
|
+
# breadcrumb.
|
87
|
+
#
|
88
|
+
# Examples
|
89
|
+
#
|
90
|
+
# html.items(crumbs)
|
91
|
+
# # => "<a href=\"/\">Home</a> / Other"
|
92
|
+
# # The String returned cannot be considered as html safe.
|
93
|
+
#
|
94
|
+
# Returns a non html safe String representing the breadcrumb items.
|
36
95
|
def items(crumbs)
|
37
96
|
crumbs.inject('') do |out, crumb|
|
38
97
|
active = crumb == crumbs.last
|
@@ -41,12 +100,50 @@ module Ariane
|
|
41
100
|
end
|
42
101
|
end
|
43
102
|
|
103
|
+
# Public: Returns a rendered breadcrumb item.
|
104
|
+
#
|
105
|
+
# Appends the divider unless active is true.
|
106
|
+
#
|
107
|
+
# crumb - The Crumb item to be rendered.
|
108
|
+
# active - A Boolean indicating if the Crumb is active or not
|
109
|
+
# (default: false).
|
110
|
+
#
|
111
|
+
# Examples
|
112
|
+
#
|
113
|
+
# html.item(crumb)
|
114
|
+
# # => "<a href=\"/\">Home</a> /"
|
115
|
+
#
|
116
|
+
# html.item(crumb, true)
|
117
|
+
# # => "Home"
|
118
|
+
#
|
119
|
+
# Returns an hmtl safe String representing a rendered Crumb item.
|
44
120
|
def item(crumb, active=false)
|
45
121
|
out = link(crumb, active)
|
46
122
|
out << options[:divider] if options[:divider] && !active
|
47
123
|
out
|
48
124
|
end
|
49
125
|
|
126
|
+
# Public: Returns a Crumb link.
|
127
|
+
#
|
128
|
+
# crumb - The Crumb item to be rendered.
|
129
|
+
# active - A Boolean indicating if the Crumb is active or not
|
130
|
+
# (default: false).
|
131
|
+
#
|
132
|
+
# Examples
|
133
|
+
#
|
134
|
+
# html.link(crumb)
|
135
|
+
# # => "<a href=\"/\">Home</a>"
|
136
|
+
#
|
137
|
+
# # If the :link_active option is false:
|
138
|
+
# html.link(crumb, true)
|
139
|
+
# # => "Home"
|
140
|
+
#
|
141
|
+
# # If the :link_active option is true and
|
142
|
+
# # the :link_class option is set to 'active':
|
143
|
+
# html.link(crumb, true)
|
144
|
+
# # => "<a href=\"/\" class=\"active\">Home</a>"
|
145
|
+
#
|
146
|
+
# Returns an html safe String representing the link for the Crumb item.
|
50
147
|
def link(crumb, active=false)
|
51
148
|
classes = options[:link_class]
|
52
149
|
|
@@ -3,7 +3,36 @@ require 'ariane/render/html'
|
|
3
3
|
module Ariane
|
4
4
|
module Render
|
5
5
|
|
6
|
+
# Public: HTML renderer.
|
7
|
+
#
|
8
|
+
# Displays the breadcrumb as follows:
|
9
|
+
#
|
10
|
+
# <ul class="breadcrumb">
|
11
|
+
# <li>
|
12
|
+
# <a href="/">Home</a>
|
13
|
+
# <span class="divider">/</span>
|
14
|
+
# </li>
|
15
|
+
# <li>Other</li>
|
16
|
+
# </ul>
|
17
|
+
#
|
6
18
|
class HTMLList < HTML
|
19
|
+
# Public: Initialize an HMTLList renderer.
|
20
|
+
#
|
21
|
+
# options - A Hash containing options for the renderer (default: {}):
|
22
|
+
# :active_class - The String class used for active Crumb when
|
23
|
+
# rendered as a link (default: 'active').
|
24
|
+
# :divider - The String divider used to separate crumbs
|
25
|
+
# (default: HTMLList#divider).
|
26
|
+
# :item_class - A String class used for each breadcrumb item
|
27
|
+
# (default: nil).
|
28
|
+
# :link_active - A Boolean telling if the active Crumb should
|
29
|
+
# be rendered as a link (default: false).
|
30
|
+
# :link_class - The String html class for each link
|
31
|
+
# (default: nil).
|
32
|
+
# :list_class - The String html class used for the crumbs list
|
33
|
+
# container (default: 'breadcrumb').
|
34
|
+
# :list_id - The String html id used for the crumbs list
|
35
|
+
# container (default: nil).
|
7
36
|
def initialize(options={})
|
8
37
|
options = {
|
9
38
|
item_class: nil
|
@@ -12,12 +41,48 @@ module Ariane
|
|
12
41
|
super(options)
|
13
42
|
end
|
14
43
|
|
44
|
+
# Public: Defines the breadcrumb container.
|
45
|
+
#
|
46
|
+
# crumbs - An Array containing a list of Crumb objects composing the
|
47
|
+
# breadcrumb.
|
48
|
+
#
|
49
|
+
# Examples
|
50
|
+
#
|
51
|
+
# htmllist.list(crumbs)
|
52
|
+
# # => "<ul class=\"breadcrumb\"> ... </ul>"
|
53
|
+
# # The String returned cannot be considered as html safe.
|
54
|
+
#
|
55
|
+
# Returns a non html safe String representing the breadcrumb.
|
15
56
|
def list(crumbs)
|
16
57
|
content_tag(:ul, id: options[:list_id], class: options[:list_class]) do
|
17
58
|
raw items(crumbs)
|
18
59
|
end
|
19
60
|
end
|
20
61
|
|
62
|
+
# Public: Returns a rendered breadcrumb item.
|
63
|
+
#
|
64
|
+
# Appends the divider unless active is true.
|
65
|
+
#
|
66
|
+
# crumb - The Crumb item to be rendered.
|
67
|
+
# active - A Boolean indicating if the Crumb is active or not
|
68
|
+
# (default: false).
|
69
|
+
#
|
70
|
+
# Examples
|
71
|
+
#
|
72
|
+
# htmllist.item(crumb)
|
73
|
+
# # => "<li><a href=\"/\">Home</a><span class=\"divider\">/</span></li>"
|
74
|
+
#
|
75
|
+
# # If the :item_class options is set to 'crumb':
|
76
|
+
# htmllist.item(crumb)
|
77
|
+
# # => "<li class=\"crumb\"> ... </li>"
|
78
|
+
#
|
79
|
+
# htmllist.item(crumb, true)
|
80
|
+
# # => "<li>Home</li>"
|
81
|
+
#
|
82
|
+
# htmllist.item(crumb, true)
|
83
|
+
# # => "<li class=\"active\">Home</li>"
|
84
|
+
#
|
85
|
+
# Returns an hmtl safe String representing a rendered Crumb item.
|
21
86
|
def item(crumb, active=false)
|
22
87
|
classes = options[:item_class]
|
23
88
|
|
@@ -28,11 +93,27 @@ module Ariane
|
|
28
93
|
|
29
94
|
content_tag(:li, class: classes) do
|
30
95
|
out = link(crumb, active)
|
31
|
-
out <<
|
96
|
+
out << divider unless active
|
32
97
|
out
|
33
98
|
end
|
34
99
|
end
|
35
100
|
|
101
|
+
# Public: Returns a Crumb link.
|
102
|
+
#
|
103
|
+
# crumb - The Crumb item to be rendered.
|
104
|
+
# active - A Boolean indicating if the Crumb is active or not
|
105
|
+
# (default: false).
|
106
|
+
#
|
107
|
+
# Examples
|
108
|
+
#
|
109
|
+
# htmllist.link(crumb)
|
110
|
+
# # => "<a href=\"/\">Home</a>"
|
111
|
+
#
|
112
|
+
# # If the :link_active option is false:
|
113
|
+
# htmllist.link(crumb, true)
|
114
|
+
# # => "Home"
|
115
|
+
#
|
116
|
+
# Returns an html safe String representing the link for the Crumb item.
|
36
117
|
def link(crumb, active=false)
|
37
118
|
link_active = !active || options[:link_active]
|
38
119
|
if crumb.url && link_active
|
@@ -43,8 +124,16 @@ module Ariane
|
|
43
124
|
link.html_safe
|
44
125
|
end
|
45
126
|
|
127
|
+
# Public: Returns the divider used to separate crumbs.
|
128
|
+
#
|
129
|
+
# Examples
|
130
|
+
#
|
131
|
+
# htmllist.divider
|
132
|
+
# # => "<span class=\"divider\">/</span>"
|
133
|
+
#
|
134
|
+
# Returns the String representing the html divider.
|
46
135
|
def divider
|
47
|
-
content_tag(:span,
|
136
|
+
content_tag(:span, options[:divider].strip, class: 'divider')
|
48
137
|
end
|
49
138
|
end
|
50
139
|
|
data/lib/ariane/version.rb
CHANGED
@@ -2,13 +2,15 @@ require 'ariane'
|
|
2
2
|
|
3
3
|
module Ariane
|
4
4
|
describe Breadcrumb do
|
5
|
+
subject { Breadcrumb.new }
|
6
|
+
|
5
7
|
describe "#crumbs" do
|
6
8
|
it "has a crumbs method that returns an Enumerable" do
|
7
|
-
|
9
|
+
subject.crumbs.is_a?(Enumerable).should be_true
|
8
10
|
end
|
9
11
|
|
10
12
|
it "set the crumbs to an empty Enumerable by default" do
|
11
|
-
crumbs =
|
13
|
+
crumbs = subject.crumbs
|
12
14
|
crumbs.respond_to?(:count).should be_true
|
13
15
|
crumbs.count.should be(0)
|
14
16
|
end
|
@@ -16,19 +18,18 @@ module Ariane
|
|
16
18
|
|
17
19
|
describe "#add" do
|
18
20
|
it "creates a new crumb and push it to crumbs" do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
subject.add 'text', 'url', :foo => :bar
|
22
|
+
subject.crumbs.count.should be(1)
|
23
|
+
subject.crumbs.last.text.should == 'text'
|
24
|
+
subject.crumbs.last.url.should == 'url'
|
25
|
+
subject.crumbs.last.data.should == { :foo => :bar }
|
24
26
|
end
|
25
27
|
|
26
28
|
it "yields passing the new crumb if a block is given" do
|
27
|
-
|
28
|
-
breadcrumb.add 'text' do |crumb|
|
29
|
+
subject.add 'text' do |crumb|
|
29
30
|
crumb.url = 'url'
|
30
31
|
end
|
31
|
-
|
32
|
+
subject.crumbs.last.url.should == 'url'
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
@@ -38,10 +39,9 @@ module Ariane
|
|
38
39
|
|
39
40
|
it "uses Ariane's default renderer if none is passed as argument" do
|
40
41
|
Ariane.default_renderer = test_renderer
|
41
|
-
|
42
|
-
breadcrumb.add 'text', 'url'
|
42
|
+
subject.add 'text', 'url'
|
43
43
|
test_renderer.should_receive(:render)
|
44
|
-
|
44
|
+
subject.render
|
45
45
|
end
|
46
46
|
|
47
47
|
it "instanciates the renderer if a class is given" do
|
@@ -54,10 +54,9 @@ module Ariane
|
|
54
54
|
end
|
55
55
|
|
56
56
|
it "calls render on the renderer, passing it the cumbs" do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
breadcrumb.render(test_renderer)
|
57
|
+
subject.add 'text', 'url'
|
58
|
+
test_renderer.should_receive(:render).with(subject.crumbs)
|
59
|
+
subject.render(test_renderer)
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
data/spec/ariane/crumb_spec.rb
CHANGED
@@ -2,33 +2,51 @@ require 'ariane/crumb'
|
|
2
2
|
|
3
3
|
module Ariane
|
4
4
|
describe Crumb do
|
5
|
-
|
6
|
-
Crumb.new.respond_to?(:text)
|
7
|
-
end
|
5
|
+
subject { Crumb.new }
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
describe ".new" do
|
8
|
+
it "sets its text attribute based on the first argument of the initializer" do
|
9
|
+
crumb = Crumb.new('test')
|
10
|
+
crumb.text.should == 'test'
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
it "sets its url attribute based on the second argument of the initializer" do
|
14
|
+
crumb = Crumb.new('text', 'test-url')
|
15
|
+
crumb.url.should == 'test-url'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets its data based on third argument of the initializer" do
|
19
|
+
crumb = Crumb.new('text', 'url', :foo => :bar)
|
20
|
+
crumb.data.should == { :foo => :bar }
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
24
|
+
describe "#text" do
|
25
|
+
it "sets text as an empty string by default" do
|
26
|
+
subject.text.should == ''
|
27
|
+
end
|
19
28
|
|
20
|
-
|
21
|
-
|
29
|
+
it "has a setter for the text attribute" do
|
30
|
+
subject.text = 'test'
|
31
|
+
subject.text.should == 'test'
|
32
|
+
end
|
22
33
|
end
|
23
34
|
|
24
|
-
|
25
|
-
|
35
|
+
describe "#url" do
|
36
|
+
it "sets url as nil by default" do
|
37
|
+
subject.url.should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a setter for the url attribute" do
|
41
|
+
subject.url = '/'
|
42
|
+
subject.url.should == '/'
|
43
|
+
end
|
26
44
|
end
|
27
45
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
46
|
+
describe "#data" do
|
47
|
+
it "has a data attribute which is a hash" do
|
48
|
+
subject.data.should == {}
|
49
|
+
end
|
32
50
|
end
|
33
51
|
end
|
34
52
|
end
|
@@ -106,6 +106,10 @@ module Ariane
|
|
106
106
|
it "returns the HTML list divider" do
|
107
107
|
HTMLList.new.divider.should == '<span class="divider">/</span>'
|
108
108
|
end
|
109
|
+
|
110
|
+
it "returns the HTML list divider for a custom divider" do
|
111
|
+
HTMLList.new(divider: ' > ').divider.should == '<span class="divider">></span>'
|
112
|
+
end
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ariane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70159377260060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70159377260060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70159377256400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: 2.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70159377256400
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70159377253500 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70159377253500
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rspec
|
38
|
-
requirement: &
|
49
|
+
requirement: &70159377252560 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70159377252560
|
47
58
|
description: Ariane is a flexible breadcrumb system for Rails. It is fully compatible
|
48
59
|
with the Twitter Bootstrap and can be adapted to any kind of output.
|
49
60
|
email:
|
@@ -53,6 +64,7 @@ extensions: []
|
|
53
64
|
extra_rdoc_files: []
|
54
65
|
files:
|
55
66
|
- .gitignore
|
67
|
+
- .travis.yml
|
56
68
|
- CHANGELOG.md
|
57
69
|
- COPYING
|
58
70
|
- Gemfile
|
@@ -108,3 +120,4 @@ test_files:
|
|
108
120
|
- spec/ariane/render/html_list_spec.rb
|
109
121
|
- spec/ariane/render/html_spec.rb
|
110
122
|
- spec/ariane_spec.rb
|
123
|
+
has_rdoc:
|