breadnbutter 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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +1 -0
- data/app/views/breadnbutter/_crumb.html.erb +8 -0
- data/breadnbutter.gemspec +23 -0
- data/lib/breadnbutter.rb +112 -0
- data/lib/breadnbutter/engine.rb +10 -0
- data/lib/breadnbutter/helpers.rb +15 -0
- data/lib/breadnbutter/railtie.rb +8 -0
- data/lib/breadnbutter/version.rb +3 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 26e1b2c693ceb291448b5e92e23494ccb033972b
|
4
|
+
data.tar.gz: bd4e47e2270eeb929ce481ce49ddfd36159bf4d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63b9ead3df6b7394011f0e93ccf6cc91a28e7b25022a125238859701149b1ce383a52687c277034d5852660814f72a480f4a6ec056bfc07adae9ca5c9e2d774e
|
7
|
+
data.tar.gz: 49926b2b506b1496a99fecda4294802f67f9596919a230004679e860e0a2e40c34dd28a9f601fbbd5a064ac5336701b5eece02c718a56be9c104ef5bdd29d764
|
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jack Desert
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# BreadnButter
|
2
|
+
|
3
|
+
Creates a linkable breadcrumb trail based on your url:
|
4
|
+
|
5
|
+
[Home](http://github.com/jackdesert/breadnbutter) » [Projects](http://github.com/jackdesert/breadnbutter/projects) » [Mow the Yard](http://github.com/jackdesert/breadnbutter/projects/mow-the-yard) » Edit
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'breadnbutter'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install breadnbutter
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
Requires Rails 3.1 or greater, since it uses Engine and Railtie
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
On any view that you want breadcrumbs, call
|
28
|
+
|
29
|
+
<%= render_breadcrumbs %>
|
30
|
+
|
31
|
+
Typically it makes sense to put this in app/views/layouts/application.html.erb
|
32
|
+
|
33
|
+
## Customization
|
34
|
+
|
35
|
+
The following can be set to further customize BreadnButter
|
36
|
+
|
37
|
+
# config/application.rb
|
38
|
+
|
39
|
+
# Use a different character between crumbs
|
40
|
+
config.breadnbutter_joiner = ':'
|
41
|
+
|
42
|
+
# Specify any text elements you want hidden
|
43
|
+
config.breadnbutter_hidden_elements = ['Hide Me']
|
44
|
+
|
45
|
+
# Change the text for the 'Home' link
|
46
|
+
config.breadnbutter_home_text = 'Noteworthy Name'
|
47
|
+
|
48
|
+
# Change the url for the 'Home' link
|
49
|
+
config.breadnbutter_home_url = 'http://classy_url.com/'
|
50
|
+
|
51
|
+
## Styling
|
52
|
+
|
53
|
+
For the aesthete in you, add some styling and tweak to taste.
|
54
|
+
|
55
|
+
#breadnbutter{
|
56
|
+
padding: 1ex 1ex;
|
57
|
+
font-size: 20px;
|
58
|
+
background-color: black;
|
59
|
+
joiner{
|
60
|
+
padding: 0 0.5ex;
|
61
|
+
color: grey;
|
62
|
+
}
|
63
|
+
crumb a{
|
64
|
+
color: gold;
|
65
|
+
}
|
66
|
+
crumb{
|
67
|
+
color: grey;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'breadnbutter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "breadnbutter"
|
8
|
+
spec.version = BreadnButter::VERSION
|
9
|
+
spec.authors = ["Jack Desert"]
|
10
|
+
spec.email = ["jackdesert@gmail.com"]
|
11
|
+
spec.description = %q{Craft generic breadcrumbs from the controller path}
|
12
|
+
spec.summary = %q{Most of the times when I use a breadcrumb, the requirements are really simple: show me what object I'm looking, and what its parent is, and give me links back to either the parent, the view, or the root.}
|
13
|
+
spec.homepage = "http://github.com/jackdesert/breadnbutter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/breadnbutter.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require "breadnbutter/version"
|
2
|
+
|
3
|
+
if Rails.version < '3.1'
|
4
|
+
raise "Rails 3.1 or greater is required to run BreadnButter"
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'breadnbutter/railtie'
|
8
|
+
require 'breadnbutter/engine'
|
9
|
+
|
10
|
+
module BreadnButter
|
11
|
+
class Crumb
|
12
|
+
JOINER = "»".html_safe
|
13
|
+
HIDDEN_ELEMENTS = []
|
14
|
+
HOME_URL = '/'
|
15
|
+
HOME_TEXT = 'HOME'
|
16
|
+
|
17
|
+
attr_accessor :url, :text
|
18
|
+
|
19
|
+
def linkable
|
20
|
+
url.present?
|
21
|
+
end
|
22
|
+
|
23
|
+
def hidden?
|
24
|
+
hidden_elements.include? text
|
25
|
+
end
|
26
|
+
|
27
|
+
def joiner
|
28
|
+
begin
|
29
|
+
Rails.configuration.breadnbutter_joiner
|
30
|
+
rescue NoMethodError
|
31
|
+
JOINER
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def hidden_elements
|
36
|
+
begin
|
37
|
+
Rails.configuration.breadnbutter_hidden_elements
|
38
|
+
rescue NoMethodError
|
39
|
+
HIDDEN_ELEMENTS
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.home_text
|
44
|
+
begin
|
45
|
+
Rails.configuration.breadnbutter_home_text
|
46
|
+
rescue NoMethodError
|
47
|
+
HOME_TEXT
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.home_url
|
52
|
+
begin
|
53
|
+
Rails.configuration.breadnbutter_home_url
|
54
|
+
rescue NoMethodError
|
55
|
+
HOME_URL
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.new_from_hash(hash)
|
60
|
+
new_crumb = self.new
|
61
|
+
new_crumb.text = value_from_key(:text, hash)
|
62
|
+
new_crumb.url = value_from_key(:url, hash)
|
63
|
+
new_crumb
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.get_text_from_element(element, previous_element)
|
67
|
+
if element =~ /^[0-9]+$/
|
68
|
+
model = previous_element.classify.constantize
|
69
|
+
begin
|
70
|
+
text = model.find(element).name
|
71
|
+
rescue NoMethodError
|
72
|
+
text = element
|
73
|
+
end
|
74
|
+
else
|
75
|
+
text = element
|
76
|
+
end
|
77
|
+
text.titleize
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.override_first(array)
|
81
|
+
first = self.new_from_hash(text: home_text, url: home_url)
|
82
|
+
array[0] = first
|
83
|
+
array
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.generate_crumbs_from_url(in_url)
|
87
|
+
output = []
|
88
|
+
used_elements = []
|
89
|
+
elements = in_url.split('/')
|
90
|
+
last_index = elements.length - 1
|
91
|
+
elements.each_with_index do |element, index|
|
92
|
+
used_elements << element
|
93
|
+
url = used_elements.join('/')
|
94
|
+
previous_element = elements[index -1]
|
95
|
+
text = self.get_text_from_element(element, previous_element)
|
96
|
+
output_url = (index < last_index) ? url : nil
|
97
|
+
new_crumb = self.new_from_hash(url: output_url, text: text)
|
98
|
+
output << new_crumb unless new_crumb.hidden?
|
99
|
+
end
|
100
|
+
self.override_first(output)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
protected
|
105
|
+
|
106
|
+
def self.value_from_key(key, hash)
|
107
|
+
hash[key.to_s] || hash[key.to_sym]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BreadnButter::Helpers
|
2
|
+
# Include this module in any controller you want to use breadcrumbs
|
3
|
+
def get_breadcrumbs
|
4
|
+
# note controller.request.env instead of controller.env
|
5
|
+
# so that it works in both development, staging,
|
6
|
+
# and in our controller specs which render views
|
7
|
+
url = controller.request.env['PATH_INFO']
|
8
|
+
BreadnButter::Crumb.generate_crumbs_from_url(url)
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_breadcrumbs
|
12
|
+
render :partial => 'breadnbutter/crumb', :locals => {:breadcrumbs => get_breadcrumbs}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: breadnbutter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jack Desert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Craft generic breadcrumbs from the controller path
|
42
|
+
email:
|
43
|
+
- jackdesert@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- CHANGELOG
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- app/views/breadnbutter/_crumb.html.erb
|
55
|
+
- breadnbutter.gemspec
|
56
|
+
- lib/breadnbutter.rb
|
57
|
+
- lib/breadnbutter/engine.rb
|
58
|
+
- lib/breadnbutter/helpers.rb
|
59
|
+
- lib/breadnbutter/railtie.rb
|
60
|
+
- lib/breadnbutter/version.rb
|
61
|
+
homepage: http://github.com/jackdesert/breadnbutter
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: 'Most of the times when I use a breadcrumb, the requirements are really simple:
|
85
|
+
show me what object I''m looking, and what its parent is, and give me links back
|
86
|
+
to either the parent, the view, or the root.'
|
87
|
+
test_files: []
|