bready 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/bready.gemspec +24 -0
- data/lib/bready.rb +65 -0
- data/lib/bready/version.rb +3 -0
- metadata +100 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
Bready is a tool for building breadcrumbs
|
2
|
+
|
3
|
+
Install
|
4
|
+
-----------
|
5
|
+
In console:
|
6
|
+
```
|
7
|
+
gem install bready
|
8
|
+
```
|
9
|
+
or in your Gemfile:
|
10
|
+
```
|
11
|
+
gem 'bready'
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
Configure
|
16
|
+
-----------
|
17
|
+
It can work with or without Rails. Here is an example of usage when you want to use it with the Ruby on Rails framework.
|
18
|
+
First you need to create a configuration file config/initializers/bready.rb
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Bready::Breadcrumbs.setup do |config|
|
22
|
+
# delimiter between parts of breadcrumbs
|
23
|
+
config.delimiter = ' | '
|
24
|
+
|
25
|
+
# Root chunk that will be used as a first chunk always
|
26
|
+
config.root_chunk = ['Home', '/']
|
27
|
+
|
28
|
+
# the name of the tag that wraps breadcrumbs
|
29
|
+
config.block_tag = 'div'
|
30
|
+
|
31
|
+
# set the class for tag that was described above
|
32
|
+
config.block_class = 'breadcrumbs'
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
Usage
|
38
|
+
-----------
|
39
|
+
You can pass an array of breadcrumb chunks into initializer method like this:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
bready = Bready::Breadcrumbs.new([
|
43
|
+
['Categories', '/Categories/'],
|
44
|
+
['Products', '/Products/'],
|
45
|
+
])
|
46
|
+
```
|
47
|
+
|
48
|
+
You can add more chunks later on. Here are examples of how to do it:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
bready.add_chunk(['Products', '/Products/'])
|
52
|
+
```
|
53
|
+
|
54
|
+
To add more than one chunk:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
bready.add_chunks([['Products', '/Products/'], ['Products2', '/Products2/']])
|
58
|
+
```
|
59
|
+
|
60
|
+
|
61
|
+
In the view you can render breadcrumbs by simply calling render method of an instance:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
bready.render
|
65
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bready.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bready/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "bready"
|
8
|
+
gem.version = Bready::VERSION
|
9
|
+
gem.authors = ["HeeL"]
|
10
|
+
gem.email = ["parizhskiy@gmail.com"]
|
11
|
+
gem.description = %q{Bready is a tool for building breadcrumbs}
|
12
|
+
gem.summary = %q{Build customized breadcrumbs, using Google Rich Snippets}
|
13
|
+
gem.homepage = "https://github.com/heel/bready"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^test/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('test-unit', '2.4.3')
|
21
|
+
gem.add_development_dependency('shoulda', '2.11.3')
|
22
|
+
gem.add_development_dependency('shoulda-matchers', '1.2.0')
|
23
|
+
|
24
|
+
end
|
data/lib/bready.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require_relative "bready/version"
|
4
|
+
|
5
|
+
module Bready
|
6
|
+
class Breadcrumbs
|
7
|
+
@@delimiter = ' > '
|
8
|
+
@@block_class = 'breadcrumbs'
|
9
|
+
@@block_tag = 'div'
|
10
|
+
@@root_chunk = []
|
11
|
+
|
12
|
+
def initialize(chunks)
|
13
|
+
@chunks = chunks
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.setup
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.delimiter= value
|
21
|
+
@@delimiter = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.block_class= value
|
25
|
+
@@block_class = value
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.block_tag= value
|
29
|
+
@@block_tag = value
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.root_chunk= value
|
33
|
+
@@root_chunk = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_chunks(chunks)
|
37
|
+
chunks.each{|chunk| add_chunk(chunk)}
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_chunk(chunk)
|
41
|
+
@chunks << chunk
|
42
|
+
end
|
43
|
+
|
44
|
+
def render
|
45
|
+
"<#{@@block_tag} class='#{@@block_class}' xmlns:v='http://rdf.data-vocabulary.org/#'>#{render_chunks}</#{@@block_tag}>"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def render_chunks
|
51
|
+
rendered = ''
|
52
|
+
@chunks.unshift(@@root_chunk).map do |label, url|
|
53
|
+
rendered << @@delimiter unless rendered.empty?
|
54
|
+
if url
|
55
|
+
rendered << "<span typeof='v:Breadcrumb'><a href='#{url}' rel='v:url' property='v:title'>#{label}</a></span>"
|
56
|
+
else
|
57
|
+
rendered << "<span>#{label}</span>"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
rendered
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bready
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- HeeL
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: test-unit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.4.3
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.4.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: shoulda
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.11.3
|
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: 2.11.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: shoulda-matchers
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.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: 1.2.0
|
62
|
+
description: Bready is a tool for building breadcrumbs
|
63
|
+
email:
|
64
|
+
- parizhskiy@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bready.gemspec
|
74
|
+
- lib/bready.rb
|
75
|
+
- lib/bready/version.rb
|
76
|
+
homepage: https://github.com/heel/bready
|
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.23
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Build customized breadcrumbs, using Google Rich Snippets
|
100
|
+
test_files: []
|