croutons 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 +3 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +120 -0
- data/LICENSE +20 -0
- data/README.md +22 -0
- data/Rakefile +7 -0
- data/app/views/breadcrumbs/_breadcrumbs.html.erb +9 -0
- data/croutons.gemspec +19 -0
- data/lib/croutons.rb +6 -0
- data/lib/croutons/breadcrumb.rb +26 -0
- data/lib/croutons/breadcrumb_trail.rb +51 -0
- data/lib/croutons/controller.rb +35 -0
- data/lib/croutons/engine.rb +6 -0
- data/lib/croutons/version.rb +3 -0
- data/spec/features/breadcrumbs_spec.rb +63 -0
- data/spec/lib/croutons/breadcrumb_spec.rb +47 -0
- data/spec/lib/croutons/breadcrumb_trail_spec.rb +83 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/rails_app.rb +105 -0
- metadata +113 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: d49c400b14e1ccce5fab8540166dbc4d300df853
|
|
4
|
+
data.tar.gz: 770ec40bb463b47d65e3db37929b93d3362c68fc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 52df3bd704b508230ea387837a433e0047c1db40ca01166da459be7cefc4676912b0fb6ab85cc424b3c3c53f2158ab50445be67206ca0e28b32cc0fe5ccadc2c
|
|
7
|
+
data.tar.gz: e69654ec8e87815c9c2b8d2cb4472486511eb6c72a81bd7cce9fb9cf01218d69dc55427a76f2a55eaef2e0190e31419a39bf6c2e94a0cdc759dd66f2fa961468
|
data/.gitignore
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Declare your gem's dependencies in croutons.gemspec.
|
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
|
5
|
+
# development dependencies will be added by default to the :development group.
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
|
11
|
+
# your gem to rubygems.org.
|
|
12
|
+
|
|
13
|
+
# To use debugger
|
|
14
|
+
# gem 'debugger'
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
croutons (0.0.1)
|
|
5
|
+
rails (>= 4.1.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
actionmailer (4.1.5)
|
|
11
|
+
actionpack (= 4.1.5)
|
|
12
|
+
actionview (= 4.1.5)
|
|
13
|
+
mail (~> 2.5.4)
|
|
14
|
+
actionpack (4.1.5)
|
|
15
|
+
actionview (= 4.1.5)
|
|
16
|
+
activesupport (= 4.1.5)
|
|
17
|
+
rack (~> 1.5.2)
|
|
18
|
+
rack-test (~> 0.6.2)
|
|
19
|
+
actionview (4.1.5)
|
|
20
|
+
activesupport (= 4.1.5)
|
|
21
|
+
builder (~> 3.1)
|
|
22
|
+
erubis (~> 2.7.0)
|
|
23
|
+
activemodel (4.1.5)
|
|
24
|
+
activesupport (= 4.1.5)
|
|
25
|
+
builder (~> 3.1)
|
|
26
|
+
activerecord (4.1.5)
|
|
27
|
+
activemodel (= 4.1.5)
|
|
28
|
+
activesupport (= 4.1.5)
|
|
29
|
+
arel (~> 5.0.0)
|
|
30
|
+
activesupport (4.1.5)
|
|
31
|
+
i18n (~> 0.6, >= 0.6.9)
|
|
32
|
+
json (~> 1.7, >= 1.7.7)
|
|
33
|
+
minitest (~> 5.1)
|
|
34
|
+
thread_safe (~> 0.1)
|
|
35
|
+
tzinfo (~> 1.1)
|
|
36
|
+
arel (5.0.1.20140414130214)
|
|
37
|
+
builder (3.2.2)
|
|
38
|
+
capybara (2.3.0)
|
|
39
|
+
mime-types (>= 1.16)
|
|
40
|
+
nokogiri (>= 1.3.3)
|
|
41
|
+
rack (>= 1.0.0)
|
|
42
|
+
rack-test (>= 0.5.4)
|
|
43
|
+
xpath (~> 2.0)
|
|
44
|
+
diff-lcs (1.2.5)
|
|
45
|
+
erubis (2.7.0)
|
|
46
|
+
hike (1.2.3)
|
|
47
|
+
i18n (0.6.11)
|
|
48
|
+
json (1.8.1)
|
|
49
|
+
mail (2.5.4)
|
|
50
|
+
mime-types (~> 1.16)
|
|
51
|
+
treetop (~> 1.4.8)
|
|
52
|
+
mime-types (1.25.1)
|
|
53
|
+
mini_portile (0.6.0)
|
|
54
|
+
minitest (5.4.1)
|
|
55
|
+
multi_json (1.10.1)
|
|
56
|
+
nokogiri (1.6.3.1)
|
|
57
|
+
mini_portile (= 0.6.0)
|
|
58
|
+
polyglot (0.3.5)
|
|
59
|
+
rack (1.5.2)
|
|
60
|
+
rack-test (0.6.2)
|
|
61
|
+
rack (>= 1.0)
|
|
62
|
+
rails (4.1.5)
|
|
63
|
+
actionmailer (= 4.1.5)
|
|
64
|
+
actionpack (= 4.1.5)
|
|
65
|
+
actionview (= 4.1.5)
|
|
66
|
+
activemodel (= 4.1.5)
|
|
67
|
+
activerecord (= 4.1.5)
|
|
68
|
+
activesupport (= 4.1.5)
|
|
69
|
+
bundler (>= 1.3.0, < 2.0)
|
|
70
|
+
railties (= 4.1.5)
|
|
71
|
+
sprockets-rails (~> 2.0)
|
|
72
|
+
railties (4.1.5)
|
|
73
|
+
actionpack (= 4.1.5)
|
|
74
|
+
activesupport (= 4.1.5)
|
|
75
|
+
rake (>= 0.8.7)
|
|
76
|
+
thor (>= 0.18.1, < 2.0)
|
|
77
|
+
rake (10.3.2)
|
|
78
|
+
rspec-core (3.0.3)
|
|
79
|
+
rspec-support (~> 3.0.0)
|
|
80
|
+
rspec-expectations (3.0.3)
|
|
81
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
82
|
+
rspec-support (~> 3.0.0)
|
|
83
|
+
rspec-mocks (3.0.3)
|
|
84
|
+
rspec-support (~> 3.0.0)
|
|
85
|
+
rspec-rails (3.0.2)
|
|
86
|
+
actionpack (>= 3.0)
|
|
87
|
+
activesupport (>= 3.0)
|
|
88
|
+
railties (>= 3.0)
|
|
89
|
+
rspec-core (~> 3.0.0)
|
|
90
|
+
rspec-expectations (~> 3.0.0)
|
|
91
|
+
rspec-mocks (~> 3.0.0)
|
|
92
|
+
rspec-support (~> 3.0.0)
|
|
93
|
+
rspec-support (3.0.3)
|
|
94
|
+
sprockets (2.12.1)
|
|
95
|
+
hike (~> 1.2)
|
|
96
|
+
multi_json (~> 1.0)
|
|
97
|
+
rack (~> 1.0)
|
|
98
|
+
tilt (~> 1.1, != 1.3.0)
|
|
99
|
+
sprockets-rails (2.1.4)
|
|
100
|
+
actionpack (>= 3.0)
|
|
101
|
+
activesupport (>= 3.0)
|
|
102
|
+
sprockets (~> 2.8)
|
|
103
|
+
thor (0.19.1)
|
|
104
|
+
thread_safe (0.3.4)
|
|
105
|
+
tilt (1.4.1)
|
|
106
|
+
treetop (1.4.15)
|
|
107
|
+
polyglot
|
|
108
|
+
polyglot (>= 0.3.1)
|
|
109
|
+
tzinfo (1.2.2)
|
|
110
|
+
thread_safe (~> 0.1)
|
|
111
|
+
xpath (2.0.0)
|
|
112
|
+
nokogiri (~> 1.3)
|
|
113
|
+
|
|
114
|
+
PLATFORMS
|
|
115
|
+
ruby
|
|
116
|
+
|
|
117
|
+
DEPENDENCIES
|
|
118
|
+
capybara
|
|
119
|
+
croutons!
|
|
120
|
+
rspec-rails
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2014 Calle Erlandsson, George Brocklehurst, and thoughtbot inc.
|
|
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.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Croutons
|
|
2
|
+
|
|
3
|
+
Easy breadcrumbs for Rails apps.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
1. Include `Croutons::Controller` in `ApplicationController`
|
|
8
|
+
2. Call the `#breadcrumbs` helper in your layout or other views
|
|
9
|
+
3. Define a `BreadcrumbTrail` class, which inherits from
|
|
10
|
+
`Croutons::BreadcrumbTrail`
|
|
11
|
+
4. Define missing methods on the `BreadcrumbTrail` class. For example, for
|
|
12
|
+
the `admin/locations/index.html.erb` view you would define a
|
|
13
|
+
`#admin_locations_index` method.
|
|
14
|
+
|
|
15
|
+
In these methods you build up a breadcrumb trail by calling `#breadcrumb`
|
|
16
|
+
with a label and an optional URL, and calling the methods for other views
|
|
17
|
+
to build on existing trails. View assigns (i.e. the controller ivars) are
|
|
18
|
+
available via the `#objects` method which returns a hash.
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
MIT. See the LICENSE file for details.
|
data/Rakefile
ADDED
data/croutons.gemspec
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
|
|
3
|
+
require "croutons/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "croutons"
|
|
7
|
+
s.version = Croutons::VERSION
|
|
8
|
+
s.authors = ["Calle Erlandsson", "George Brocklehurst"]
|
|
9
|
+
s.email = ["calle@thoughtbot.com", "george@thoughtbot.com", "hello@thoughtbot.com"]
|
|
10
|
+
s.homepage = "https://github.com/thoughtbot/croutons"
|
|
11
|
+
s.summary = "Easy breadcrumbs for Rails apps."
|
|
12
|
+
s.license = "MIT"
|
|
13
|
+
s.files = `git ls-files -z`.split("\x0")
|
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
|
15
|
+
s.require_paths = ["lib"]
|
|
16
|
+
s.add_dependency "rails", ">= 4.1.0"
|
|
17
|
+
s.add_development_dependency "rspec-rails"
|
|
18
|
+
s.add_development_dependency "capybara"
|
|
19
|
+
end
|
data/lib/croutons.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Croutons
|
|
2
|
+
class Breadcrumb
|
|
3
|
+
attr_reader :label, :url
|
|
4
|
+
|
|
5
|
+
def initialize(label, url = nil)
|
|
6
|
+
self.label = label
|
|
7
|
+
self.url = url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def labelize
|
|
11
|
+
self.url = nil
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def link?
|
|
15
|
+
url.present?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def ==(other)
|
|
19
|
+
label == other.label && url == other.url
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_writer :label, :url
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'croutons/breadcrumb'
|
|
2
|
+
|
|
3
|
+
module Croutons
|
|
4
|
+
class BreadcrumbTrail
|
|
5
|
+
def self.breadcrumbs(*args)
|
|
6
|
+
new(*args).breadcrumbs
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
attr_reader :breadcrumbs
|
|
10
|
+
|
|
11
|
+
def initialize(template_identifer, objects = {})
|
|
12
|
+
@template_identifer = template_identifer
|
|
13
|
+
@objects = objects.with_indifferent_access
|
|
14
|
+
@breadcrumbs = []
|
|
15
|
+
build_breadcrumbs
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def method_missing(name, *args)
|
|
19
|
+
if respond_to_missing?(name)
|
|
20
|
+
Rails.application.routes.url_helpers.public_send(name, *args)
|
|
21
|
+
else
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def respond_to_missing?(name)
|
|
27
|
+
Rails.application.routes.url_helpers.respond_to?(name)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_reader :template_identifer, :objects
|
|
33
|
+
|
|
34
|
+
def build_breadcrumbs
|
|
35
|
+
send(template_identifer)
|
|
36
|
+
labelize_last
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def labelize_last
|
|
40
|
+
breadcrumbs.last.try(:labelize)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def breadcrumb(*args)
|
|
44
|
+
breadcrumbs << Breadcrumb.new(*args)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def t(*args)
|
|
48
|
+
I18n.t(*args)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Croutons
|
|
2
|
+
module Controller
|
|
3
|
+
def self.included(controller)
|
|
4
|
+
controller.helper_method(:breadcrumbs)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def render_to_body(options)
|
|
8
|
+
@_template = options[:template]
|
|
9
|
+
@_prefixes = options[:prefixes]
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def breadcrumbs
|
|
16
|
+
template = lookup_context.find_template(@_template, @_prefixes)
|
|
17
|
+
template_identifier = template.virtual_path.gsub('/', '_')
|
|
18
|
+
breadcrumbs = breadcrumb_trail.breadcrumbs(template_identifier, view_assigns)
|
|
19
|
+
render_to_string(
|
|
20
|
+
partial: 'breadcrumbs/breadcrumbs',
|
|
21
|
+
locals: { breadcrumbs: breadcrumbs },
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def breadcrumb_trail
|
|
26
|
+
::BreadcrumbTrail
|
|
27
|
+
rescue NameError
|
|
28
|
+
raise NotImplementedError,
|
|
29
|
+
'Define a `BreadcrumbTrail` class that inherits from '\
|
|
30
|
+
'`Breadcrumbs::BreadcrumbTrail`, or override the '\
|
|
31
|
+
'`breadcrumb_trail` method in your controller so that it '\
|
|
32
|
+
'returns an object that responds to `#breadcrumbs`.'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe "Breadcrumbs" do
|
|
4
|
+
before(:all) do |test|
|
|
5
|
+
setup_rails_app do |rails_app|
|
|
6
|
+
rails_app.scaffold_model "Post", "title:string"
|
|
7
|
+
rails_app.add_croutons_mixin_to_application_controller
|
|
8
|
+
rails_app.add_breadcrumbs_to_layout
|
|
9
|
+
rails_app.add_breadcrumb_trail_class <<-RUBY
|
|
10
|
+
require "croutons/breadcrumb_trail"
|
|
11
|
+
|
|
12
|
+
class BreadcrumbTrail < Croutons::BreadcrumbTrail
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def posts_index
|
|
16
|
+
breadcrumb("Posts", posts_path)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def posts_show
|
|
20
|
+
posts_index
|
|
21
|
+
breadcrumb(objects[:post].title)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
RUBY
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test.class.send :include, Capybara::DSL
|
|
28
|
+
test.class.send :include, Rails.application.routes.url_helpers
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "are rendered on page" do
|
|
32
|
+
post = Post.create!(title: "My first post")
|
|
33
|
+
|
|
34
|
+
visit posts_path
|
|
35
|
+
|
|
36
|
+
with_breadcrumbs do |items|
|
|
37
|
+
expect(items.length).to eq 1
|
|
38
|
+
expect(items.first).to have_content("Posts")
|
|
39
|
+
expect(items.first).not_to have_css("a")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
visit post_path(post)
|
|
43
|
+
|
|
44
|
+
with_breadcrumbs do |items|
|
|
45
|
+
expect(items.length).to eq 2
|
|
46
|
+
expect(items.first).to have_link("Posts", href: posts_path)
|
|
47
|
+
expect(items.last).to have_content(post.title)
|
|
48
|
+
expect(items.last).not_to have_css("a")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when not defined" do
|
|
53
|
+
it "raises a helpful exception" do
|
|
54
|
+
expect { visit new_post_path }.to raise_exception(/posts_new/)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def with_breadcrumbs
|
|
59
|
+
within(".breadcrumbs") do
|
|
60
|
+
yield all("li")
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "croutons/breadcrumb"
|
|
3
|
+
|
|
4
|
+
describe Croutons::Breadcrumb do
|
|
5
|
+
describe "#labelize" do
|
|
6
|
+
it "sets url to nil" do
|
|
7
|
+
breadcrumb = described_class.new("Some text", "Some url")
|
|
8
|
+
|
|
9
|
+
breadcrumb.labelize
|
|
10
|
+
|
|
11
|
+
expect(breadcrumb.url).to be_nil
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "#link?" do
|
|
16
|
+
it "returns true when the url is present" do
|
|
17
|
+
expect(described_class.new("Some text", "Some url")).to be_link
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns false when the url is blank" do
|
|
21
|
+
expect(described_class.new("Some text", nil)).not_to be_link
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#==" do
|
|
26
|
+
it "returns true when the label and URL match" do
|
|
27
|
+
one = described_class.new("label", "url")
|
|
28
|
+
two = described_class.new("label", "url")
|
|
29
|
+
|
|
30
|
+
expect(one).to eq(two)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "returns false when the labels differ" do
|
|
34
|
+
one = described_class.new("label", "url")
|
|
35
|
+
two = described_class.new("other", "url")
|
|
36
|
+
|
|
37
|
+
expect(one).not_to eq(two)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "returns false when the URLs differ" do
|
|
41
|
+
one = described_class.new("label", "url")
|
|
42
|
+
two = described_class.new("label", "other")
|
|
43
|
+
|
|
44
|
+
expect(one).not_to eq(two)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "croutons/breadcrumb_trail"
|
|
3
|
+
require "croutons/breadcrumb"
|
|
4
|
+
require "rails"
|
|
5
|
+
|
|
6
|
+
describe Croutons::BreadcrumbTrail do
|
|
7
|
+
describe ".breadcrumbs" do
|
|
8
|
+
let(:trail) do
|
|
9
|
+
Class.new(described_class) do
|
|
10
|
+
def one
|
|
11
|
+
breadcrumb("One", "/one")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def two
|
|
15
|
+
one
|
|
16
|
+
breadcrumb("Two", "/two")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def thing
|
|
20
|
+
breadcrumb(objects[:thing])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def translated
|
|
24
|
+
breadcrumb(t(objects[:key]))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def routes
|
|
28
|
+
breadcrumb("Some path", some_path)
|
|
29
|
+
breadcrumb("You are here")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "for a known template identifier" do
|
|
35
|
+
it "returns breadcrumbs" do
|
|
36
|
+
expect(trail.breadcrumbs(:one)).to eq [
|
|
37
|
+
Croutons::Breadcrumb.new("One"),
|
|
38
|
+
]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "removes the URL from the final crumb" do
|
|
42
|
+
expect(trail.breadcrumbs(:two)).to eq [
|
|
43
|
+
Croutons::Breadcrumb.new("One", "/one"),
|
|
44
|
+
Croutons::Breadcrumb.new("Two"),
|
|
45
|
+
]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "makes the given objects available through #objects" do
|
|
49
|
+
expect(trail.breadcrumbs(:thing, thing: "Foo")).
|
|
50
|
+
to eq [Croutons::Breadcrumb.new("Foo")]
|
|
51
|
+
expect(trail.breadcrumbs(:thing, "thing" => "Bar")).
|
|
52
|
+
to eq [Croutons::Breadcrumb.new("Bar")]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "makes I18n available" do
|
|
56
|
+
allow(I18n).to receive(:t).
|
|
57
|
+
with("some.translation").
|
|
58
|
+
and_return("translated string")
|
|
59
|
+
expect(trail.breadcrumbs(:translated, key: "some.translation")).
|
|
60
|
+
to eq [Croutons::Breadcrumb.new("translated string")]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "makes Rails route helpers available" do
|
|
64
|
+
route_helpers = double("route_helpers", some_path: "/some/path")
|
|
65
|
+
allow(Rails).
|
|
66
|
+
to receive_message_chain(:application, :routes, :url_helpers).
|
|
67
|
+
and_return(route_helpers)
|
|
68
|
+
|
|
69
|
+
expect(trail.breadcrumbs(:routes)).to eq [
|
|
70
|
+
Croutons::Breadcrumb.new("Some path", "/some/path"),
|
|
71
|
+
Croutons::Breadcrumb.new("You are here"),
|
|
72
|
+
]
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "for an unknown template identifier" do
|
|
77
|
+
it "raises a helpful exception" do
|
|
78
|
+
expect { trail.breadcrumbs(:not_real) }.
|
|
79
|
+
to raise_exception(NoMethodError)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
class RailsApp
|
|
2
|
+
PROJECT_ROOT = File.expand_path("../../..", __FILE__).freeze
|
|
3
|
+
|
|
4
|
+
module Helpers
|
|
5
|
+
def setup_rails_app(&block)
|
|
6
|
+
RailsApp.new.setup(&block)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
create_rails_app
|
|
12
|
+
disable_class_caching
|
|
13
|
+
customize_gemfile
|
|
14
|
+
bundle
|
|
15
|
+
yield self
|
|
16
|
+
setup_database
|
|
17
|
+
load_environment
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def scaffold_model(name, *columns)
|
|
21
|
+
in_app_directory do
|
|
22
|
+
run "rails generate scaffold #{name} #{columns.join(' ')} --test-framework=none"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def add_croutons_mixin_to_application_controller
|
|
27
|
+
transform_file(path("app/controllers/application_controller.rb")) do |content|
|
|
28
|
+
content.sub(
|
|
29
|
+
/^(class.*)$/,
|
|
30
|
+
"require 'croutons/controller'\n\n\\1\n include Croutons::Controller\n"
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_breadcrumbs_to_layout
|
|
36
|
+
transform_file(path("app/views/layouts/application.html.erb")) do |content|
|
|
37
|
+
content.sub("<body>", "<body>\n<%= breadcrumbs %>")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def add_breadcrumb_trail_class(source)
|
|
42
|
+
File.write(path("app/models/breadcrumb_trail.rb"), source)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def create_rails_app
|
|
48
|
+
run "bundle exec rails new #{path} --skip-bundle --force"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def disable_class_caching
|
|
52
|
+
transform_file(path("config/environments/test.rb")) do |content|
|
|
53
|
+
content.gsub(/^\s*config\.cache_classes.*$/, "config.cache_classes = false")
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def customize_gemfile
|
|
58
|
+
File.open(path("Gemfile"), "a") do |f|
|
|
59
|
+
f << "gem 'croutons', path: '#{PROJECT_ROOT}'\n"
|
|
60
|
+
f << "gem 'rspec-rails', group: :test\n"
|
|
61
|
+
f << "gem 'capybara', group: :test\n"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def bundle
|
|
66
|
+
in_app_directory do
|
|
67
|
+
run "bundle"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def setup_database
|
|
72
|
+
in_app_directory do
|
|
73
|
+
run "rake db:drop:all db:create:all db:migrate"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def load_environment
|
|
78
|
+
require path("config/environment.rb")
|
|
79
|
+
require "rspec/rails"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def in_app_directory(&block)
|
|
83
|
+
Dir.chdir(path, &block)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def run(command)
|
|
87
|
+
`#{command}`
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def transform_file(filename)
|
|
91
|
+
content = File.read(filename)
|
|
92
|
+
File.open(filename, "w") do |f|
|
|
93
|
+
content = yield(content)
|
|
94
|
+
f.write(content)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def path(filename = "")
|
|
99
|
+
File.join(PROJECT_ROOT, "spec", "dummy_app", filename)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
RSpec.configure do |config|
|
|
104
|
+
config.include RailsApp::Helpers
|
|
105
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: croutons
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Calle Erlandsson
|
|
8
|
+
- George Brocklehurst
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rails
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ">="
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: 4.1.0
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: 4.1.0
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: rspec-rails
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
42
|
+
- !ruby/object:Gem::Dependency
|
|
43
|
+
name: capybara
|
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
type: :development
|
|
50
|
+
prerelease: false
|
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
description:
|
|
57
|
+
email:
|
|
58
|
+
- calle@thoughtbot.com
|
|
59
|
+
- george@thoughtbot.com
|
|
60
|
+
- hello@thoughtbot.com
|
|
61
|
+
executables: []
|
|
62
|
+
extensions: []
|
|
63
|
+
extra_rdoc_files: []
|
|
64
|
+
files:
|
|
65
|
+
- ".gitignore"
|
|
66
|
+
- Gemfile
|
|
67
|
+
- Gemfile.lock
|
|
68
|
+
- LICENSE
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- app/views/breadcrumbs/_breadcrumbs.html.erb
|
|
72
|
+
- croutons.gemspec
|
|
73
|
+
- lib/croutons.rb
|
|
74
|
+
- lib/croutons/breadcrumb.rb
|
|
75
|
+
- lib/croutons/breadcrumb_trail.rb
|
|
76
|
+
- lib/croutons/controller.rb
|
|
77
|
+
- lib/croutons/engine.rb
|
|
78
|
+
- lib/croutons/version.rb
|
|
79
|
+
- spec/features/breadcrumbs_spec.rb
|
|
80
|
+
- spec/lib/croutons/breadcrumb_spec.rb
|
|
81
|
+
- spec/lib/croutons/breadcrumb_trail_spec.rb
|
|
82
|
+
- spec/spec_helper.rb
|
|
83
|
+
- spec/support/rails_app.rb
|
|
84
|
+
homepage: https://github.com/thoughtbot/croutons
|
|
85
|
+
licenses:
|
|
86
|
+
- MIT
|
|
87
|
+
metadata: {}
|
|
88
|
+
post_install_message:
|
|
89
|
+
rdoc_options: []
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
requirements: []
|
|
103
|
+
rubyforge_project:
|
|
104
|
+
rubygems_version: 2.2.2
|
|
105
|
+
signing_key:
|
|
106
|
+
specification_version: 4
|
|
107
|
+
summary: Easy breadcrumbs for Rails apps.
|
|
108
|
+
test_files:
|
|
109
|
+
- spec/features/breadcrumbs_spec.rb
|
|
110
|
+
- spec/lib/croutons/breadcrumb_spec.rb
|
|
111
|
+
- spec/lib/croutons/breadcrumb_trail_spec.rb
|
|
112
|
+
- spec/spec_helper.rb
|
|
113
|
+
- spec/support/rails_app.rb
|