croutons 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile.lock +4 -2
- data/README.md +97 -14
- data/croutons.gemspec +1 -0
- data/lib/croutons/controller.rb +3 -2
- data/lib/croutons/version.rb +1 -1
- data/spec/features/breadcrumbs_spec.rb +15 -3
- data/spec/support/rails_app.rb +9 -6
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61e3cdbf4accef61075b07b77c880553dcdf1f16
|
4
|
+
data.tar.gz: 3aa0e45ba9172a432f036be7a3cbfae6741386f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5fa9c469fa8b4e06de0a863f14b2815f3f5504faf3ef669a7f7f46ab3f2c62a3014c07cab72b55e684a95e867db328f902de03d66701819cba439febb6d971e
|
7
|
+
data.tar.gz: 9f96d24f6d49aa293d4909bfa1d9efb294ea82e7fa925afd59d3ecc55f8266784fe91f0ef9a423cdefced00e7b3df584ad6e4a27f23aa2d6c6765929d2e285e4
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.3
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
croutons (0.0.
|
4
|
+
croutons (0.0.2)
|
5
5
|
rails (>= 4.1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -91,7 +91,7 @@ GEM
|
|
91
91
|
rspec-mocks (~> 3.0.0)
|
92
92
|
rspec-support (~> 3.0.0)
|
93
93
|
rspec-support (3.0.3)
|
94
|
-
sprockets (2.12.
|
94
|
+
sprockets (2.12.2)
|
95
95
|
hike (~> 1.2)
|
96
96
|
multi_json (~> 1.0)
|
97
97
|
rack (~> 1.0)
|
@@ -100,6 +100,7 @@ GEM
|
|
100
100
|
actionpack (>= 3.0)
|
101
101
|
activesupport (>= 3.0)
|
102
102
|
sprockets (~> 2.8)
|
103
|
+
sqlite3 (1.3.9)
|
103
104
|
thor (0.19.1)
|
104
105
|
thread_safe (0.3.4)
|
105
106
|
tilt (1.4.1)
|
@@ -118,3 +119,4 @@ DEPENDENCIES
|
|
118
119
|
capybara
|
119
120
|
croutons!
|
120
121
|
rspec-rails
|
122
|
+
sqlite3
|
data/README.md
CHANGED
@@ -1,22 +1,105 @@
|
|
1
|
-
|
1
|
+
Croutons
|
2
|
+
========
|
2
3
|
|
3
4
|
Easy breadcrumbs for Rails apps.
|
4
5
|
|
5
|
-
|
6
|
+
Usage
|
7
|
+
-----
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
### Required steps
|
10
|
+
|
11
|
+
1. Include `Croutons::Controller` in your `ApplicationController`.
|
12
|
+
|
13
|
+
This will make a `#breadcrumbs` helper available in your layouts and views.
|
14
|
+
2. Call the `#breadcrumbs` helper in your layouts or views.
|
9
15
|
3. Define a `BreadcrumbTrail` class, which inherits from
|
10
|
-
`Croutons::BreadcrumbTrail
|
11
|
-
4. Define missing methods on the `BreadcrumbTrail` class.
|
12
|
-
|
13
|
-
|
16
|
+
`Croutons::BreadcrumbTrail`.
|
17
|
+
4. Define missing methods on the `BreadcrumbTrail` class.
|
18
|
+
|
19
|
+
For example, for the `admin/locations/index.html.erb` view you would define
|
20
|
+
an `#admin_locations_index` method.
|
21
|
+
|
22
|
+
In these methods, you build up a breadcrumb trail by calling `#breadcrumb`
|
23
|
+
with a label and an optional URL. You can also call previously defined
|
24
|
+
methods to build on existing trails. View assigns (i.e. the controller
|
25
|
+
instance variables) are available via the `#objects` method which returns a
|
26
|
+
`Hash`. Rails route helpers are also available inside this class.
|
27
|
+
|
28
|
+
Please see [the example below](#example) for further reference.
|
29
|
+
|
30
|
+
### Optional steps
|
31
|
+
|
32
|
+
* Instead of defining a `BreadcrumbTrail` class you can use an object of your
|
33
|
+
own that responds to `#breadcrumbs`.
|
34
|
+
|
35
|
+
To do this, override the private `#breadcrumb_trail` method in the controller
|
36
|
+
where you included `Croutons::Controller`, to return the object you want to
|
37
|
+
use.
|
38
|
+
|
39
|
+
The `#breadcrumbs` method is passed two parameters: one `template_identifier`
|
40
|
+
`String` and one `objects` `Hash`. The `#breadcrumbs` method should return an
|
41
|
+
`Array` of `Croutons::Breadcrumb`s.
|
42
|
+
|
43
|
+
* Override the view used to render breadcrumbs.
|
44
|
+
|
45
|
+
To do this, create a view called `breadcrumbs/_breadcrumbs.html.erb`.
|
46
|
+
|
47
|
+
In this view, an `Array` of `Croutons::Breadcrumb`s is assigned to the local
|
48
|
+
variable `breadcrumbs`. These `Croutons::Breadcrumb`s have two public
|
49
|
+
attributes: `#label` and `#url`. The `#url` attribute is optional. To check
|
50
|
+
whether the `Croutons::Breadcrumb` has a `#url` or not (i.e. should be
|
51
|
+
rendered as a link or not), check whether the `#link?` method returns `true`
|
52
|
+
or `false`.
|
53
|
+
|
54
|
+
### Example
|
55
|
+
|
56
|
+
#### `app/controllers/application_controller.rb`
|
57
|
+
|
58
|
+
class ApplicationController < ActionController::Base
|
59
|
+
include Croutons::Controller
|
60
|
+
end
|
61
|
+
|
62
|
+
#### `app/controllers/posts_controller.rb`
|
63
|
+
|
64
|
+
class PostsController < ApplicationController
|
65
|
+
def index
|
66
|
+
@posts = Post.all
|
67
|
+
end
|
68
|
+
|
69
|
+
def show
|
70
|
+
@post = Post.find(params[:id])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#### `app/views/layouts/application.html.erb`
|
75
|
+
|
76
|
+
<!DOCTYPE html>
|
77
|
+
<html>
|
78
|
+
<head>
|
79
|
+
<title>My blog</title>
|
80
|
+
</head>
|
81
|
+
<body>
|
82
|
+
<%= breadcrumbs %>
|
83
|
+
<%= yield %>
|
84
|
+
</body>
|
85
|
+
</html>
|
86
|
+
|
87
|
+
#### `app/models/breadcrumb_trail.rb`
|
88
|
+
|
89
|
+
class BreadcrumbTrail < Croutons::BreadcrumbTrail
|
90
|
+
def posts_index
|
91
|
+
breadcrumb("Posts", posts_path)
|
92
|
+
end
|
14
93
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
94
|
+
def posts_show
|
95
|
+
posts_index
|
96
|
+
breadcrumb(objects[:post].title, post_path(objects[:post])
|
97
|
+
end
|
98
|
+
end
|
19
99
|
|
20
|
-
|
100
|
+
License
|
101
|
+
-------
|
21
102
|
|
22
|
-
|
103
|
+
Croutons is Copyright © 2014 Calle Erlandsson, George Brocklehurst, and
|
104
|
+
thoughtbot. It is free software, and may be redistributed under the terms
|
105
|
+
specified in the LICENSE file.
|
data/croutons.gemspec
CHANGED
data/lib/croutons/controller.rb
CHANGED
@@ -12,10 +12,11 @@ module Croutons
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def breadcrumbs
|
15
|
+
def breadcrumbs(objects = {})
|
16
16
|
template = lookup_context.find_template(@_template, @_prefixes)
|
17
17
|
template_identifier = template.virtual_path.gsub('/', '_')
|
18
|
-
|
18
|
+
objects.reverse_merge!(view_assigns)
|
19
|
+
breadcrumbs = breadcrumb_trail.breadcrumbs(template_identifier, objects)
|
19
20
|
render_to_string(
|
20
21
|
partial: 'breadcrumbs/breadcrumbs',
|
21
22
|
locals: { breadcrumbs: breadcrumbs },
|
data/lib/croutons/version.rb
CHANGED
@@ -5,7 +5,9 @@ describe "Breadcrumbs" do
|
|
5
5
|
setup_rails_app do |rails_app|
|
6
6
|
rails_app.scaffold_model "Post", "title:string"
|
7
7
|
rails_app.add_croutons_mixin_to_application_controller
|
8
|
-
rails_app.
|
8
|
+
rails_app.add_to_view('posts/index', '<%= breadcrumbs %>')
|
9
|
+
rails_app.add_to_view('posts/show', '<%= breadcrumbs role: params[:role] %>')
|
10
|
+
rails_app.add_to_view('posts/new', '<%= breadcrumbs %>')
|
9
11
|
rails_app.add_breadcrumb_trail_class <<-RUBY
|
10
12
|
require "croutons/breadcrumb_trail"
|
11
13
|
|
@@ -17,7 +19,9 @@ describe "Breadcrumbs" do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def posts_show
|
20
|
-
|
22
|
+
if objects[:role] == "admin"
|
23
|
+
posts_index
|
24
|
+
end
|
21
25
|
breadcrumb(objects[:post].title)
|
22
26
|
end
|
23
27
|
end
|
@@ -39,7 +43,7 @@ describe "Breadcrumbs" do
|
|
39
43
|
expect(items.first).not_to have_css("a")
|
40
44
|
end
|
41
45
|
|
42
|
-
visit post_path(post)
|
46
|
+
visit post_path(post, role: "admin")
|
43
47
|
|
44
48
|
with_breadcrumbs do |items|
|
45
49
|
expect(items.length).to eq 2
|
@@ -47,6 +51,14 @@ describe "Breadcrumbs" do
|
|
47
51
|
expect(items.last).to have_content(post.title)
|
48
52
|
expect(items.last).not_to have_css("a")
|
49
53
|
end
|
54
|
+
|
55
|
+
visit post_path(post, role: "guest")
|
56
|
+
|
57
|
+
with_breadcrumbs do |items|
|
58
|
+
expect(items.length).to eq 1
|
59
|
+
expect(items.first).to have_content(post.title)
|
60
|
+
expect(items.first).not_to have_css("a")
|
61
|
+
end
|
50
62
|
end
|
51
63
|
|
52
64
|
context "when not defined" do
|
data/spec/support/rails_app.rb
CHANGED
@@ -19,7 +19,7 @@ class RailsApp
|
|
19
19
|
|
20
20
|
def scaffold_model(name, *columns)
|
21
21
|
in_app_directory do
|
22
|
-
run "rails generate scaffold #{name} #{columns.join(' ')} --
|
22
|
+
run "rails generate scaffold #{name} #{columns.join(' ')} --force"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -32,9 +32,9 @@ class RailsApp
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
transform_file(path("app/views
|
37
|
-
content
|
35
|
+
def add_to_view(name, content_to_add)
|
36
|
+
transform_file(path("app/views/#{name}.html.erb")) do |content|
|
37
|
+
content << content_to_add
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -45,7 +45,9 @@ class RailsApp
|
|
45
45
|
private
|
46
46
|
|
47
47
|
def create_rails_app
|
48
|
-
run "bundle exec rails new #{path} --skip-bundle
|
48
|
+
run "bundle exec rails new #{path} --skip-gemfile --skip-bundle "\
|
49
|
+
"--skip-git --skip-keeps --skip-spring --skip-javascript "\
|
50
|
+
"--skip-test-unit --no-rc --skip-sprockets --force"
|
49
51
|
end
|
50
52
|
|
51
53
|
def disable_class_caching
|
@@ -55,7 +57,8 @@ class RailsApp
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def customize_gemfile
|
58
|
-
File.open(path("Gemfile"), "
|
60
|
+
File.open(path("Gemfile"), "w") do |f|
|
61
|
+
f << "source 'https://rubygems.org'\n"
|
59
62
|
f << "gem 'croutons', path: '#{PROJECT_ROOT}'\n"
|
60
63
|
f << "gem 'rspec-rails', group: :test\n"
|
61
64
|
f << "gem 'capybara', group: :test\n"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: croutons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calle Erlandsson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: sqlite3
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
description:
|
57
71
|
email:
|
58
72
|
- calle@thoughtbot.com
|
@@ -63,6 +77,8 @@ extensions: []
|
|
63
77
|
extra_rdoc_files: []
|
64
78
|
files:
|
65
79
|
- ".gitignore"
|
80
|
+
- ".ruby-version"
|
81
|
+
- ".travis.yml"
|
66
82
|
- Gemfile
|
67
83
|
- Gemfile.lock
|
68
84
|
- LICENSE
|