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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d49c400b14e1ccce5fab8540166dbc4d300df853
4
- data.tar.gz: 770ec40bb463b47d65e3db37929b93d3362c68fc
3
+ metadata.gz: 61e3cdbf4accef61075b07b77c880553dcdf1f16
4
+ data.tar.gz: 3aa0e45ba9172a432f036be7a3cbfae6741386f8
5
5
  SHA512:
6
- metadata.gz: 52df3bd704b508230ea387837a433e0047c1db40ca01166da459be7cefc4676912b0fb6ab85cc424b3c3c53f2158ab50445be67206ca0e28b32cc0fe5ccadc2c
7
- data.tar.gz: e69654ec8e87815c9c2b8d2cb4472486511eb6c72a81bd7cce9fb9cf01218d69dc55427a76f2a55eaef2e0190e31419a39bf6c2e94a0cdc759dd66f2fa961468
6
+ metadata.gz: b5fa9c469fa8b4e06de0a863f14b2815f3f5504faf3ef669a7f7f46ab3f2c62a3014c07cab72b55e684a95e867db328f902de03d66701819cba439febb6d971e
7
+ data.tar.gz: 9f96d24f6d49aa293d4909bfa1d9efb294ea82e7fa925afd59d3ecc55f8266784fe91f0ef9a423cdefced00e7b3df584ad6e4a27f23aa2d6c6765929d2e285e4
@@ -0,0 +1 @@
1
+ 2.1.3
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
4
+ script: bundle exec rspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- croutons (0.0.1)
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.1)
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
- # Croutons
1
+ Croutons
2
+ ========
2
3
 
3
4
  Easy breadcrumbs for Rails apps.
4
5
 
5
- ## Usage
6
+ Usage
7
+ -----
6
8
 
7
- 1. Include `Croutons::Controller` in `ApplicationController`
8
- 2. Call the `#breadcrumbs` helper in your layout or other views
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. For example, for
12
- the `admin/locations/index.html.erb` view you would define a
13
- `#admin_locations_index` method.
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
- 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.
94
+ def posts_show
95
+ posts_index
96
+ breadcrumb(objects[:post].title, post_path(objects[:post])
97
+ end
98
+ end
19
99
 
20
- ## License
100
+ License
101
+ -------
21
102
 
22
- MIT. See the LICENSE file for details.
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.
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency "rails", ">= 4.1.0"
17
17
  s.add_development_dependency "rspec-rails"
18
18
  s.add_development_dependency "capybara"
19
+ s.add_development_dependency "sqlite3"
19
20
  end
@@ -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
- breadcrumbs = breadcrumb_trail.breadcrumbs(template_identifier, view_assigns)
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 },
@@ -1,3 +1,3 @@
1
1
  module Croutons
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.add_breadcrumbs_to_layout
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
- posts_index
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
@@ -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(' ')} --test-framework=none"
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 add_breadcrumbs_to_layout
36
- transform_file(path("app/views/layouts/application.html.erb")) do |content|
37
- content.sub("<body>", "<body>\n<%= breadcrumbs %>")
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 --force"
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"), "a") do |f|
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.1
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-09-12 00:00:00.000000000 Z
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