gretel 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gretel/crumbs.rb CHANGED
@@ -21,10 +21,13 @@ module Gretel
21
21
  end
22
22
 
23
23
  def get_crumb(name, object = nil)
24
+ crumb = all[name]
25
+ raise ArgumentError, "Breadcrumb :#{name} not found." unless crumb
26
+
24
27
  @object = object # share the object so we can call it from link() and parent()
25
28
  @parent = nil
26
29
 
27
- all[name].call(object)
30
+ crumb.call(object)
28
31
  Gretel::Crumb.new(@links, @parent)
29
32
  end
30
33
 
@@ -46,14 +46,14 @@ module Gretel
46
46
  while crumb = crumb.parent
47
47
  last_parent = crumb.name
48
48
  crumb = Crumbs.get_crumb(crumb.name, crumb.object)
49
- while link = crumb.links.shift
49
+ while link = crumb.links.pop
50
50
  links.unshift link
51
51
  end
52
52
  end
53
53
 
54
54
  if options[:autoroot] && name != :root && last_parent != :root
55
55
  crumb = Crumbs.get_crumb(:root)
56
- while link = crumb.links.shift
56
+ while link = crumb.links.pop
57
57
  links.unshift link
58
58
  end
59
59
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gretel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lasse Bunk
@@ -32,7 +32,6 @@ files:
32
32
  - lib/gretel/crumb.rb
33
33
  - lib/gretel/crumbs.rb
34
34
  - lib/gretel/helper_methods.rb
35
- - lib/gretel/helper_methods_old.rb
36
35
  - lib/gretel/link.rb
37
36
  - lib/gretel/parent.rb
38
37
  - lib/gretel.rb
@@ -1,90 +0,0 @@
1
- module Gretel
2
- module HelperMethods
3
- include ActionView::Helpers::UrlHelper
4
- def controller # hack because ActionView::Helpers::UrlHelper needs a controller method
5
- end
6
-
7
- def self.included(base)
8
- base.send :helper_method, :breadcrumb_for, :breadcrumb
9
- end
10
-
11
- def breadcrumb(*args)
12
- options = args.extract_options!
13
- name, object = args[0], args[1]
14
-
15
- if name
16
- @_breadcrumb_name = name
17
- @_breadcrumb_object = object
18
- else
19
- if @_breadcrumb_name
20
- crumb = breadcrumb_for(@_breadcrumb_name, @_breadcrumb_object, options)
21
- elsif options[:show_root_alone]
22
- crumb = breadcrumb_for(:root, options)
23
- end
24
- end
25
-
26
- if crumb && options[:pretext]
27
- crumb = options[:pretext].html_safe + " " + crumb
28
- end
29
-
30
- crumb
31
- end
32
-
33
- def breadcrumb_for(*args)
34
- options = args.extract_options!
35
- link_last = options[:link_last]
36
-
37
- name, object = args[0], args[1]
38
-
39
- crumbs = []
40
-
41
- crumb = Crumbs.get_crumb(name, object)
42
- if crumb.links
43
- last_link = crumb.links.pop
44
- #if link_last
45
- # out = out + " " + separator + " " + link_to_if(link_last, last_link.text, last_crumb.link.url, last_crumb.options.merge(:class => "current"))
46
- #else
47
- # if options[:use_microformats]
48
- # out = out + " " + separator + " " + content_tag(:span, last_link.text, :class => "current", :itemprop => "title")
49
- # else
50
- crumbs << content_tag(:span, last_link.text, :class => "current")
51
- # end
52
- #end
53
- end
54
-
55
- last_parent = nil
56
- while parent = crumb.parent
57
- last_parent = parent.name
58
- crumb = Crumbs.get_crumb(parent.name, parent.object)
59
-
60
- if crumb.links
61
- while link = crumb.links.shift
62
- if link
63
- #if options[:use_microformats]
64
- # parents = out + " " + separator + " " + content_tag(:div, link_to(content_tag(:span, link.text, :itemprop => "title"), link.url, link.options.merge(:itemprop => "url")) + " ", :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
65
- #else
66
- crumbs.shift link_to(link.text, link.url, link.options)
67
- #end
68
- end
69
- end
70
- end
71
- end
72
-
73
- # TODO: Refactor this
74
- if options[:autoroot] && name != :root && last_parent != :root
75
- crumb = Crumbs.get_crumb(:root)
76
- if crumb.links
77
- while link = crumb.links.shift
78
- #if options[:use_microformats]
79
- # out = content_tag(:div, link_to(content_tag(:span, link.text, :itemprop => "title"), link.url, link.options.merge(:itemprop => "url")) + " ", :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb") + " " + separator + " " + out
80
- #else
81
- crumbs.unshift link_to(link.text, link.url, link.options)
82
- #end
83
- end
84
- end
85
- end
86
-
87
- crumbs.join(" " + (options[:separator] || "&gt;") + " ").html_safe
88
- end
89
- end
90
- end