loaf 0.3.0 → 0.4.0

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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -8
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +23 -2
  5. data/Appraisals +18 -0
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +16 -1
  8. data/README.md +69 -52
  9. data/Rakefile +5 -3
  10. data/bin/setup +7 -0
  11. data/gemfiles/rails3.2.gemfile +21 -0
  12. data/gemfiles/rails4.0.gemfile +22 -0
  13. data/gemfiles/rails4.1.gemfile +21 -0
  14. data/gemfiles/rails4.2.gemfile +21 -0
  15. data/lib/loaf.rb +24 -1
  16. data/lib/loaf/configuration.rb +15 -22
  17. data/lib/loaf/controller_extensions.rb +25 -12
  18. data/lib/loaf/crumb.rb +13 -1
  19. data/lib/loaf/crumb_formatter.rb +14 -13
  20. data/lib/loaf/options_validator.rb +10 -2
  21. data/lib/loaf/translation.rb +15 -8
  22. data/lib/loaf/version.rb +1 -8
  23. data/lib/loaf/view_extensions.rb +42 -15
  24. data/loaf.gemspec +10 -17
  25. data/spec/integration/configuration_spec.rb +7 -8
  26. data/spec/integration/crumbs_routing_spec.rb +31 -28
  27. data/spec/rails_app/app/controllers/application_controller.rb +0 -2
  28. data/spec/rails_app/app/controllers/posts_controller.rb +13 -2
  29. data/spec/rails_app/app/views/layouts/_breadcrumbs.html.erb +2 -0
  30. data/spec/rails_app/app/views/posts/index.html.erb +0 -2
  31. data/spec/rails_app/app/views/posts/new.html.erb +3 -0
  32. data/spec/rails_app/app/views/posts/show.html.erb +1 -0
  33. data/spec/rails_app/config/environments/development.rb +2 -0
  34. data/spec/rails_app/config/environments/production.rb +2 -0
  35. data/spec/rails_app/config/environments/test.rb +2 -3
  36. data/spec/rails_app/config/routes.rb +0 -2
  37. data/spec/rails_app/{app/mailers → log}/.gitkeep +0 -0
  38. data/spec/spec_helper.rb +42 -4
  39. data/spec/support/dummy_view.rb +7 -0
  40. data/spec/unit/controller_extensions_spec.rb +63 -0
  41. data/spec/unit/crumb_formatter_spec.rb +38 -0
  42. data/spec/unit/options_validator_spec.rb +17 -0
  43. data/spec/unit/translation_spec.rb +22 -0
  44. data/spec/unit/view_extensions/breadcrumb_spec.rb +24 -0
  45. data/spec/unit/view_extensions/breadcrumbs_spec.rb +128 -0
  46. data/spec/unit/view_extensions/has_breadcrumbs_spec.rb +12 -0
  47. data/tasks/console.rake +10 -0
  48. data/tasks/coverage.rake +11 -0
  49. data/tasks/spec.rake +29 -0
  50. metadata +50 -100
  51. data/.rvmrc +0 -28
  52. data/Gemfile.lock +0 -132
  53. data/spec/integration/nested_crumbs_spec.rb +0 -5
  54. data/spec/loaf/controller_extensions_spec.rb +0 -55
  55. data/spec/loaf/crumb_formatter_spec.rb +0 -33
  56. data/spec/loaf/options_validator_spec.rb +0 -29
  57. data/spec/loaf/translation_spec.rb +0 -23
  58. data/spec/loaf/view_extensions_spec.rb +0 -114
  59. data/spec/loaf_spec.rb +0 -5
  60. data/spec/rails_app/app/assets/images/rails.png +0 -0
  61. data/spec/rails_app/app/assets/javascripts/application.js +0 -9
  62. data/spec/rails_app/app/assets/stylesheets/application.css +0 -7
  63. data/spec/rails_app/app/helpers/application_helper.rb +0 -2
  64. data/spec/rails_app/app/models/.gitkeep +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cb34b106f14868575b5831d9de8255e52e94f2d
4
+ data.tar.gz: 8f3fdcef497c132f17cd4496b124a60b92cbc67a
5
+ SHA512:
6
+ metadata.gz: 568cd3729c360ab6d1aa4a8c19d9618d8d6dfb8312a57693896c940d94cddd5f4979e8f656ad0c3cd76db67b2b62c9d9f3fb0d5dce802bb2048a3dcc9d7aa344
7
+ data.tar.gz: 8cb65d4d05998f474f9356490f7cfe9a923b65de0e7ec8855a9bad4057f3306941a6f9bb38fea283d100e28a6349015beb79a708f84e278fe437285adef5bdab
data/.gitignore CHANGED
@@ -1,10 +1,23 @@
1
- coverage
2
- rdoc
3
- doc
4
- .yardoc
1
+ *.gem
2
+ *.rbc
5
3
  .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ gemfiles/*.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
6
13
  pkg
7
- *.swp
8
- log
9
- *.sqlite3
10
- .bundle
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -1,4 +1,25 @@
1
- script: 'rake'
1
+ language: ruby
2
+ sudo: false
3
+ bundler_args: --without yard benchmarks
4
+ install: 'travis_retry bin/setup'
5
+ script: 'bundle exec appraisal rake ci'
2
6
  rvm:
3
- - 1.9.2
4
7
  - 1.9.3
8
+ - 2.0.0
9
+ - 2.1.0
10
+ - 2.2.0
11
+ matrix:
12
+ include:
13
+ - rvm: jruby-19mode
14
+ - rvm: jruby-20mode
15
+ - rvm: jruby-21mode
16
+ - rvm: jruby-head
17
+ - rvm: rbx-2
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ - rvm: jruby-20mode
22
+ - rvm: jruby-21mode
23
+ fast_finish: true
24
+ branches:
25
+ only: master
@@ -0,0 +1,18 @@
1
+ if RUBY_VERSION < "2.2.0"
2
+ appraise 'rails3.2' do
3
+ gem 'rails', '~> 3.2.21'
4
+ end
5
+ end
6
+
7
+ appraise 'rails4.0' do
8
+ gem 'rails', '~> 4.0.13'
9
+ gem 'test-unit'
10
+ end
11
+
12
+ appraise 'rails4.1' do
13
+ gem 'rails', '~> 4.1.9'
14
+ end
15
+
16
+ appraise 'rails4.2' do
17
+ gem 'rails', '~> 4.2.0'
18
+ end
@@ -1,3 +1,15 @@
1
+ 0.4.0 (January 10, 2015)
2
+
3
+ * Change breadcrumbs view method to return enumerator without block
4
+ * Change Crumb to ruby class and add force option
5
+ * Change Configuration to ruby class and scope config options
6
+ * Add ability to force current path through :force option
7
+ * Change format_name to only take name argument
8
+ * Change to expose config settings on configuration
9
+ * Fix bug with url parameter to allow for regular rails path variables
10
+ * Update test suite to work against different rubies 1.9.x, 2.x
11
+ * Test Rails 3.2.x, 4.0, 4.1, 4.2
12
+
1
13
  0.3.0 (February 25, 2012)
2
14
 
3
15
  * Add loaf gem errors
data/Gemfile CHANGED
@@ -1,3 +1,18 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ gem 'bundler', '~> 1.3'
6
+ gem 'appraisal', '~> 1.0.2'
7
+ gem 'rake', '~> 10.4.2'
8
+ gem 'yard', '~> 0.8.7'
9
+ gem 'sqlite3', '~> 1.3.10', platforms: :ruby
10
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.10', platforms: :jruby
11
+ gem 'capybara', '~> 2.4.4'
12
+ gem 'rspec-rails', '~> 3.1.0'
13
+
14
+ group :metrics do
15
+ gem 'coveralls', '~> 0.7.2'
16
+ gem 'simplecov', '~> 0.9.1'
17
+ gem 'yardstick', '~> 0.9.9'
18
+ end
data/README.md CHANGED
@@ -1,90 +1,114 @@
1
- # Loaf [![Build Status](https://secure.travis-ci.org/peter-murach/loaf.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/peter-murach/loaf.png?travis)][gemnasium]
2
-
1
+ # Loaf
2
+ [![Gem Version](https://badge.fury.io/rb/loaf.png)][gem]
3
+ [![Build Status](https://secure.travis-ci.org/peter-murach/loaf.png?branch=master)][travis]
4
+ [![Code Climate](https://codeclimate.com/github/peter-murach/loaf.png)][codeclimate]
5
+ [![Dependency Status](https://gemnasium.com/peter-murach/loaf.png?travis)][gemnasium]
6
+ [![Coverage Status](https://coveralls.io/repos/peter-murach/loaf/badge.png?branch=master)][coveralls]
7
+ [![Inline docs](http://inch-ci.org/github/peter-murach/loaf.png?branch=master)][inchpages]
8
+
9
+ [gem]: http://badge.fury.io/rb/loaf
3
10
  [travis]: http://travis-ci.org/peter-murach/loaf
11
+ [codeclimate]: https://codeclimate.com/github/peter-murach/loaf
4
12
  [gemnasium]: https://gemnasium.com/peter-murach/loaf
13
+ [coveralls]: https://coveralls.io/r/peter-murach/loaf
14
+ [inchpages]: http://inch-ci.org/github/peter-murach/loaf
5
15
 
6
- Breadcrumbs creation library.
7
-
8
- * Helps in creating breadcrumbs.
9
- * Uses controllers to specify names and routes for parts of breadcrum trails or collections of breadcrumbs.
10
- * Stays out of your way when it comes to markup exposing only single helper method to access breadcrumb data.
11
- * Supports Rails 2 & 3.
16
+ > **Loaf** manages and displays breadcrumb trails in your Rails application.
12
17
 
13
- ## Installation
18
+ ## Features
14
19
 
15
- Install from source:
20
+ * Uses controllers or views to specify breadcrumb trails
21
+ * No markup assumptions for breadcrumbs rendering
22
+ * Use locales file for names - optional
23
+ * Tested with Rails 3.2, 4.0, 4.1, 4.2
16
24
 
17
- ```ruby
18
- gem install loaf
19
- ```
25
+ ## Installation
20
26
 
21
- Add to your Gemfile:
27
+ Add this line to your application's Gemfile:
22
28
 
23
29
  ```ruby
24
30
  gem 'loaf'
25
31
  ```
26
32
 
27
- ## Configuration
28
-
29
- There is a small set of custom opinionated defaults. The following options are valid parameters:
33
+ And then execute:
30
34
 
31
35
  ```ruby
32
- :crumb_length # breadcrumb length in integer, default length is 30 characters
33
- :root # boolean, default is true, displays the home crumb
34
- :capitalize # set breadcrumbs to have initial letter uppercase, default false
35
- :style_classes # CSS class to be used to style current breadcrumb,
36
- # defaults to 'selected'
36
+ $ bundle
37
37
  ```
38
38
 
39
- You can override them in your views by passing them to the view `breadcrumb` helper
39
+ Or install it yourself as:
40
40
 
41
41
  ```ruby
42
- <% breadcrumbs :crumb_length => 20 do |name, url, styles| %>
43
- ..
44
- <% end %>
42
+ gem install loaf
45
43
  ```
46
44
 
47
- or by adding initializer
45
+ ## 1. Usage
48
46
 
49
- ```ruby
50
- Loaf.configure do |config|
51
- config.crumb_length => 20
52
- end
53
- ```
54
-
55
- ## Usage
47
+ **Loaf** allows you to add breadcrumbs in controllers and views.
56
48
 
57
- In controller:
49
+ In order to add breadcrumbs in controller use `breadcrumb` method. Outside of controller actions the `breadcrumb` helper behaviour is similar to filters and as such you can limit breadcrumb scope with familiar options `:only`, `:except`. Any breadcrumb specified inside actions creates another level in breadcrumbs trail.
58
50
 
59
51
  ```ruby
60
52
  class Blog::CategoriesController < ApplicationController
61
53
 
62
- breadcrumb 'Article Categories', 'blog_categories_path', :only => [:show]
54
+ breadcrumb 'Article Categories', :blog_categories_path, only: [:show]
63
55
 
64
56
  def show
65
- breadcrumb "#{@category.title}", 'blog_category_path(@category)'
57
+ breadcrumb "#{@category.title}", blog_category_path(@category)
66
58
  end
67
59
  end
68
60
  ```
69
61
 
70
- You can add breadcrumbs for nested resources, for instance, article categories:
62
+ **Loaf** adds `breadcrumb` helper also to the views. Together with controller breadcrumbs, the view breadcrumbs are appended as the last. For instance, to specify view breadcrumb do:
63
+
64
+ ```ruby
65
+ <% breadcrumb "#{@category.title}", blog_category_path(@category) %>
66
+ ```
71
67
 
72
- In your view add semantic markup to show breadcrumbs:
68
+ Finally, in your view layout add semantic markup to show breadcrumbs:
73
69
 
74
70
  ```html
75
- <ul id="breadcrumbs">
76
- <%- breadcrumbs :crumb_length => 20 do |name, url, styles| -%>
71
+ <ul class='breadcrumbs'>
72
+ <% breadcrumbs do |name, url, styles| %>
77
73
  <li class="<%= styles %>">
78
74
  <%= link_to name, url %>
79
75
  <span><%= styles == 'selected' ? '' : '::' %></span>
80
76
  </li>
81
- <%- end -%>
77
+ <% end %>
82
78
  </ul>
83
79
  ```
84
80
 
85
81
  Usually best practice is to put such snippet inside its own partial.
86
82
 
87
- ## Locale
83
+ ## 2. Configuration
84
+
85
+ There is a small set of custom opinionated defaults. The following options are valid parameters:
86
+
87
+ ```ruby
88
+ :crumb_length # breadcrumb length in integer, default length is 30 characters
89
+ :root # boolean, default is true, displays the home crumb
90
+ :capitalize # set breadcrumbs to have initial letter uppercase, default false
91
+ :style_classes # CSS class to be used to style current breadcrumb,
92
+ # defaults to 'selected'
93
+ ```
94
+
95
+ You can override them in your views by passing them to the view `breadcrumb` helper
96
+
97
+ ```ruby
98
+ <% breadcrumbs crumb_length: 20 do |name, url, styles| %>
99
+ ..
100
+ <% end %>
101
+ ```
102
+
103
+ or by adding initializer in `config/initializers/loaf.rb`:
104
+
105
+ ```ruby
106
+ Loaf.configure do |config|
107
+ config.crumb_length = 20
108
+ end
109
+ ```
110
+
111
+ ## 3. Locale
88
112
 
89
113
  When adding breadcrumbs one can use locales for their titles. The only assumption it makes is that all breadcrumb names are scoped inside `breadcrumbs` namespace. However, this can be easily changed by passing `:scope => 'new_scope_name'` configuration option
90
114
 
@@ -112,17 +136,10 @@ en:
112
136
  categories: 'Article Categories'
113
137
  ```
114
138
 
115
- ## TODO
116
-
117
- * Add ability to add breadcrumbs for nested resources
118
- * Add support for name internationalisation
119
- * Finish specs
120
-
121
- ## Contributing to loaf
139
+ ## Contributing
122
140
 
123
141
  Questions or problems? Please post them on the [issue tracker](https://github.com/peter-murach/loaf/issues). You can contribute changes by forking the project and submitting a pull request. You can ensure the tests are passing by running `bundle` and `rake`.
124
142
 
125
143
  ## Copyright
126
144
 
127
- Copyright (c) 2011 Piotr Murach. See LICENSE.txt for
128
- further details.
145
+ Copyright (c) 2011-2015 Piotr Murach. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'rubygems'
4
+ require 'bundler/setup'
3
5
  require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
6
 
6
- RSpec::Core::RakeTask.new(:spec)
7
+ FileList['tasks/**/*.rake'].each(&method(:import))
7
8
 
8
- task :default => :spec
9
+ desc 'Run all specs'
10
+ task ci: %w[ spec ]
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ # Install gems required by Appraisal
6
+ bundle install
7
+ bundle exec appraisal install
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.3"
6
+ gem "appraisal", "~> 1.0.2"
7
+ gem "rake", "~> 10.3.2"
8
+ gem "yard", "~> 0.8.7"
9
+ gem "sqlite3", "~> 1.3.10", :platforms => :ruby
10
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.10", :platforms => :jruby
11
+ gem "capybara", "~> 2.4.4"
12
+ gem "rspec-rails", "~> 3.1.0"
13
+ gem "rails", "~> 3.2.21"
14
+
15
+ group :metrics do
16
+ gem "coveralls", "~> 0.7.2"
17
+ gem "simplecov", "~> 0.9.1"
18
+ gem "yardstick", "~> 0.9.9"
19
+ end
20
+
21
+ gemspec :path => "../"
@@ -0,0 +1,22 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.3"
6
+ gem "appraisal", "~> 1.0.2"
7
+ gem "rake", "~> 10.3.2"
8
+ gem "yard", "~> 0.8.7"
9
+ gem "sqlite3", "~> 1.3.10", :platforms => :ruby
10
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.10", :platforms => :jruby
11
+ gem "capybara", "~> 2.4.4"
12
+ gem "rspec-rails", "~> 3.1.0"
13
+ gem "rails", "~> 4.0.13"
14
+ gem "test-unit"
15
+
16
+ group :metrics do
17
+ gem "coveralls", "~> 0.7.2"
18
+ gem "simplecov", "~> 0.9.1"
19
+ gem "yardstick", "~> 0.9.9"
20
+ end
21
+
22
+ gemspec :path => "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.3"
6
+ gem "appraisal", "~> 1.0.2"
7
+ gem "rake", "~> 10.3.2"
8
+ gem "yard", "~> 0.8.7"
9
+ gem "sqlite3", "~> 1.3.10", :platforms => :ruby
10
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.10", :platforms => :jruby
11
+ gem "capybara", "~> 2.4.4"
12
+ gem "rspec-rails", "~> 3.1.0"
13
+ gem "rails", "~> 4.1.9"
14
+
15
+ group :metrics do
16
+ gem "coveralls", "~> 0.7.2"
17
+ gem "simplecov", "~> 0.9.1"
18
+ gem "yardstick", "~> 0.9.9"
19
+ end
20
+
21
+ gemspec :path => "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "bundler", "~> 1.3"
6
+ gem "appraisal", "~> 1.0.2"
7
+ gem "rake", "~> 10.3.2"
8
+ gem "yard", "~> 0.8.7"
9
+ gem "sqlite3", "~> 1.3.10", :platforms => :ruby
10
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.10", :platforms => :jruby
11
+ gem "capybara", "~> 2.4.4"
12
+ gem "rspec-rails", "~> 3.1.0"
13
+ gem "rails", "~> 4.2.0"
14
+
15
+ group :metrics do
16
+ gem "coveralls", "~> 0.7.2"
17
+ gem "simplecov", "~> 0.9.1"
18
+ gem "yardstick", "~> 0.9.9"
19
+ end
20
+
21
+ gemspec :path => "../"
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'loaf/configuration'
2
4
  require 'loaf/errors'
3
5
  require 'loaf/railtie'
@@ -13,7 +15,28 @@ require 'loaf/options_validator'
13
15
  I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
14
16
 
15
17
  module Loaf
16
- extend Configuration
18
+ # Set global configuration
19
+ #
20
+ # @api public
21
+ def self.configuration=(config)
22
+ @configuration = config
23
+ end
24
+
25
+ # Get global configuration
26
+ #
27
+ # @api public
28
+ def self.configuration
29
+ @configuration ||= Configuration.new
30
+ end
31
+
32
+ # Sets the Loaf configuration options. Best used by passing a block.
33
+ #
34
+ # Loaf.configure do |config|
35
+ # config.capitalize = true
36
+ # end
37
+ def self.configure
38
+ yield configuration
39
+ end
17
40
 
18
41
  if defined? Rails::Railtie
19
42
  require 'loaf/railtie'