has_breadcrumb 0.1.0
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/MIT-LICENSE +20 -0
- data/README.textile +68 -0
- data/VERSION +1 -0
- data/examples/images/crumbs.gif +0 -0
- data/examples/index.html +19 -0
- data/examples/styles.css +33 -0
- data/init.rb +4 -0
- data/lib/breadcrumb.rb +37 -0
- data/lib/has_breadcrumbs.rb +13 -0
- data/spec/has_breadcrumbs_spec.rb +64 -0
- data/spec/spec_helper.rb +8 -0
- metadata +68 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Nando Vieira
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
h1. has_breadcrumbs
|
2
|
+
|
3
|
+
has_breadcrumbs is a simple plugin that adds a breadcrumb object into controllers and views.
|
4
|
+
|
5
|
+
h2. Instalation
|
6
|
+
|
7
|
+
1) Install the plugin with `script/plugin install git://github.com/danielvlopes/has_breadcrumbs.git`
|
8
|
+
|
9
|
+
h2. Usage
|
10
|
+
|
11
|
+
On your controller:
|
12
|
+
|
13
|
+
<pre>
|
14
|
+
class ApplicationController < ActionController::Base
|
15
|
+
before_filter :add_initial_breadcrumbs
|
16
|
+
|
17
|
+
private
|
18
|
+
def add_initial_breadcrumbs
|
19
|
+
breadcrumb.add 'Home', root_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ThingsController < ApplicationController
|
24
|
+
def index
|
25
|
+
breadcrumb.add 'Things', things_path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
</pre>
|
29
|
+
|
30
|
+
You don't need to provide an URL; in that case, a span will be generated
|
31
|
+
instead of a link:
|
32
|
+
|
33
|
+
<pre>
|
34
|
+
breadcrumb.add 'Some page'
|
35
|
+
</pre>
|
36
|
+
|
37
|
+
You can set additional HTML attributes if you need to:
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
breadcrumb.add 'Home', root_path, :id => 'home', :title => 'Go to the home page'
|
41
|
+
</pre>
|
42
|
+
|
43
|
+
On your view (possibly application.html.erb):
|
44
|
+
|
45
|
+
<pre>You are here: <%= breadcrumb.display %></pre>
|
46
|
+
|
47
|
+
You can set your own separator:
|
48
|
+
|
49
|
+
<pre>
|
50
|
+
You are here: <%= breadcrumb.display %>
|
51
|
+
</pre>
|
52
|
+
|
53
|
+
The output in your html will be something like below:
|
54
|
+
|
55
|
+
<pre>
|
56
|
+
<ul id="breadcrumbs">
|
57
|
+
<li class="item-0"><a href="#">Home</a></li>
|
58
|
+
<li class="item-1"><a href="#">Main section</a></li>
|
59
|
+
<li class="item-2"><a href="#">Sub section</a></li>
|
60
|
+
<li class="item-3 last">The page you are on right now</li>
|
61
|
+
</ul>
|
62
|
+
</pre>
|
63
|
+
|
64
|
+
For a good css example take a look in examples folder.
|
65
|
+
|
66
|
+
This work is based on "http://github.com/fnando/has_breadcrumbs/tree/master":http://github.com/fnando/has_breadcrumbs/tree/master by Nando Vieira.
|
67
|
+
|
68
|
+
This adaptation is maded by Daniel Lopes, and still under the MIT license.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
Binary file
|
data/examples/index.html
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
6
|
+
<title>CSS breadcrumbs</title>
|
7
|
+
<link rel="stylesheet" href="styles.css" type="text/css" media="all" />
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<ul id="breadcrumbs">
|
11
|
+
<li class="item-0"><a href="#">Home</a></li>
|
12
|
+
<li><a href="#">Main section</a></li>
|
13
|
+
<li><a href="#">Sub section</a></li>
|
14
|
+
<li>The page you are on right now</li>
|
15
|
+
</ul>
|
16
|
+
|
17
|
+
<p>Example from <a href="http://veerle.duoh.com/blog/comments/simple_scalable_css_based_breadcrumbs/">veerle.duoh.com</a></p>
|
18
|
+
</body>
|
19
|
+
</html>
|
data/examples/styles.css
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
body {
|
2
|
+
font:71%/165% "Lucida Grande", Lucida, Verdana, sans-serif;
|
3
|
+
}
|
4
|
+
ul, li {
|
5
|
+
list-style-type:none;
|
6
|
+
padding:0;
|
7
|
+
margin:0;
|
8
|
+
}
|
9
|
+
#breadcrumbs {
|
10
|
+
height:2.3em;
|
11
|
+
border:1px solid #dedede;
|
12
|
+
}
|
13
|
+
#breadcrumbs li {
|
14
|
+
float:left;
|
15
|
+
line-height:2.3em;
|
16
|
+
color:#777;
|
17
|
+
padding-left:.75em;
|
18
|
+
}
|
19
|
+
#breadcrumbs li a {
|
20
|
+
background:url(images/crumbs.gif) no-repeat right center;
|
21
|
+
display:block;
|
22
|
+
padding:0 15px 0 0;
|
23
|
+
}
|
24
|
+
#breadcrumbs li a:link,
|
25
|
+
#breadcrumbs li a:visited {
|
26
|
+
color:#777;
|
27
|
+
text-decoration:none;
|
28
|
+
}
|
29
|
+
a:link, a:visited,
|
30
|
+
#breadcrumbs li a:hover,
|
31
|
+
#breadcrumbs li a:focus {
|
32
|
+
color:#dd2c0d;
|
33
|
+
}
|
data/init.rb
ADDED
data/lib/breadcrumb.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
class Breadcrumb
|
2
|
+
include ActionView::Helpers::TagHelper
|
3
|
+
|
4
|
+
attr_accessor :items
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@items = []
|
8
|
+
end
|
9
|
+
|
10
|
+
alias :<<, :add
|
11
|
+
|
12
|
+
def add(name, url=nil, options={})
|
13
|
+
@items << [name, url, options]
|
14
|
+
end
|
15
|
+
|
16
|
+
def display
|
17
|
+
size = @items.size
|
18
|
+
|
19
|
+
crumbs = @items.to_enum(:each_with_index).collect do |item, index|
|
20
|
+
name, url, options = item
|
21
|
+
|
22
|
+
options[:class] ||= ""
|
23
|
+
options[:class] << " item-#{index}"
|
24
|
+
options[:class] << " last" if size - 1 == index
|
25
|
+
options[:class].squish!
|
26
|
+
|
27
|
+
if url.nil? || (size - 1 == index)
|
28
|
+
content_tag(:li, name, options)
|
29
|
+
else
|
30
|
+
content_tag(:li, content_tag(:a, name, :href => url), options)
|
31
|
+
end
|
32
|
+
end.join("\n")
|
33
|
+
|
34
|
+
content_tag(:ul, "\n#{crumbs}\n", :id=>"breadcrumbs")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class SampleController < ActionController::Base
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "has_breadcrumbs" do
|
7
|
+
before(:each) do
|
8
|
+
@app = SampleController.new
|
9
|
+
@breadcrumb = Breadcrumb.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "controller should respond to breadcrumb method" do
|
13
|
+
@app.should respond_to(:breadcrumb)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should instantiate breadcrumb" do
|
17
|
+
@app.breadcrumb.add 'something'
|
18
|
+
@app.instance_variables.should include('@breadcrumb')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should instantiate breadcrumb only once" do
|
22
|
+
Breadcrumb.should_receive(:new).once.and_return(mock('breadcrumb', :null_object => true))
|
23
|
+
@app.breadcrumb.add 'things'
|
24
|
+
@app.breadcrumb.add 'something'
|
25
|
+
end
|
26
|
+
|
27
|
+
# it "should return span when no link is provided" do
|
28
|
+
# @breadcrumb.add 'Things'
|
29
|
+
# @breadcrumb.display.should have_tag('span.breadcrumb.item-0.last', 'Things')
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# it "should return A tag when link is provided" do
|
33
|
+
# @breadcrumb.add 'Things', '/things'
|
34
|
+
# @breadcrumb.display.should have_tag('a.breadcrumb.item-0.last[href=/things]', 'Things')
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# it "should use default separator" do
|
38
|
+
# @breadcrumb.add 'Things'
|
39
|
+
# @breadcrumb.add 'Something'
|
40
|
+
# @breadcrumb.display.should have_tag('span.separator', '»')
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# it "should use custom separator" do
|
44
|
+
# @breadcrumb.add 'Things'
|
45
|
+
# @breadcrumb.add 'Something'
|
46
|
+
# @breadcrumb.display('|').should have_tag('span.separator', '|')
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# it "should use options" do
|
50
|
+
# @breadcrumb.add 'Things', '/things', :rel => 'external', :id => 'things', :class => 'link'
|
51
|
+
# @breadcrumb.display.should have_tag('a#things.breadcrumb.item-0.last.link[href=/things][rel=external]')
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
it "should add new items" do
|
55
|
+
@breadcrumb.add 'Things', '/things', :id => 'things'
|
56
|
+
@breadcrumb.add 'Something', '/things/something', :id => 'something'
|
57
|
+
@breadcrumb.items.last.should == ['Something', '/things/something', {:id => 'something'}]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should add helper method" do
|
61
|
+
SampleController.should_receive(:helper_method).with(:breadcrumb)
|
62
|
+
SampleController.send(:include, SimplesIdeias::Breadcrumbs::ActionController)
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: has_breadcrumb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel Sobrinho
|
8
|
+
- Daniel Lopes
|
9
|
+
- Nando Vieira
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2010-01-17 00:00:00 -02:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description:
|
19
|
+
email: gabriel.sobrinho@gmail.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files:
|
25
|
+
- README.textile
|
26
|
+
files:
|
27
|
+
- MIT-LICENSE
|
28
|
+
- README.textile
|
29
|
+
- VERSION
|
30
|
+
- examples/images/crumbs.gif
|
31
|
+
- examples/index.html
|
32
|
+
- examples/styles.css
|
33
|
+
- init.rb
|
34
|
+
- lib/breadcrumb.rb
|
35
|
+
- lib/has_breadcrumbs.rb
|
36
|
+
- spec/has_breadcrumbs_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/sobrinho/has_breadcrumb
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --charset=UTF-8
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: has_breadcrumbs is a simple plugin that adds a `breadcrumb` object into controllers and views.
|
66
|
+
test_files:
|
67
|
+
- spec/has_breadcrumbs_spec.rb
|
68
|
+
- spec/spec_helper.rb
|