gretel 1.0.5 → 1.0.6
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.
- data/lib/gretel/crumbs.rb +9 -12
- data/lib/gretel/helper_methods.rb +6 -6
- data/lib/gretel/parent.rb +3 -3
- metadata +2 -2
data/lib/gretel/crumbs.rb
CHANGED
@@ -20,32 +20,29 @@ module Gretel
|
|
20
20
|
all[name] = block
|
21
21
|
end
|
22
22
|
|
23
|
-
def get_crumb(name,
|
23
|
+
def get_crumb(name, object = nil)
|
24
24
|
raise "Crumb '#{name}' not found." unless all[name]
|
25
25
|
|
26
|
-
@
|
26
|
+
@object = object # share the object so we can call it from link() and parent()
|
27
27
|
@link = nil
|
28
28
|
@parent = nil
|
29
29
|
|
30
|
-
all[name].call(
|
30
|
+
all[name].call(object)
|
31
31
|
Gretel::Crumb.new(@link, @parent)
|
32
32
|
end
|
33
33
|
|
34
34
|
def link(text, url, options = {})
|
35
|
-
text = text.call(
|
36
|
-
url = url.call(
|
35
|
+
text = text.call(@object) if text.is_a?(Proc)
|
36
|
+
url = url.call(@object) if url.is_a?(Proc)
|
37
37
|
|
38
38
|
@link = Gretel::Link.new(text, url, options)
|
39
39
|
end
|
40
40
|
|
41
|
-
def parent(name,
|
42
|
-
name = name.call(
|
41
|
+
def parent(name, object = nil)
|
42
|
+
name = name.call(@object) if name.is_a?(Proc)
|
43
|
+
object = object.call(@object) if object.is_a?(Proc)
|
43
44
|
|
44
|
-
|
45
|
-
params[i] = param.call(&@params) if param.is_a?(Proc)
|
46
|
-
end
|
47
|
-
|
48
|
-
@parent = Gretel::Parent.new(name, *params)
|
45
|
+
@parent = Gretel::Parent.new(name, object)
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -10,14 +10,14 @@ module Gretel
|
|
10
10
|
|
11
11
|
def breadcrumb(*args)
|
12
12
|
options = args.extract_options!
|
13
|
-
name,
|
13
|
+
name, object = args[0], args[1]
|
14
14
|
|
15
15
|
if name
|
16
16
|
@_breadcrumb_name = name
|
17
|
-
@
|
17
|
+
@_breadcrumb_object = object
|
18
18
|
else
|
19
19
|
if @_breadcrumb_name
|
20
|
-
crumb = breadcrumb_for(@_breadcrumb_name,
|
20
|
+
crumb = breadcrumb_for(@_breadcrumb_name, @_breadcrumb_object, options)
|
21
21
|
elsif options[:show_root_alone]
|
22
22
|
crumb = breadcrumb_for(:root, options)
|
23
23
|
end
|
@@ -36,14 +36,14 @@ module Gretel
|
|
36
36
|
options[:link_last] = true
|
37
37
|
separator = (options[:separator] || ">").html_safe
|
38
38
|
|
39
|
-
name,
|
39
|
+
name, object = args[0], args[1]
|
40
40
|
|
41
|
-
crumb = Crumbs.get_crumb(name,
|
41
|
+
crumb = Crumbs.get_crumb(name, object)
|
42
42
|
out = link_to_if(link_last, crumb.link.text, crumb.link.url, crumb.link.options)
|
43
43
|
|
44
44
|
while parent = crumb.parent
|
45
45
|
last_parent = parent.name
|
46
|
-
crumb = Crumbs.get_crumb(parent.name,
|
46
|
+
crumb = Crumbs.get_crumb(parent.name, parent.object)
|
47
47
|
out = link_to(crumb.link.text, crumb.link.url, crumb.link.options) + " " + separator + " " + out
|
48
48
|
end
|
49
49
|
|
data/lib/gretel/parent.rb
CHANGED