breadcrumb 0.0.2
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.rdoc +55 -0
- data/Rakefile +27 -0
- data/lib/breadcrumb/helper.rb +94 -0
- data/lib/breadcrumb/version.rb +3 -0
- data/lib/breadcrumb.rb +9 -0
- data/lib/tasks/breadcrumb_tasks.rake +4 -0
- metadata +100 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Marcelo Guilherme Jacobus Jr <marcelo.jacobus@gmail.com>
|
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.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= Breadcrumb
|
2
|
+
|
3
|
+
= Instalation
|
4
|
+
Put the following line in your Gemfile
|
5
|
+
gem "breadcrumb", :git => "git@github.com:mjacobus/Breadcrumb.git"
|
6
|
+
|
7
|
+
= Usage
|
8
|
+
|
9
|
+
Layout:
|
10
|
+
<%= raw breadcrumb %>
|
11
|
+
|
12
|
+
You can add a root path by doing this
|
13
|
+
|
14
|
+
<%= raw breadcrumb.prepend("Home","/") %>
|
15
|
+
|
16
|
+
In your view (say the uri path is /books/religion/the-holly-bible):
|
17
|
+
<%
|
18
|
+
breadcrumb.add("Books","/books")
|
19
|
+
breadcrumb.add("Religion", books_category_path(@book.category))
|
20
|
+
breadcrumb.add(@book.title)
|
21
|
+
%>
|
22
|
+
|
23
|
+
It will render
|
24
|
+
<div class="breadcrumb">
|
25
|
+
<a href="/books">Books</a>
|
26
|
+
<span class="separator"> » </span>
|
27
|
+
<a href="/books/religion">Religion</a>
|
28
|
+
<span class="separator"> » </span>
|
29
|
+
<span>The Holly Bible</span>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
You can change the separator
|
33
|
+
breadcrumb.separator = '<span class="separator"> > </span>'
|
34
|
+
|
35
|
+
Titleizing
|
36
|
+
You can use breadcrumb for creating the page title:
|
37
|
+
<title><%= breadcrumb.titleize %></title>
|
38
|
+
|
39
|
+
which will ouput
|
40
|
+
<title>Books :: Religion :: The Holly Bible</title>
|
41
|
+
|
42
|
+
Titleize accepts block. When using blocks, returning false removes the title part. Returing nil, won't change the behavior. Returning String changes the title part.
|
43
|
+
<title><%= breadcrumb.titleize {|part| "Our Awesome Books" if parts == 'Books' } %></title>
|
44
|
+
Ouputs
|
45
|
+
<title>Our Awesome Books :: Religion :: The Holly Bible</title>
|
46
|
+
|
47
|
+
Removing the title part
|
48
|
+
<title><%= breadcrumb.titleize {|part| false if part == "Religion" } %></title>
|
49
|
+
or
|
50
|
+
<title><%= breadcrumb.titleize {|part, order| false if order == 1 } %></title>
|
51
|
+
Outputs
|
52
|
+
<title>Books :: The Holly Bible</title>
|
53
|
+
|
54
|
+
And you can change the title separator:
|
55
|
+
breadcrumb.title_separator = '-'
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Breadcrumb'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Breadcrumb
|
3
|
+
class Helper
|
4
|
+
|
5
|
+
# get parts
|
6
|
+
def parts
|
7
|
+
@parts ||= []
|
8
|
+
end
|
9
|
+
|
10
|
+
# add breadcrumb
|
11
|
+
def add(label, url = nil)
|
12
|
+
parts << [label, url]
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
# prepend elements to the breadcrumb
|
17
|
+
def prepend(label, url = nil)
|
18
|
+
parts.prepend([label, url])
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
# set title separator
|
23
|
+
def separator=(separator)
|
24
|
+
@separator = separator
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def separator
|
29
|
+
@separator ||= '<span class="separator"> » </span>'
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
html = []
|
34
|
+
parts.each do |part|
|
35
|
+
if part == parts.last
|
36
|
+
html << "<span>#{part[0]}</span>"
|
37
|
+
else
|
38
|
+
html << "<a href=\"#{part[1]}\">#{part[0]}</a>"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
html.length > 1 ? "<div class=\"breadcrumb\">#{html.join(separator)}</div>" : ""
|
43
|
+
end
|
44
|
+
|
45
|
+
# Given
|
46
|
+
# add 'Home','/'
|
47
|
+
# add 'News','/news'
|
48
|
+
# add 'The Last News','news/the-last-news'
|
49
|
+
#
|
50
|
+
# titleize 'Home :: News :: The Last News'
|
51
|
+
#
|
52
|
+
# with block given
|
53
|
+
# when block returns not nil, not false, uses return as title part
|
54
|
+
#
|
55
|
+
# titleize {|part| Example.com if part == 'Home'} 'Example.com :: News :: The Last News'
|
56
|
+
#
|
57
|
+
# when returns nil, uses default title part
|
58
|
+
# when returns false, skips part
|
59
|
+
# titleize {|part, order| false if order == 0 } 'News :: The Last News'
|
60
|
+
def titleize(&block)
|
61
|
+
title_parts = []
|
62
|
+
order = 0
|
63
|
+
parts.each do |part|
|
64
|
+
|
65
|
+
if block_given?
|
66
|
+
response = yield(part.first,order)
|
67
|
+
if response != false
|
68
|
+
if response == nil
|
69
|
+
title_parts << part.first
|
70
|
+
else
|
71
|
+
title_parts << response
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
title_parts << part.first
|
76
|
+
end
|
77
|
+
order += 1
|
78
|
+
end
|
79
|
+
title_parts.join(title_separator)
|
80
|
+
end
|
81
|
+
|
82
|
+
# set title separator
|
83
|
+
def title_separator=(separator)
|
84
|
+
@title_separator = separator
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def title_separator
|
89
|
+
@title_separator ||= ' :: '
|
90
|
+
end
|
91
|
+
|
92
|
+
end # end of class
|
93
|
+
end
|
94
|
+
|
data/lib/breadcrumb.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: breadcrumb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Marcelo Jacobus
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: guard-rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Breadcrumb Helper
|
63
|
+
email:
|
64
|
+
- marcelo.jacobus@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/tasks/breadcrumb_tasks.rake
|
70
|
+
- lib/breadcrumb.rb
|
71
|
+
- lib/breadcrumb/version.rb
|
72
|
+
- lib/breadcrumb/helper.rb
|
73
|
+
- MIT-LICENSE
|
74
|
+
- Rakefile
|
75
|
+
- README.rdoc
|
76
|
+
homepage: http://github.com/mjacobus/breadcrumb
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.24
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Breadcrumb Helper
|
100
|
+
test_files: []
|