crumbs 1.1.2 → 1.2.0

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: 7f70ae6eeba2b20e9ee261ff06383f9df40b93e0
4
- data.tar.gz: a386fbd54af37f2c1e0cc0d4657848e0e6a224a6
3
+ metadata.gz: 081d368a0f3413cccc92fedb8eeec622b626ee1a
4
+ data.tar.gz: b8f970e0e85570aab1f4cb493c050b0126625bd0
5
5
  SHA512:
6
- metadata.gz: 3930d7d633e0acf5b7fd4076bd78c8aee1499a8578259df8c77726c22d35b07b80bdde6e38e56a3887d4ac0cb3bdd0fca22c07354c343f28957acdc4628beeaa
7
- data.tar.gz: 6ccf8263cab04beaddb7319a1314542b9851473411506041e0a1ba0f8f68a2c3c14c6fc8ee7c35b94c0f6a7bfa653a40de73dbbb742920fda1fd1a706abfeaf2
6
+ metadata.gz: 3f195ea732621d1be2cb8761d978baa3b1227c3581d0ecf7e63a523e28c080750743538882055827355c1f9472d277f070ed3b8274c7b2493d0312281266acbd
7
+ data.tar.gz: 3d91bb86d4a4a38f9d88ea4261c0dc65eecfd64780a741dd9091fb3b607adee49b9ac1b591a046a57c87e46f8d2bda2302dae812f9da549bb93433688677eb8d
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ [![Gem Version](https://badge.fury.io/rb/crumbs.svg)](http://badge.fury.io/rb/crumbs) [![Code Climate](https://codeclimate.com/github/museways/crumbs/badges/gpa.svg)](https://codeclimate.com/github/museways/crumbs) [![Build Status](https://travis-ci.org/museways/crumbs.svg?branch=master)](https://travis-ci.org/museways/crumbs)
2
+
3
+ # Crumbs
4
+
5
+ Adds a handy crumbs variable available in your views in rails.
6
+
7
+ ## Install
8
+
9
+ Put this line in your Gemfile:
10
+ ```ruby
11
+ gem 'crumbs'
12
+ ```
13
+
14
+ Then bundle:
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Generate the configuration file:
22
+ ```
23
+ rails g crumbs:install
24
+ ```
25
+
26
+ The defaults values are:
27
+ ```ruby
28
+ Crumbs.configure do |config|
29
+ config.show_last = false
30
+ end
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ In your controllers add crumbs to the actions you want:
36
+ ```ruby
37
+ crumb :home, 'Home'
38
+ ```
39
+
40
+ You can use a lambda, proc or block too, will receive the corresponding url parameters:
41
+ ```ruby
42
+ crumb :product, proc { |params| Product.find(params[:id]).name }
43
+ ```
44
+
45
+ Then in your views would be available a crumbs variable:
46
+ ```erb
47
+ <% @crumbs.each do |crumb| %>
48
+ &gt; <%= link_to crumb[:name], crumb[:path] %>
49
+ <% end %>
50
+ ```
51
+
52
+ ## Last crumb
53
+
54
+ If you want to show the last crumb, change the default:
55
+ ```ruby
56
+ Crumbs.configure do |config|
57
+ config.crumbs.show_last = true
58
+ end
59
+ ```
60
+
61
+ ## Credits
62
+
63
+ This gem is maintained and funded by [museways](http://museways.com).
64
+
65
+ ## License
66
+
67
+ It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -22,7 +22,7 @@ module Crumbs
22
22
  elsif
23
23
  session[:referers] = [referer]
24
24
  end
25
- paths.pop unless Rails.application.config.crumbs.show_last
25
+ paths.pop unless Crumbs.config.show_last
26
26
  @crumbs = []
27
27
  paths.each do |path|
28
28
  params = Rails.application.routes.recognize_path("#{request.base_url}#{path}") rescue next
@@ -39,17 +39,15 @@ module Crumbs
39
39
  paths = [paths] unless paths.is_a? Array
40
40
  session[:referers].rindex { |referer| paths.include? referer[:path] }
41
41
  end
42
-
42
+
43
43
  module ClassMethods
44
-
44
+
45
45
  protected
46
-
46
+
47
47
  def crumb(action, name=nil, &block)
48
- controller = self.name.gsub('::', '/').gsub('Controller', '').underscore
49
- name = block_given? ? block : name
50
- Crumbs::Definitions.add controller.to_s, action.to_s, name
48
+ Crumbs::Definitions.add controller_path, action.to_s, (block_given? ? block : name)
51
49
  end
52
-
50
+
53
51
  end
54
52
  end
55
53
  end
@@ -1,11 +1,11 @@
1
1
  module Crumbs
2
2
  class Definitions
3
3
  class << self
4
-
4
+
5
5
  def all
6
6
  @all ||= {}
7
7
  end
8
-
8
+
9
9
  def add(controller, action, name)
10
10
  if all.has_key? controller
11
11
  all[controller][action] = name
@@ -13,14 +13,14 @@ module Crumbs
13
13
  all[controller] = { action => name }
14
14
  end
15
15
  end
16
-
16
+
17
17
  def find(controller, action, params)
18
18
  if all.has_key? controller and all[controller].has_key? action
19
19
  name = all[controller][action]
20
20
  name.is_a?(Proc) ? name.call(params) : name
21
21
  end
22
22
  end
23
-
23
+
24
24
  end
25
25
  end
26
26
  end
@@ -1,9 +1,6 @@
1
1
  module Crumbs
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- config.crumbs = ActiveSupport::OrderedOptions.new
5
- config.crumbs.show_last = false
6
-
7
4
  initializer 'crumbs' do
8
5
  ::ActionController::Base.send :include, Crumbs::ActionController::Base
9
6
  end
@@ -1,5 +1,5 @@
1
1
  module Crumbs
2
2
 
3
- VERSION = '1.1.2'
3
+ VERSION = '1.2.0'
4
4
 
5
5
  end
data/lib/crumbs.rb CHANGED
@@ -1,7 +1,21 @@
1
1
  require 'crumbs/action_controller/base'
2
2
  require 'crumbs/definitions'
3
3
  require 'crumbs/railtie'
4
- require 'crumbs/version'
5
4
 
6
5
  module Crumbs
6
+ class << self
7
+
8
+ def configure
9
+ yield config
10
+ end
11
+
12
+ def config
13
+ @config ||= begin
14
+ ActiveSupport::OrderedOptions.new.tap do |config|
15
+ config.show_last = false
16
+ end
17
+ end
18
+ end
19
+
20
+ end
7
21
  end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+
3
+ module Crumbs
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def create_initializer
9
+ copy_file 'crumbs.rb', 'config/initializers/crumbs.rb'
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ Crumbs.configure do |config|
2
+ end