has_breadcrumbs 0.1.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/MIT-LICENSE +20 -0
- data/README.textile +72 -0
- data/Rakefile +14 -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/has_breadcrumb.gemspec +50 -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 +70 -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,72 @@
|
|
|
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
|
+
You can install using as gem:
|
|
8
|
+
|
|
9
|
+
<pre>
|
|
10
|
+
Rails::Initializer.run do |config|
|
|
11
|
+
config.gem 'has_breadcrumbs'
|
|
12
|
+
end
|
|
13
|
+
</pre>
|
|
14
|
+
|
|
15
|
+
or install as plugin with `script/plugin install git://github.com/sobrinho/has_breadcrumbs.git`
|
|
16
|
+
|
|
17
|
+
h2. Usage
|
|
18
|
+
|
|
19
|
+
On your controller:
|
|
20
|
+
|
|
21
|
+
<pre>
|
|
22
|
+
class ApplicationController < ActionController::Base
|
|
23
|
+
before_filter :add_initial_breadcrumb
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
def add_initial_breadcrumb
|
|
28
|
+
breadcrumb.add 'Home', root_path
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class PostsController < ApplicationController
|
|
33
|
+
def index
|
|
34
|
+
# you can also use << instead of add
|
|
35
|
+
breadcrumb.add 'Posts', posts_path
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
</pre>
|
|
39
|
+
|
|
40
|
+
You don't need to provide an URL; in that case, a span will be generated
|
|
41
|
+
instead of a link:
|
|
42
|
+
|
|
43
|
+
<pre>
|
|
44
|
+
breadcrumb.add 'Some page'
|
|
45
|
+
</pre>
|
|
46
|
+
|
|
47
|
+
You can set additional HTML attributes if you need to:
|
|
48
|
+
|
|
49
|
+
<pre>
|
|
50
|
+
breadcrumb.add 'Home', root_path, :id => 'home', :title => 'Go to the home page'
|
|
51
|
+
</pre>
|
|
52
|
+
|
|
53
|
+
On your view:
|
|
54
|
+
|
|
55
|
+
<pre>You are here: <%= breadcrumb.display %></pre>
|
|
56
|
+
|
|
57
|
+
The output in your html will be something like below:
|
|
58
|
+
|
|
59
|
+
<pre>
|
|
60
|
+
<ul id="breadcrumbs">
|
|
61
|
+
<li class="item-0"><a href="#">Home</a></li>
|
|
62
|
+
<li class="item-1"><a href="#">Main section</a></li>
|
|
63
|
+
<li class="item-2"><a href="#">Sub section</a></li>
|
|
64
|
+
<li class="item-3 last">The page you are on right now</li>
|
|
65
|
+
</ul>
|
|
66
|
+
</pre>
|
|
67
|
+
|
|
68
|
+
For a good css example take a look in examples folder.
|
|
69
|
+
|
|
70
|
+
This work is based on "http://github.com/fnando/has_breadcrumbs":http://github.com/fnando/has_breadcrumbs by Nando Vieira.
|
|
71
|
+
|
|
72
|
+
Adaptation made by Daniel Lopes and gemified by Gabriel Sobrinho, under the MIT license.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'jeweler'
|
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
|
4
|
+
gemspec.name = "has_breadcrumbs"
|
|
5
|
+
gemspec.summary = "has_breadcrumbs is a simple plugin that adds a `breadcrumb` object into controllers and views."
|
|
6
|
+
gemspec.email = "gabriel.sobrinho@gmail.com"
|
|
7
|
+
gemspec.homepage = "http://github.com/sobrinho/has_breadcrumbs"
|
|
8
|
+
gemspec.authors = ["Gabriel Sobrinho", "Daniel Lopes", "Nando Vieira"]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
Jeweler::GemcutterTasks.new
|
|
12
|
+
rescue LoadError
|
|
13
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
|
14
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.1
|
|
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
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{has_breadcrumb}
|
|
8
|
+
s.version = "0.1.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Gabriel Sobrinho", "Daniel Lopes", "Nando Vieira"]
|
|
12
|
+
s.date = %q{2010-01-17}
|
|
13
|
+
s.email = %q{gabriel.sobrinho@gmail.com}
|
|
14
|
+
s.extra_rdoc_files = [
|
|
15
|
+
"README.textile"
|
|
16
|
+
]
|
|
17
|
+
s.files = [
|
|
18
|
+
"MIT-LICENSE",
|
|
19
|
+
"README.textile",
|
|
20
|
+
"VERSION",
|
|
21
|
+
"examples/images/crumbs.gif",
|
|
22
|
+
"examples/index.html",
|
|
23
|
+
"examples/styles.css",
|
|
24
|
+
"init.rb",
|
|
25
|
+
"lib/breadcrumb.rb",
|
|
26
|
+
"lib/has_breadcrumbs.rb",
|
|
27
|
+
"spec/has_breadcrumbs_spec.rb",
|
|
28
|
+
"spec/spec_helper.rb"
|
|
29
|
+
]
|
|
30
|
+
s.homepage = %q{http://github.com/sobrinho/has_breadcrumb}
|
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
32
|
+
s.require_paths = ["lib"]
|
|
33
|
+
s.rubygems_version = %q{1.3.5}
|
|
34
|
+
s.summary = %q{has_breadcrumbs is a simple plugin that adds a `breadcrumb` object into controllers and views.}
|
|
35
|
+
s.test_files = [
|
|
36
|
+
"spec/has_breadcrumbs_spec.rb",
|
|
37
|
+
"spec/spec_helper.rb"
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
if s.respond_to? :specification_version then
|
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
42
|
+
s.specification_version = 3
|
|
43
|
+
|
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
45
|
+
else
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
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,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: has_breadcrumbs
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
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
|
+
- Rakefile
|
|
30
|
+
- VERSION
|
|
31
|
+
- examples/images/crumbs.gif
|
|
32
|
+
- examples/index.html
|
|
33
|
+
- examples/styles.css
|
|
34
|
+
- has_breadcrumb.gemspec
|
|
35
|
+
- init.rb
|
|
36
|
+
- lib/breadcrumb.rb
|
|
37
|
+
- lib/has_breadcrumbs.rb
|
|
38
|
+
- spec/has_breadcrumbs_spec.rb
|
|
39
|
+
- spec/spec_helper.rb
|
|
40
|
+
has_rdoc: true
|
|
41
|
+
homepage: http://github.com/sobrinho/has_breadcrumbs
|
|
42
|
+
licenses: []
|
|
43
|
+
|
|
44
|
+
post_install_message:
|
|
45
|
+
rdoc_options:
|
|
46
|
+
- --charset=UTF-8
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: "0"
|
|
54
|
+
version:
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: "0"
|
|
60
|
+
version:
|
|
61
|
+
requirements: []
|
|
62
|
+
|
|
63
|
+
rubyforge_project:
|
|
64
|
+
rubygems_version: 1.3.5
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 3
|
|
67
|
+
summary: has_breadcrumbs is a simple plugin that adds a `breadcrumb` object into controllers and views.
|
|
68
|
+
test_files:
|
|
69
|
+
- spec/has_breadcrumbs_spec.rb
|
|
70
|
+
- spec/spec_helper.rb
|