ariane 0.0.1
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 +4 -0
- data/COPYING +13 -0
- data/Gemfile +4 -0
- data/README.md +196 -0
- data/Rakefile +1 -0
- data/ariane.gemspec +25 -0
- data/lib/ariane.rb +49 -0
- data/lib/ariane/breadcrumb.rb +21 -0
- data/lib/ariane/crumb.rb +12 -0
- data/lib/ariane/rails.rb +2 -0
- data/lib/ariane/rails/controller_helper.rb +15 -0
- data/lib/ariane/rails/view_helper.rb +9 -0
- data/lib/ariane/render.rb +3 -0
- data/lib/ariane/render/base.rb +23 -0
- data/lib/ariane/render/html.rb +69 -0
- data/lib/ariane/render/html_list.rb +52 -0
- data/lib/ariane/version.rb +3 -0
- data/spec/ariane/breadcrumb_spec.rb +64 -0
- data/spec/ariane/crumb_spec.rb +34 -0
- data/spec/ariane/render/base_spec.rb +46 -0
- data/spec/ariane/render/html_list_spec.rb +99 -0
- data/spec/ariane/render/html_spec.rb +128 -0
- data/spec/ariane_spec.rb +52 -0
- metadata +109 -0
data/.gitignore
ADDED
data/COPYING
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012, Simon COURTOIS
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
4
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
5
|
+
and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
13
|
+
THIS SOFTWARE.
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
# Ariane
|
2
|
+
|
3
|
+
Ariane is a flexible breadcrumb system for Rails. And it's fully compatible with
|
4
|
+
the [Twitter Bootstrap](http://twitter.github.com/bootstrap/) !
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add the following line to your `Gemfile`:
|
9
|
+
|
10
|
+
``` ruby
|
11
|
+
gem 'ariane'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Requirements
|
15
|
+
|
16
|
+
* Ruby >= 1.9.x
|
17
|
+
|
18
|
+
## Quickstart
|
19
|
+
|
20
|
+
To get started, define a before_filter in your `ApplicationController` and use
|
21
|
+
it to add the first entry:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
class ApplicationController < ActionController::Base
|
25
|
+
before_filter :set_ariane
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def set_ariane
|
30
|
+
ariane.add 'Home', root_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
You can then add more entries from your other controllers:
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
class OtherController < ApplicationController
|
39
|
+
protected
|
40
|
+
|
41
|
+
def set_ariane
|
42
|
+
super
|
43
|
+
ariane.add 'Other', other_path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Then in your layout, simply call `ariane.render` to see the magic happen:
|
49
|
+
|
50
|
+
``` erb
|
51
|
+
<%= ariane.render %>
|
52
|
+
```
|
53
|
+
|
54
|
+
This will render the following:
|
55
|
+
|
56
|
+
``` html
|
57
|
+
<ul class="breadcrumb">
|
58
|
+
<li>
|
59
|
+
<a href="/">Home</a>
|
60
|
+
<span class="divider">/</span>
|
61
|
+
</li>
|
62
|
+
<li class="active">Other</li>
|
63
|
+
</ul>
|
64
|
+
```
|
65
|
+
## ariane.add
|
66
|
+
|
67
|
+
`ariane.add` takes two arguments, both being optional.
|
68
|
+
|
69
|
+
* `text` is the text to use as link text
|
70
|
+
* `url` is the path to where you want the link to point
|
71
|
+
|
72
|
+
Note that if you don't set the url, the text will simply be rendered as is.
|
73
|
+
|
74
|
+
Alternatively, you can pass a block to `ariane.add`. The block will receive the new crumb as argument.
|
75
|
+
|
76
|
+
``` ruby
|
77
|
+
ariane.add do |crumb|
|
78
|
+
crumb.text = 'Home'
|
79
|
+
crumb.url = root_path
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
## Customize the output
|
84
|
+
|
85
|
+
Ariane provides a set of renderers you can use to generate the output. To see
|
86
|
+
the options you can use with each renderer, take a look at the wiki.
|
87
|
+
|
88
|
+
The default renderer is `HTMLList` but you can select another one.
|
89
|
+
|
90
|
+
### Using ariane.render
|
91
|
+
|
92
|
+
You can choose the renderer when calling `ariane.render` by passing it as the
|
93
|
+
first argument:
|
94
|
+
|
95
|
+
``` erb
|
96
|
+
<%= ariane.render(Ariane::Render::HTML) %>
|
97
|
+
```
|
98
|
+
|
99
|
+
This will render the following text:
|
100
|
+
|
101
|
+
``` html
|
102
|
+
<p class="breadcrumb">
|
103
|
+
<a href="/">Home</a> / Other
|
104
|
+
</p>
|
105
|
+
```
|
106
|
+
|
107
|
+
### Using an initializer
|
108
|
+
|
109
|
+
You may also choose to set the renderer when Rails is loaded:
|
110
|
+
|
111
|
+
``` ruby
|
112
|
+
# config/initializers/ariane.rb
|
113
|
+
Ariane.configure do |config|
|
114
|
+
config.default_renderer = Ariane::Render::HTML
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
If you want further customization, you can instanciate the renderer and then use
|
119
|
+
it in `Ariane.configure`.
|
120
|
+
|
121
|
+
``` ruby
|
122
|
+
# config/initializers/ariane.rb
|
123
|
+
rndr = Ariane::Render::HTML.new(divider: ' | ')
|
124
|
+
|
125
|
+
Ariane.configure do |config|
|
126
|
+
config.default_renderer = rndr
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
Calling `ariane.render` will output the following HTML:
|
131
|
+
|
132
|
+
```
|
133
|
+
<p class="breadcrumb">
|
134
|
+
<a href="/">Home</a> | Other
|
135
|
+
</p>
|
136
|
+
```
|
137
|
+
|
138
|
+
## Bring your own Renderer
|
139
|
+
|
140
|
+
Ariane is flexible enough to let you define or extend renderers.
|
141
|
+
|
142
|
+
``` ruby
|
143
|
+
class HTMLOrderedList < Ariane::Render::HTMLList
|
144
|
+
def list(crumbs)
|
145
|
+
content_tag(:ol, class: options[:list_class]) do
|
146
|
+
raw items(crumbs)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def divider
|
151
|
+
content_tag(:span, '|', class: 'separator')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
This example is simple but shows that you can touch pretty anything in the
|
157
|
+
renderers.
|
158
|
+
|
159
|
+
Now if you call
|
160
|
+
|
161
|
+
``` erb
|
162
|
+
<%= ariane.render(HTMLOrderedList) %>
|
163
|
+
```
|
164
|
+
|
165
|
+
You'll obtain the following HTML:
|
166
|
+
|
167
|
+
``` html
|
168
|
+
<ol class="breadcrumb">
|
169
|
+
<li>
|
170
|
+
<a href="/">Home</a>
|
171
|
+
<span class="separator">|</span>
|
172
|
+
</li>
|
173
|
+
<li class="active">Other</li>
|
174
|
+
</ul>
|
175
|
+
```
|
176
|
+
|
177
|
+
### Create a renderer from scratch
|
178
|
+
|
179
|
+
You can create a complete renderer, simply take a look at
|
180
|
+
`lib/ariane/render/html.rb` for a complete example implementation.
|
181
|
+
|
182
|
+
## Boring legal stuff
|
183
|
+
|
184
|
+
Copyright (c) 2012, Simon COURTOIS
|
185
|
+
|
186
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
187
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
188
|
+
and this permission notice appear in all copies.
|
189
|
+
|
190
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
191
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
192
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
193
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
194
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
195
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
196
|
+
THIS SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ariane.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ariane/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ariane"
|
7
|
+
s.version = Ariane::VERSION
|
8
|
+
s.authors = ["Simon COURTOIS"]
|
9
|
+
s.email = ["scourtois@cubyx.fr"]
|
10
|
+
s.homepage = "http://github.com/simonc/ariane"
|
11
|
+
s.summary = "A flexible breadcrumb system for Rails, fully compatible " \
|
12
|
+
"with the Twitter Bootstrap."
|
13
|
+
s.description = "Ariane is a flexible breadcrumb system for Rails. It is " \
|
14
|
+
"fully compatible with the Twitter Bootstrap and can be " \
|
15
|
+
"adapted to any kind of output."
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "actionpack", ">= 2.3.0"
|
23
|
+
s.add_dependency "activesupport", ">= 2.3.0"
|
24
|
+
s.add_development_dependency "rspec"
|
25
|
+
end
|
data/lib/ariane.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ariane/version'
|
2
|
+
require 'ariane/crumb'
|
3
|
+
require 'ariane/breadcrumb'
|
4
|
+
require 'ariane/render'
|
5
|
+
|
6
|
+
require 'ariane/rails' if defined?(Rails)
|
7
|
+
|
8
|
+
module Ariane
|
9
|
+
class << self
|
10
|
+
attr_accessor :request
|
11
|
+
|
12
|
+
def configure
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
|
16
|
+
def request_env=(environment)
|
17
|
+
@request_env = environment
|
18
|
+
@request_env[:breadcrumb] ||= Breadcrumb.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_env
|
22
|
+
@request_env if defined?(@request_env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def request
|
26
|
+
@request_id if defined? @request_id
|
27
|
+
end
|
28
|
+
|
29
|
+
def request=(request_id)
|
30
|
+
@request_id = request_id
|
31
|
+
end
|
32
|
+
|
33
|
+
def breadcrumb
|
34
|
+
@request_env[:breadcrumb]
|
35
|
+
end
|
36
|
+
|
37
|
+
def breadcrumb=(breadcrumb)
|
38
|
+
@request_env[:breadcrumb] = breadcrumb
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_renderer
|
42
|
+
@default_renderer ||= Ariane::Render::HTMLList.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_renderer=(renderer)
|
46
|
+
@default_renderer = renderer.is_a?(Class) ? renderer.new : renderer
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'ariane/crumb'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
class Breadcrumb
|
5
|
+
def crumbs
|
6
|
+
@crumbs ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(text='', url=nil, &block)
|
10
|
+
new_crumb = Crumb.new(text, url)
|
11
|
+
yield new_crumb if block_given?
|
12
|
+
crumbs << new_crumb
|
13
|
+
end
|
14
|
+
|
15
|
+
def render(renderer=nil)
|
16
|
+
renderer ||= Ariane.default_renderer
|
17
|
+
renderer = renderer.new if renderer.is_a?(Class)
|
18
|
+
renderer.render(crumbs)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ariane/crumb.rb
ADDED
data/lib/ariane/rails.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Ariane
|
2
|
+
module ControllerHelper
|
3
|
+
def ariane
|
4
|
+
if !Ariane.request_env || Ariane.request != request.object_id
|
5
|
+
Ariane.request = request.object_id
|
6
|
+
Ariane.request_env = request.env
|
7
|
+
Ariane.breadcrumb = Breadcrumb.new
|
8
|
+
end
|
9
|
+
|
10
|
+
Ariane.request_env[:breadcrumb]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
ActionController::Base.send :include, Ariane::ControllerHelper
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ariane
|
2
|
+
module Render
|
3
|
+
|
4
|
+
class Base
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
@options = {
|
9
|
+
divider: divider
|
10
|
+
}.merge(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(crumbs)
|
14
|
+
raise 'the render method is not implemented in your Ariane renderer'
|
15
|
+
end
|
16
|
+
|
17
|
+
def divider
|
18
|
+
' / '
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'ariane/render/base'
|
2
|
+
require 'action_view'
|
3
|
+
|
4
|
+
module Ariane
|
5
|
+
module Render
|
6
|
+
|
7
|
+
class HTML < Base
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include ActionView::Helpers::UrlHelper
|
10
|
+
include ActionView::Helpers::OutputSafetyHelper
|
11
|
+
|
12
|
+
attr_accessor :output_buffer
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
options = {
|
16
|
+
active_class: 'active',
|
17
|
+
link_active: false,
|
18
|
+
link_class: nil,
|
19
|
+
list_class: 'breadcrumb',
|
20
|
+
list_id: nil
|
21
|
+
}.merge(options)
|
22
|
+
|
23
|
+
super(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def render(crumbs)
|
27
|
+
list(crumbs).html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
def list(crumbs)
|
31
|
+
content_tag(:p, id: options[:list_id], class: options[:list_class]) do
|
32
|
+
raw items(crumbs)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def items(crumbs)
|
37
|
+
crumbs.inject('') do |out, crumb|
|
38
|
+
active = crumb == crumbs.last
|
39
|
+
out << item(crumb, active)
|
40
|
+
out
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def item(crumb, active=false)
|
45
|
+
out = link(crumb, active)
|
46
|
+
out << divider if divider && !active
|
47
|
+
out
|
48
|
+
end
|
49
|
+
|
50
|
+
def link(crumb, active=false)
|
51
|
+
classes = options[:link_class]
|
52
|
+
|
53
|
+
if active && options[:active_class]
|
54
|
+
classes ||= ''
|
55
|
+
classes << options[:active_class]
|
56
|
+
end
|
57
|
+
|
58
|
+
link_active = !active || options[:link_active]
|
59
|
+
if crumb.url && link_active
|
60
|
+
link = link_to crumb.text, crumb.url, class: classes
|
61
|
+
else
|
62
|
+
link = crumb.text
|
63
|
+
end
|
64
|
+
link
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'ariane/render/html'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
module Render
|
5
|
+
|
6
|
+
class HTMLList < HTML
|
7
|
+
def initialize(options={})
|
8
|
+
options = {
|
9
|
+
item_class: nil
|
10
|
+
}.merge(options)
|
11
|
+
|
12
|
+
super(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def list(crumbs)
|
16
|
+
content_tag(:ul, id: options[:list_id], class: options[:list_class]) do
|
17
|
+
raw items(crumbs)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def item(crumb, active=false)
|
22
|
+
classes = options[:item_class]
|
23
|
+
|
24
|
+
if active && options[:active_class]
|
25
|
+
classes ||= ''
|
26
|
+
classes << options[:active_class]
|
27
|
+
end
|
28
|
+
|
29
|
+
content_tag(:li, class: classes) do
|
30
|
+
out = link(crumb, active)
|
31
|
+
out << divider if divider && !active
|
32
|
+
out
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def link(crumb, active=false)
|
37
|
+
link_active = !active || options[:link_active]
|
38
|
+
if crumb.url && link_active
|
39
|
+
link = link_to crumb.text, crumb.url, class: options[:link_class]
|
40
|
+
else
|
41
|
+
link = crumb.text
|
42
|
+
end
|
43
|
+
link
|
44
|
+
end
|
45
|
+
|
46
|
+
def divider
|
47
|
+
content_tag(:span, '/', class: 'divider')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'ariane'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
describe Breadcrumb do
|
5
|
+
describe "#crumbs" do
|
6
|
+
it "has a crumbs method that returns an Enumerable" do
|
7
|
+
Breadcrumb.new.crumbs.is_a?(Enumerable).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "set the crumbs to an empty Enumerable by default" do
|
11
|
+
crumbs = Breadcrumb.new.crumbs
|
12
|
+
crumbs.respond_to?(:count).should be_true
|
13
|
+
crumbs.count.should be(0)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#add" do
|
18
|
+
it "creates a new crumb and push it to crumbs" do
|
19
|
+
breadcrumb = Breadcrumb.new
|
20
|
+
breadcrumb.add 'text', 'url'
|
21
|
+
breadcrumb.crumbs.count.should be(1)
|
22
|
+
breadcrumb.crumbs.last.text.should == 'text'
|
23
|
+
breadcrumb.crumbs.last.url.should == 'url'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "yields passing the new crumb if a block is given" do
|
27
|
+
breadcrumb = Breadcrumb.new
|
28
|
+
breadcrumb.add 'text' do |crumb|
|
29
|
+
crumb.url = 'url'
|
30
|
+
end
|
31
|
+
breadcrumb.crumbs.last.url.should == 'url'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#render" do
|
36
|
+
let(:test_renderer_class) { double('renderer_clas') }
|
37
|
+
let(:test_renderer) { double('renderer') }
|
38
|
+
|
39
|
+
it "uses Ariane's default renderer if none is passed as argument" do
|
40
|
+
Ariane.default_renderer = test_renderer
|
41
|
+
breadcrumb = Breadcrumb.new
|
42
|
+
breadcrumb.add 'text', 'url'
|
43
|
+
test_renderer.should_receive(:render)
|
44
|
+
breadcrumb.render
|
45
|
+
end
|
46
|
+
|
47
|
+
it "instanciates the renderer if a class is given" do
|
48
|
+
test_renderer_class.stub(:"is_a?").with(Class).and_return(true)
|
49
|
+
test_renderer_class.stub(:new).and_return(test_renderer)
|
50
|
+
|
51
|
+
test_renderer_class.should_receive(:new)
|
52
|
+
test_renderer.should_receive(:render).with([])
|
53
|
+
Breadcrumb.new.render(test_renderer_class)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "calls render on the renderer, passing it the cumbs" do
|
57
|
+
breadcrumb = Breadcrumb.new
|
58
|
+
breadcrumb.add 'text', 'url'
|
59
|
+
test_renderer.should_receive(:render).with(breadcrumb.crumbs)
|
60
|
+
breadcrumb.render(test_renderer)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'ariane/crumb'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
describe Crumb do
|
5
|
+
it "has a text attribute" do
|
6
|
+
Crumb.new.respond_to?(:text)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "sets text as an empty string by default" do
|
10
|
+
Crumb.new.text.should == ''
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a setter for the text attribute" do
|
14
|
+
crumb = Crumb.new
|
15
|
+
crumb.text = 'test'
|
16
|
+
crumb.text.should == 'test'
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
it "has an url attribute" do
|
21
|
+
Crumb.new.respond_to?(:url)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "sets url as nil by default" do
|
25
|
+
Crumb.new.url.should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a setter for the url attribute" do
|
29
|
+
crumb = Crumb.new
|
30
|
+
crumb.url = '/'
|
31
|
+
crumb.url.should == '/'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'ariane/render/base'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
module Render
|
5
|
+
|
6
|
+
describe Base do
|
7
|
+
it "has an options attribute" do
|
8
|
+
Base.new.respond_to?(:options).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a setter for the options attribute" do
|
12
|
+
base = Base.new
|
13
|
+
base.options = { test: 42 }
|
14
|
+
base.options.should == { test: 42 }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#initialize" do
|
18
|
+
it "sets the default options" do
|
19
|
+
Base.new.options.should == { divider: ' / ' }
|
20
|
+
end
|
21
|
+
|
22
|
+
it "calls divider to set the default divider" do
|
23
|
+
base = Base.new
|
24
|
+
base.options[:divider].should == base.divider
|
25
|
+
end
|
26
|
+
|
27
|
+
it "merges the options passed as argument to the default ones" do
|
28
|
+
Base.new(test: 42).options.should == { divider: ' / ', test: 42 }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "render" do
|
33
|
+
it "raises an exceptions when called" do
|
34
|
+
expect { Base.new.render }.to raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "divider" do
|
39
|
+
it "returns the default divider" do
|
40
|
+
Base.new.divider.should == ' / '
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'ariane/render/html_list'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
module Render
|
5
|
+
|
6
|
+
describe HTMLList do
|
7
|
+
describe "#initialize" do
|
8
|
+
it "sets default options" do
|
9
|
+
HTMLList.new.options.has_key?(:item_class).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "merges the options passed as argument to the default ones" do
|
13
|
+
html_list = HTMLList.new(item_class: 'test')
|
14
|
+
html_list.options[:item_class].should == 'test'
|
15
|
+
html_list.options[:list_class].should == 'breadcrumb'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "calls uses HTML default options" do
|
19
|
+
html = HTML.new
|
20
|
+
html_list = HTMLList.new
|
21
|
+
html_list.options[:list_class].should == html.options[:list_class]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#list" do
|
26
|
+
it "returns an HTML list with list_id and list_class" do
|
27
|
+
html_list = HTMLList.new(list_id: 'test')
|
28
|
+
html_list.list([]).should == '<ul class="breadcrumb" id="test"></ul>'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns an HTML list containing crumbs" do
|
32
|
+
html_list = HTMLList.new
|
33
|
+
crumbs = [Crumb.new('text', 'url')]
|
34
|
+
html_list.list(crumbs).should =~ %r[<ul class="breadcrumb">.*li.*</ul>]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#item" do
|
39
|
+
before :each do
|
40
|
+
@html_list = HTMLList.new
|
41
|
+
@crumb = Crumb.new 'text', 'url'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the crumb in a formatted form" do
|
45
|
+
@html_list.item(@crumb).should =~ %r[^<li><a href="url">text</a>]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "appends the divider to the crumb" do
|
49
|
+
@html_list.item(@crumb).should =~ %r[<span class="divider">/</span></li>$]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not append the divider if the crumb is active" do
|
53
|
+
@html_list.item(@crumb, true).should_not =~ %r[<span class="divider">/</span></li>$]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#link" do
|
58
|
+
before do
|
59
|
+
@html_list = HTMLList.new
|
60
|
+
@crumb = Crumb.new 'text', 'url'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns the link for the crumb" do
|
64
|
+
@html_list.link(@crumb).should == '<a href="url">text</a>'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "sets the link class" do
|
68
|
+
@html_list.options[:link_class] = 'test'
|
69
|
+
@html_list.link(@crumb).should == '<a href="url" class="test">text</a>'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns a link if the crumb has an url" do
|
73
|
+
@html_list.link(@crumb).should == '<a href="url">text</a>'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns a link if the crumb is active and link_active is true" do
|
77
|
+
@html_list.options[:link_active] = true
|
78
|
+
@html_list.link(@crumb, true).should =~ /<a /
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns crumb's text if the crumb has no url" do
|
82
|
+
@crumb.url = nil
|
83
|
+
@html_list.link(@crumb).should == @crumb.text
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns crumb's text if the crumb is active and link_active is false" do
|
87
|
+
@html_list.link(@crumb, true).should == @crumb.text
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#divider" do
|
92
|
+
it "returns the HTML list divider" do
|
93
|
+
HTMLList.new.divider.should == '<span class="divider">/</span>'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'ariane/render/html'
|
2
|
+
|
3
|
+
module Ariane
|
4
|
+
module Render
|
5
|
+
|
6
|
+
describe HTML do
|
7
|
+
it "has an output_buffer" do
|
8
|
+
HTML.new.respond_to?(:output_buffer)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a setter for the output_buffer" do
|
12
|
+
HTML.new.respond_to?(:"output_buffer=")
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
it "sets default options" do
|
17
|
+
HTML.new.options[:list_class].should == 'breadcrumb'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "merges the options passed as argument to the default ones" do
|
21
|
+
html = HTML.new(list_id: 'test')
|
22
|
+
html.options[:list_id].should == 'test'
|
23
|
+
html.options[:list_class].should == 'breadcrumb'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "calls uses Base default options" do
|
27
|
+
HTML.new.options[:divider].should == ' / '
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#render" do
|
32
|
+
it "returns an html_safe string" do
|
33
|
+
html = HTML.new
|
34
|
+
html.stub(:list).and_return('test')
|
35
|
+
html.render([]).html_safe?.should be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#list" do
|
40
|
+
it "returns an HTML paragraph with list_id and list_class" do
|
41
|
+
html = HTML.new(list_id: 'test')
|
42
|
+
html.list([]).should == '<p class="breadcrumb" id="test"></p>'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns an HTML paragraph containing crumbs" do
|
46
|
+
html = HTML.new
|
47
|
+
crumbs = [Crumb.new('text1', 'url1'), Crumb.new('text2', 'url2')]
|
48
|
+
html.list(crumbs).should == '<p class="breadcrumb"><a href="url1">text1</a> / text2</p>'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#items" do
|
53
|
+
it "returns all crumbs in a formatted form" do
|
54
|
+
html = HTML.new
|
55
|
+
crumbs = [Crumb.new('text1', 'url1'), Crumb.new('text2', 'url2')]
|
56
|
+
html.items(crumbs).should == '<a href="url1">text1</a> / text2'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "sets the active flag for the last item" do
|
60
|
+
html = HTML.new
|
61
|
+
crumbs = [Crumb.new('text', 'url'), Crumb.new('text', 'url')]
|
62
|
+
html.should_receive(:item).with(crumbs.first, false).and_return('')
|
63
|
+
html.should_receive(:item).with(crumbs.last, true).and_return('')
|
64
|
+
html.items(crumbs)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#item" do
|
69
|
+
before :each do
|
70
|
+
@html = HTML.new
|
71
|
+
@crumb = Crumb.new 'text', 'url'
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns the crumb in a formatted form" do
|
75
|
+
@html.item(@crumb).should =~ %r[^<a href="url">text</a>]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "appends the divider to the crumb" do
|
79
|
+
@html.item(@crumb).should =~ %r[ / $]
|
80
|
+
end
|
81
|
+
|
82
|
+
it "does not append the divider if the crumb is active" do
|
83
|
+
@html.item(@crumb, true).should_not =~ %r[ / $]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#link" do
|
88
|
+
before do
|
89
|
+
@html = HTML.new
|
90
|
+
@crumb = Crumb.new 'text', 'url'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns the link for the crumb" do
|
94
|
+
@html.link(@crumb).should == '<a href="url">text</a>'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "sets the link class" do
|
98
|
+
@html.options[:link_class] = 'test'
|
99
|
+
@html.link(@crumb).should == '<a href="url" class="test">text</a>'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "sets the active class when the crumb is active and link_active is true" do
|
103
|
+
@html.options[:link_active] = true
|
104
|
+
@html.link(@crumb, true).should == '<a href="url" class="active">text</a>'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "returns a link if the crumb has an url" do
|
108
|
+
@html.link(@crumb).should == '<a href="url">text</a>'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns a link if the crumb is active and link_active is true" do
|
112
|
+
@html.options[:link_active] = true
|
113
|
+
@html.link(@crumb, true).should =~ /<a /
|
114
|
+
end
|
115
|
+
|
116
|
+
it "returns crumb's text if the crumb has no url" do
|
117
|
+
@crumb.url = nil
|
118
|
+
@html.link(@crumb).should == @crumb.text
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns crumb's text if the crumb is active and link_active is false" do
|
122
|
+
@html.link(@crumb, true).should == @crumb.text
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
data/spec/ariane_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'ariane'
|
2
|
+
|
3
|
+
describe Ariane do
|
4
|
+
before :each do
|
5
|
+
Ariane.request_env = {}
|
6
|
+
Ariane.default_renderer = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#configure" do
|
10
|
+
it "passes Ariane to the given block" do
|
11
|
+
Ariane.configure do |config|
|
12
|
+
config.default_renderer = 'test_renderer'
|
13
|
+
end
|
14
|
+
Ariane.default_renderer.should == 'test_renderer'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#request_env=" do
|
19
|
+
it "sets the breacrumb env variable" do
|
20
|
+
Ariane.request_env = {}
|
21
|
+
Ariane.request_env[:breadcrumb].should_not be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#breadcrumb" do
|
26
|
+
it "returns the breadcrumb from the request_env" do
|
27
|
+
Ariane.request_env[:breadcrumb] = "test_breadcrumb"
|
28
|
+
Ariane.breadcrumb.should == "test_breadcrumb"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#breadcrumb=" do
|
33
|
+
it "sets the breadcrumb in the request_env" do
|
34
|
+
Ariane.breadcrumb = "test_breadcrumb"
|
35
|
+
Ariane.request_env[:breadcrumb].should == "test_breadcrumb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#default_renderer" do
|
40
|
+
it "returns the default renderer" do
|
41
|
+
Ariane.default_renderer = "test_renderer"
|
42
|
+
Ariane.default_renderer.should == "test_renderer"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#default_renderer=" do
|
47
|
+
it "instanciates the renderer if a class is passed" do
|
48
|
+
Ariane.default_renderer = String
|
49
|
+
Ariane.default_renderer.should == ""
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ariane
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon COURTOIS
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
requirement: &70152268031300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70152268031300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70152268059680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.3.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70152268059680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70152268059280 !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: *70152268059280
|
47
|
+
description: Ariane is a flexible breadcrumb system for Rails. It is fully compatible
|
48
|
+
with the Twitter Bootstrap and can be adapted to any kind of output.
|
49
|
+
email:
|
50
|
+
- scourtois@cubyx.fr
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- COPYING
|
57
|
+
- Gemfile
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- ariane.gemspec
|
61
|
+
- lib/ariane.rb
|
62
|
+
- lib/ariane/breadcrumb.rb
|
63
|
+
- lib/ariane/crumb.rb
|
64
|
+
- lib/ariane/rails.rb
|
65
|
+
- lib/ariane/rails/controller_helper.rb
|
66
|
+
- lib/ariane/rails/view_helper.rb
|
67
|
+
- lib/ariane/render.rb
|
68
|
+
- lib/ariane/render/base.rb
|
69
|
+
- lib/ariane/render/html.rb
|
70
|
+
- lib/ariane/render/html_list.rb
|
71
|
+
- lib/ariane/version.rb
|
72
|
+
- spec/ariane/breadcrumb_spec.rb
|
73
|
+
- spec/ariane/crumb_spec.rb
|
74
|
+
- spec/ariane/render/base_spec.rb
|
75
|
+
- spec/ariane/render/html_list_spec.rb
|
76
|
+
- spec/ariane/render/html_spec.rb
|
77
|
+
- spec/ariane_spec.rb
|
78
|
+
homepage: http://github.com/simonc/ariane
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.10
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: A flexible breadcrumb system for Rails, fully compatible with the Twitter
|
102
|
+
Bootstrap.
|
103
|
+
test_files:
|
104
|
+
- spec/ariane/breadcrumb_spec.rb
|
105
|
+
- spec/ariane/crumb_spec.rb
|
106
|
+
- spec/ariane/render/base_spec.rb
|
107
|
+
- spec/ariane/render/html_list_spec.rb
|
108
|
+
- spec/ariane/render/html_spec.rb
|
109
|
+
- spec/ariane_spec.rb
|