gretel 1.1.5 → 1.1.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 +5 -1
- data/lib/gretel/helper_methods.rb +75 -40
- data/lib/gretel/view_link.rb +13 -0
- data/lib/gretel.rb +1 -0
- metadata +4 -3
data/lib/gretel/crumbs.rb
CHANGED
@@ -31,7 +31,11 @@ module Gretel
|
|
31
31
|
Gretel::Crumb.new(@links, @parent)
|
32
32
|
end
|
33
33
|
|
34
|
-
def link(
|
34
|
+
def link(*args)
|
35
|
+
options = args.extract_options!
|
36
|
+
text = args[0]
|
37
|
+
url = args[1]
|
38
|
+
|
35
39
|
text = text.call(@object) if text.is_a?(Proc)
|
36
40
|
url = url.call(@object) if url.is_a?(Proc)
|
37
41
|
|
@@ -5,7 +5,7 @@ module Gretel
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.included(base)
|
8
|
-
base.send :helper_method, :
|
8
|
+
base.send :helper_method, :breadcrumbs, :breadcrumb
|
9
9
|
end
|
10
10
|
|
11
11
|
def breadcrumb(*args)
|
@@ -23,69 +23,104 @@ module Gretel
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
if crumb
|
27
|
-
|
26
|
+
if crumb
|
27
|
+
if options[:pretext]
|
28
|
+
crumb = options[:pretext].html_safe + crumb
|
29
|
+
end
|
30
|
+
if options[:posttext]
|
31
|
+
crumb = crumb + options[:posttext].html_safe
|
32
|
+
end
|
28
33
|
end
|
29
34
|
|
30
35
|
crumb
|
31
36
|
end
|
32
37
|
|
33
|
-
def
|
38
|
+
def breadcrumbs(*args)
|
34
39
|
options = args.extract_options!
|
35
|
-
link_last = options[:link_last]
|
36
|
-
|
37
|
-
name, object = args[0], args[1]
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
links.unshift link
|
44
|
-
end
|
45
|
-
|
46
|
-
while crumb = crumb.parent
|
47
|
-
last_parent = crumb.name
|
48
|
-
crumb = Crumbs.get_crumb(crumb.name, crumb.object)
|
41
|
+
if @_breadcrumb_name
|
42
|
+
links = []
|
43
|
+
|
44
|
+
crumb = Crumbs.get_crumb(@_breadcrumb_name, @_breadcrumb_object)
|
49
45
|
while link = crumb.links.pop
|
50
|
-
links.unshift link
|
46
|
+
links.unshift ViewLink.new(link.text, link.url, link.options)
|
51
47
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
48
|
+
|
49
|
+
while crumb = crumb.parent
|
50
|
+
last_parent = crumb.name
|
51
|
+
crumb = Crumbs.get_crumb(crumb.name, crumb.object)
|
52
|
+
while link = crumb.links.pop
|
53
|
+
links.unshift ViewLink.new(link.text, link.url, link.options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if options[:autoroot] && @_breadcrumb_name != :root && last_parent != :root
|
58
|
+
crumb = Crumbs.get_crumb(:root)
|
59
|
+
while link = crumb.links.pop
|
60
|
+
links.unshift ViewLink.new(link.text, link.url, link.options)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
current_link = links.pop
|
65
|
+
|
66
|
+
out = []
|
67
|
+
while link = links.shift
|
68
|
+
out << ViewLink.new(link.text, link.url, link.options)
|
58
69
|
end
|
70
|
+
|
71
|
+
if current_link
|
72
|
+
out << ViewLink.new(current_link.text, current_link.url, current_link.options, true)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
out = []
|
59
76
|
end
|
77
|
+
|
78
|
+
out
|
79
|
+
end
|
80
|
+
|
81
|
+
def breadcrumb_for(*args)
|
82
|
+
options = args.extract_options!
|
83
|
+
name, object = args[0], args[1]
|
84
|
+
|
85
|
+
links = breadcrumbs(name, object, options)
|
60
86
|
|
61
|
-
|
87
|
+
current_link = links.pop
|
62
88
|
|
63
89
|
out = []
|
64
90
|
while link = links.shift
|
65
|
-
|
66
|
-
|
91
|
+
out << get_crumb(link.text, link.url, options[:semantic], nil, link.options)
|
92
|
+
end
|
93
|
+
|
94
|
+
if current_link
|
95
|
+
if options[:link_last] || options[:link_current]
|
96
|
+
out << get_crumb(current_link.text, current_link.url, options[:semantic], "current", current_link.options)
|
67
97
|
else
|
68
|
-
out <<
|
98
|
+
out << get_crumb(current_link.text, nil, options[:semantic], "current")
|
69
99
|
end
|
70
100
|
end
|
71
101
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
102
|
+
out.join(options[:separator] || " > ").html_safe
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_crumb(text, url, semantic, css_class, options = {})
|
106
|
+
if url.blank?
|
107
|
+
if semantic
|
108
|
+
content_tag(:div, content_tag(:span, text, :class => css_class, :itemprop => "title"), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
|
79
109
|
else
|
80
|
-
if
|
81
|
-
|
110
|
+
if css_class
|
111
|
+
content_tag(:span, text, :class => css_class)
|
82
112
|
else
|
83
|
-
|
113
|
+
text
|
84
114
|
end
|
85
115
|
end
|
116
|
+
else
|
117
|
+
options.merge! :class => (options[:class] ? options[:class] + " " : "") + css_class if css_class
|
118
|
+
if semantic
|
119
|
+
content_tag(:div, link_to(content_tag(:span, text, :itemprop => "title"), url, options.merge(:itemprop => "url")), :itemscope => "", :itemtype => "http://data-vocabulary.org/Breadcrumb")
|
120
|
+
else
|
121
|
+
link_to(text, url, options)
|
122
|
+
end
|
86
123
|
end
|
87
|
-
|
88
|
-
out.join(" " + (options[:separator] || ">") + " ").html_safe
|
89
124
|
end
|
90
125
|
end
|
91
126
|
end
|
data/lib/gretel.rb
CHANGED
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:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 6
|
10
|
+
version: 1.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lasse Bunk
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/gretel/helper_methods.rb
|
35
35
|
- lib/gretel/link.rb
|
36
36
|
- lib/gretel/parent.rb
|
37
|
+
- lib/gretel/view_link.rb
|
37
38
|
- lib/gretel.rb
|
38
39
|
homepage: http://github.com/lassebunk/gretel
|
39
40
|
licenses: []
|