loaf 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.document +5 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +28 -0
  5. data/.travis.yml +4 -0
  6. data/CHANGELOG.md +8 -0
  7. data/Gemfile.lock +132 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +128 -0
  10. data/Rakefile +2 -45
  11. data/init.rb +3 -0
  12. data/lib/loaf.rb +14 -8
  13. data/lib/loaf/configuration.rb +2 -0
  14. data/lib/loaf/{filters.rb → controller_extensions.rb} +13 -12
  15. data/lib/loaf/crumb.rb +6 -0
  16. data/lib/loaf/crumb_formatter.rb +20 -0
  17. data/lib/loaf/railtie.rb +15 -6
  18. data/lib/loaf/translation.rb +18 -9
  19. data/lib/loaf/version.rb +4 -2
  20. data/lib/loaf/view_extensions.rb +43 -0
  21. data/loaf.gemspec +28 -0
  22. data/spec/integration/configuration_spec.rb +13 -0
  23. data/spec/integration/crumbs_routing_spec.rb +33 -0
  24. data/spec/integration/nested_crumbs_spec.rb +5 -0
  25. data/spec/loaf/crumb_formatter_spec.rb +33 -0
  26. data/spec/loaf/translation_spec.rb +23 -0
  27. data/spec/loaf_spec.rb +5 -0
  28. data/spec/rails_app/.gitignore +5 -0
  29. data/spec/rails_app/Rakefile +8 -0
  30. data/spec/rails_app/app/assets/images/rails.png +0 -0
  31. data/spec/rails_app/app/assets/javascripts/application.js +9 -0
  32. data/spec/rails_app/app/assets/stylesheets/application.css +7 -0
  33. data/spec/rails_app/app/controllers/application_controller.rb +5 -0
  34. data/spec/rails_app/app/controllers/comments_controller.rb +4 -0
  35. data/spec/rails_app/app/controllers/home_controller.rb +4 -0
  36. data/spec/rails_app/app/controllers/posts_controller.rb +12 -0
  37. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  38. data/spec/rails_app/app/mailers/.gitkeep +0 -0
  39. data/spec/rails_app/app/models/.gitkeep +0 -0
  40. data/spec/rails_app/app/views/home/index.html.erb +1 -0
  41. data/spec/rails_app/app/views/layouts/_breadcrumbs.html.erb +8 -0
  42. data/spec/rails_app/app/views/layouts/application.html.erb +16 -0
  43. data/spec/rails_app/app/views/posts/index.html.erb +1 -0
  44. data/spec/rails_app/app/views/posts/new.html.erb +1 -0
  45. data/spec/rails_app/config.ru +4 -0
  46. data/spec/rails_app/config/application.rb +48 -0
  47. data/spec/rails_app/config/boot.rb +10 -0
  48. data/spec/rails_app/config/database.yml +25 -0
  49. data/spec/rails_app/config/environment.rb +5 -0
  50. data/spec/rails_app/config/environments/development.rb +30 -0
  51. data/spec/rails_app/config/environments/production.rb +60 -0
  52. data/spec/rails_app/config/environments/test.rb +42 -0
  53. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  55. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  56. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  57. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  58. data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
  59. data/spec/rails_app/config/locales/en.yml +5 -0
  60. data/spec/rails_app/config/routes.rb +9 -0
  61. data/spec/rails_app/db/seeds.rb +7 -0
  62. data/spec/rails_app/lib/assets/.gitkeep +0 -0
  63. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  64. data/spec/rails_app/public/404.html +26 -0
  65. data/spec/rails_app/public/422.html +26 -0
  66. data/spec/rails_app/public/500.html +26 -0
  67. data/spec/rails_app/public/favicon.ico +0 -0
  68. data/spec/rails_app/public/robots.txt +5 -0
  69. data/spec/rails_app/script/rails +6 -0
  70. data/spec/spec_helper.rb +15 -0
  71. data/spec/support/capybara.rb +10 -0
  72. data/spec/support/load_routes.rb +6 -0
  73. metadata +202 -119
  74. data/README.rdoc +0 -71
  75. data/lib/loaf/helpers.rb +0 -49
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ coverage
2
+ rdoc
3
+ doc
4
+ .yardoc
5
+ .bundle
6
+ pkg
7
+ *.swp
8
+ log
9
+ *.sqlite3
10
+ .bundle
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+
3
+ environment_id="ruby-1.9.3-p0@loaf"
4
+
5
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
6
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
7
+ then
8
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
9
+
10
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
11
+ then
12
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
13
+ fi
14
+ else
15
+ # If the environment file has not yet been created, use the RVM CLI to select.
16
+ if ! rvm --create "$environment_id"
17
+ then
18
+ echo "Failed to create RVM environment '${environment_id}'."
19
+ return 1
20
+ fi
21
+ fi
22
+
23
+ if [[ $- == *i* ]] # check for interactive shells
24
+ then
25
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
26
+ else
27
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
28
+ fi
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ script: 'rake'
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ 0.2.0 (February , 2012)
2
+
3
+ * Change gemspec with new gem dependencies, use git
4
+ * Setup testing environment with dummy rails app
5
+ * Add integration tests for breadcrumbs view rendering
6
+ * Add translation module for breadcrumbs title lookup
7
+ * Add breadcrumb formatting module with tests
8
+ * Refactor names for controller and view extensions
data/Gemfile.lock ADDED
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ loaf (0.1.1)
5
+ rails
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.1.3)
11
+ actionpack (= 3.1.3)
12
+ mail (~> 2.3.0)
13
+ actionpack (3.1.3)
14
+ activemodel (= 3.1.3)
15
+ activesupport (= 3.1.3)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.5)
20
+ rack-cache (~> 1.1)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.3)
24
+ activemodel (3.1.3)
25
+ activesupport (= 3.1.3)
26
+ builder (~> 3.0.0)
27
+ i18n (~> 0.6)
28
+ activerecord (3.1.3)
29
+ activemodel (= 3.1.3)
30
+ activesupport (= 3.1.3)
31
+ arel (~> 2.2.1)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.1.3)
34
+ activemodel (= 3.1.3)
35
+ activesupport (= 3.1.3)
36
+ activesupport (3.1.3)
37
+ multi_json (~> 1.0)
38
+ arel (2.2.1)
39
+ builder (3.0.0)
40
+ capybara (1.1.2)
41
+ mime-types (>= 1.16)
42
+ nokogiri (>= 1.3.3)
43
+ rack (>= 1.0.0)
44
+ rack-test (>= 0.5.4)
45
+ selenium-webdriver (~> 2.0)
46
+ xpath (~> 0.1.4)
47
+ childprocess (0.2.3)
48
+ ffi (~> 1.0.6)
49
+ diff-lcs (1.1.3)
50
+ erubis (2.7.0)
51
+ ffi (1.0.11)
52
+ hike (1.2.1)
53
+ i18n (0.6.0)
54
+ json (1.6.3)
55
+ mail (2.3.0)
56
+ i18n (>= 0.4.0)
57
+ mime-types (~> 1.16)
58
+ treetop (~> 1.4.8)
59
+ mime-types (1.17.2)
60
+ multi_json (1.0.4)
61
+ nokogiri (1.5.0)
62
+ polyglot (0.3.3)
63
+ rack (1.3.5)
64
+ rack-cache (1.1)
65
+ rack (>= 0.4)
66
+ rack-mount (0.8.3)
67
+ rack (>= 1.0.0)
68
+ rack-ssl (1.3.2)
69
+ rack
70
+ rack-test (0.6.1)
71
+ rack (>= 1.0)
72
+ rails (3.1.3)
73
+ actionmailer (= 3.1.3)
74
+ actionpack (= 3.1.3)
75
+ activerecord (= 3.1.3)
76
+ activeresource (= 3.1.3)
77
+ activesupport (= 3.1.3)
78
+ bundler (~> 1.0)
79
+ railties (= 3.1.3)
80
+ railties (3.1.3)
81
+ actionpack (= 3.1.3)
82
+ activesupport (= 3.1.3)
83
+ rack-ssl (~> 1.3.2)
84
+ rake (>= 0.8.7)
85
+ rdoc (~> 3.4)
86
+ thor (~> 0.14.6)
87
+ rake (0.9.2.2)
88
+ rdoc (3.12)
89
+ json (~> 1.4)
90
+ rspec (2.7.0)
91
+ rspec-core (~> 2.7.0)
92
+ rspec-expectations (~> 2.7.0)
93
+ rspec-mocks (~> 2.7.0)
94
+ rspec-core (2.7.1)
95
+ rspec-expectations (2.7.0)
96
+ diff-lcs (~> 1.1.2)
97
+ rspec-mocks (2.7.0)
98
+ rspec-rails (2.7.0)
99
+ actionpack (~> 3.0)
100
+ activesupport (~> 3.0)
101
+ railties (~> 3.0)
102
+ rspec (~> 2.7.0)
103
+ rubyzip (0.9.5)
104
+ selenium-webdriver (2.15.0)
105
+ childprocess (>= 0.2.1)
106
+ ffi (~> 1.0.9)
107
+ multi_json (~> 1.0.4)
108
+ rubyzip
109
+ sprockets (2.0.3)
110
+ hike (~> 1.2)
111
+ rack (~> 1.0)
112
+ tilt (~> 1.1, != 1.3.0)
113
+ sqlite3 (1.3.5)
114
+ thor (0.14.6)
115
+ tilt (1.3.3)
116
+ treetop (1.4.10)
117
+ polyglot
118
+ polyglot (>= 0.3.1)
119
+ tzinfo (0.3.31)
120
+ xpath (0.1.4)
121
+ nokogiri (~> 1.3)
122
+
123
+ PLATFORMS
124
+ ruby
125
+
126
+ DEPENDENCIES
127
+ bundler
128
+ capybara
129
+ loaf!
130
+ rails (~> 3.1)
131
+ rspec-rails
132
+ sqlite3
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Piotr Murach
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,128 @@
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
+
3
+ [travis]: http://travis-ci.org/peter-murach/loaf
4
+ [gemnasium]: https://gemnasium.com/peter-murach/loaf
5
+
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.
12
+
13
+ ## Installation
14
+
15
+ Install from source:
16
+
17
+ ```ruby
18
+ gem install loaf
19
+ ```
20
+
21
+ Add to your Gemfile:
22
+
23
+ ```ruby
24
+ gem 'loaf'
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ There is a small set of custom opinionated defaults. The following options are valid parameters:
30
+
31
+ ```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'
37
+ ```
38
+
39
+ You can override them in your views by passing them to the view `breadcrumb` helper
40
+
41
+ ```ruby
42
+ <% breadcrumbs :crumb_length => 20 do |name, url, styles| %>
43
+ ..
44
+ <% end %>
45
+ ```
46
+
47
+ or by adding initializer
48
+
49
+ ```ruby
50
+ Loaf.configure do |config|
51
+ config.crumb_length => 20
52
+ end
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ In controller:
58
+
59
+ ```ruby
60
+ class Blog::CategoriesController < ApplicationController
61
+
62
+ add_breadcrumb 'Article Categories', 'blog_categories_path', :only => [:show]
63
+
64
+ def show
65
+ add_breadcrumb "#{@category.title}", 'blog_category_path(@category)'
66
+ end
67
+ end
68
+ ```
69
+
70
+ You can add breadcrumbs for nested resources, for instance, article categories:
71
+
72
+ In your view add semantic markup to show breadcrumbs:
73
+
74
+ ```html
75
+ <ul id="breadcrumbs">
76
+ <%- breadcrumbs :crumb_length => 20 do |name, url, styles| -%>
77
+ <li class="<%= styles %>">
78
+ <%= link_to name, url %>
79
+ <span><%= styles == 'selected' ? '' : '::' %></span>
80
+ </li>
81
+ <%- end -%>
82
+ </ul>
83
+ ```
84
+
85
+ Usually best practice is to put such snippet inside its own partial.
86
+
87
+ ## Locale
88
+
89
+ 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
+
91
+ ```ruby
92
+ en:
93
+ breadcrumbs:
94
+ controller:
95
+ action:
96
+ ```
97
+
98
+ Therefore in your controller/view one would have
99
+
100
+ ```ruby
101
+ class Blog::CategoriesController < ApplicationController
102
+
103
+ add_breadcrumb 'blog.categories', 'blog_categories_path'
104
+
105
+ end
106
+
107
+ And corresponding entry in locale:
108
+
109
+ en:
110
+ breadcrumbs:
111
+ blog:
112
+ categories: 'Article Categories'
113
+ ```
114
+
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
122
+
123
+ 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
+
125
+ ## Copyright
126
+
127
+ Copyright (c) 2011 Piotr Murach. See LICENSE.txt for
128
+ further details.
data/Rakefile CHANGED
@@ -1,51 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- require './lib/loaf/version.rb'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "loaf"
19
- gem.homepage = "http://github.com/peter-murach/loaf"
20
- gem.license = "MIT"
21
- gem.summary = %Q{TODO: one-line summary of your gem}
22
- gem.description = %Q{TODO: longer description of your gem}
23
- gem.email = "pmurach@gmail.com"
24
- gem.authors = ["Piotr Murach"]
25
- gem.version = Loaf::Version::STRING
26
- # dependencies defined in Gemfile
27
- end
28
- Jeweler::RubygemsDotOrgTasks.new
29
-
30
- require 'rspec/core'
3
+ require 'bundler/gem_tasks'
31
4
  require 'rspec/core/rake_task'
32
- RSpec::Core::RakeTask.new(:spec) do |spec|
33
- spec.pattern = FileList['spec/**/*_spec.rb']
34
- end
35
5
 
36
- RSpec::Core::RakeTask.new(:rcov) do |spec|
37
- spec.pattern = 'spec/**/*_spec.rb'
38
- spec.rcov = true
39
- end
6
+ RSpec::Core::RakeTask.new(:spec)
40
7
 
41
8
  task :default => :spec
42
-
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
45
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
-
47
- rdoc.rdoc_dir = 'rdoc'
48
- rdoc.title = "loaf #{version}"
49
- rdoc.rdoc_files.include('README*')
50
- rdoc.rdoc_files.include('lib/**/*.rb')
51
- end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'loaf'
2
+ require 'loaf/railtie'
3
+ Loaf::Railtie.insert
data/lib/loaf.rb CHANGED
@@ -1,16 +1,22 @@
1
- require 'action_controller'
2
1
  require 'loaf/configuration'
2
+ require 'loaf/railtie'
3
+ require 'loaf/crumb'
4
+ require 'loaf/builder'
5
+ require 'loaf/translation'
6
+ require 'loaf/controller_extensions'
7
+ require 'loaf/view_extensions'
8
+ require 'loaf/crumb_formatter'
3
9
 
4
10
  module Loaf
11
+ extend Configuration
12
+
5
13
  if defined? Rails::Railtie
6
14
  require 'loaf/railtie'
7
15
  else
8
- autoload :Filters, 'loaf/filters'
9
- autoload :Helpers, 'loaf/helpers'
16
+ autoload :ControllerExtensions, 'loaf/controller_extensions'
17
+ autoload :Helpers, 'loaf/view_extensions'
10
18
 
11
- ::ActionController::Base.send :include, Loaf::Filters
12
- ::ActionController::Base.helper Loaf::Helpers
19
+ ::ActionController::Base.send :include, Loaf::ControllerExtensions
20
+ ::ActionController::Base.helper Loaf::ViewExtensions
13
21
  end
14
-
15
- extend Configuration
16
- end
22
+ end # Loaf
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Loaf
2
4
  module Configuration
3
5