crumbs 1.0.9 → 1.1.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: 23f731609ef462cb58727f9e67be6eac84f2475e
4
- data.tar.gz: 954a7f6708787612add650639e15176c389aea0e
3
+ metadata.gz: d7de3dbbb857eb4469756682e3ad60e55088e4d2
4
+ data.tar.gz: 32c47f6e9baf0c2eea655548ec895832e7d1fca4
5
5
  SHA512:
6
- metadata.gz: 89edb12b5f957aed754ff382564ce7f90f754f63179f53021720ce6615820bb33a39df9ce961b583d41cc49e26c438b4195f9b500a62e64a703f3bebd9e44a08
7
- data.tar.gz: c6b1b02a804178b9e813059873da429532298834a4862667f315d1effd18f43899fa91ad0701bfd1e33621acf3123b33a07caa2f5e031bac531dc31262867595
6
+ metadata.gz: 3863266a5fc2e73132384ed76e07c9b3efb7f515779a8e95351e7ee56e794241940604b6091e14ded0cd17f4461077d92c5fe040829d4d206c2731bebec4fcee
7
+ data.tar.gz: 0954ec6072305b562961214bfbdc747e594d2546d010853da18f3071b4a74307e7ede34c84e4354c3fba0bb53bc851414b3d101391114a32ba3131d332031deb
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 Museways
1
+ Copyright 2014 Museways
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -10,29 +10,30 @@ module Crumbs
10
10
  protected
11
11
 
12
12
  def define_crumbs
13
- update_referers
14
- parts = request.path.split('/')
15
- parts.pop unless Rails.application.config.crumbs.show_last
13
+ paths = [request.path]
14
+ paths.unshift File.dirname(paths.first) until paths.first == '/'
15
+ if referers.empty? or referers.last[:base_url] != request.base_url
16
+ self.referers = [build_referer]
17
+ elsif request.path.starts_with? "#{referers.last[:path]}/".squeeze('/')
18
+ self.referers << build_referer
19
+ elsif index = find_referer_index(paths)
20
+ self.referers = referers[0...index] + [build_referer]
21
+ elsif
22
+ self.referers = [build_referer]
23
+ end
24
+ paths.pop unless Rails.application.config.crumbs.show_last
16
25
  @crumbs = []
17
- while parts.size > 0
18
- if crumb = find_crumb(parts.size == 1 ? '/' : parts.join('/'))
19
- @crumbs << crumb
26
+ paths.each do |path|
27
+ params = Rails.application.routes.recognize_path("#{request.base_url}#{path}") rescue next
28
+ if name = Crumbs::Definitions.find(params[:controller], params[:action], params)
29
+ if index = find_referer_index(path)
30
+ path = referers[index][:fullpath]
31
+ end
32
+ @crumbs << { name: name, path: path }
20
33
  end
21
- parts.pop
22
34
  end
23
- @crumbs.reverse!
24
35
  end
25
36
 
26
- def find_crumb(path)
27
- params = Rails.application.routes.recognize_path(request.base_url + path) rescue return
28
- if name = Crumbs::Definitions.find(params[:controller], params[:action], params)
29
- if index = find_referer_index(path)
30
- path = referers[index][:fullpath]
31
- end
32
- { name: name, path: path }
33
- end
34
- end
35
-
36
37
  def referers
37
38
  session[:referers] ||= []
38
39
  end
@@ -40,22 +41,14 @@ module Crumbs
40
41
  def referers=(value)
41
42
  session[:referers] = value
42
43
  end
43
-
44
- def find_referer_index(path)
45
- referers.index { |referer| referer[:base_url] == request.base_url and referer[:path] == path }
46
- end
47
44
 
48
- def update_referers
49
- if referers.empty? or index = find_referer_index(request.path) or (referers.last[:path].count('/') == 1 ? '/' : request.path[0...request.path.rindex('/')])
50
- if index == 0
51
- self.referers = []
52
- elsif index
53
- self.referers = referers[0...index]
54
- end
55
- referers << { base_url: request.base_url, path: request.path, fullpath: request.fullpath }
56
- else
57
- self.referers = [{ base_url: request.base_url, path: request.path, fullpath: request.fullpath }]
58
- end
45
+ def build_referer
46
+ { base_url: request.base_url, path: request.path, fullpath: request.fullpath }
47
+ end
48
+
49
+ def find_referer_index(paths)
50
+ paths = [paths] unless paths.is_a? Array
51
+ referers.rindex { |referer| paths.include? referer[:path] }
59
52
  end
60
53
 
61
54
  module ClassMethods
@@ -1,5 +1,5 @@
1
1
  module Crumbs
2
2
 
3
- VERSION = '1.0.9'
3
+ VERSION = '1.1.0'
4
4
 
5
5
  end
@@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require "crumbs"
6
+ require 'crumbs'
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
@@ -18,6 +18,6 @@ module Dummy
18
18
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
19
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
20
  # config.i18n.default_locale = :de
21
+ I18n.enforce_available_locales = false
21
22
  end
22
23
  end
23
-