crumpet 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crumpet/controller_additions.rb +13 -6
- data/lib/crumpet/crumb.rb +3 -39
- data/lib/crumpet/renderer.rb +27 -11
- data/lib/crumpet/version.rb +1 -1
- data/lib/crumpet/view_helpers.rb +1 -1
- data/lib/crumpet.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46c020bb8b8fd33ae4e359306880ddf0c37978df
|
4
|
+
data.tar.gz: 39dfcf96365be7747864c1718d66b018d1666799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e57311ee26d89332c8c4d12b5a5b1d63c73c36df1ac501e96b63d3d9a26e56600392f4ec1013c2b53de4e49541d8001ab096b707ade824d52ec89571633226c
|
7
|
+
data.tar.gz: b6366304158073f442de67cdbec8a48001ca2fda0a274a11db2a8d1765d4ecefa4936c1cb67e8b2c873df59aec6c1f6012cf1cb0b2b5834e3c95db973c2d820a
|
@@ -5,11 +5,16 @@ module Crumpet
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def add_crumb(*args)
|
8
|
-
Crumpet.
|
8
|
+
Crumpet.crumbs.add_crumb(*args)
|
9
9
|
end
|
10
10
|
|
11
11
|
def clear_crumbs
|
12
|
-
Crumpet.
|
12
|
+
Crumpet.crumbs.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
def crumbs(&block)
|
16
|
+
yield if block_given?
|
17
|
+
Crumpet.crumbs
|
13
18
|
end
|
14
19
|
|
15
20
|
module ClassMethods
|
@@ -18,11 +23,13 @@ module Crumpet
|
|
18
23
|
end
|
19
24
|
|
20
25
|
def crumbs_for(*args, &block)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
if block_given?
|
27
|
+
options = args.present? ? { only: args } : {}
|
28
|
+
before_action(options) do |instance|
|
29
|
+
instance.instance_exec(:crumbs, &block)
|
30
|
+
end
|
25
31
|
end
|
32
|
+
Crumpet.crumbs
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/lib/crumpet/crumb.rb
CHANGED
@@ -1,49 +1,13 @@
|
|
1
1
|
module Crumpet
|
2
2
|
class Crumb
|
3
|
-
attr_reader :name, :url, :options
|
3
|
+
attr_reader :name, :url, :options, :item_options, :wrapper_options
|
4
4
|
|
5
5
|
def initialize(name, *args)
|
6
6
|
@options = args.extract_options!
|
7
|
+
@item_options = @options.delete(:item_options) || {}
|
8
|
+
@wrapper_options = @options.delete(:wrapper_options) || {}
|
7
9
|
@name = name
|
8
10
|
@url = args.first
|
9
11
|
end
|
10
|
-
|
11
|
-
def link?
|
12
|
-
url.present? && option_or_default(:link).present?
|
13
|
-
end
|
14
|
-
|
15
|
-
def escape?
|
16
|
-
option_or_default(:escape)
|
17
|
-
end
|
18
|
-
|
19
|
-
def truncate?
|
20
|
-
truncate.present?
|
21
|
-
end
|
22
|
-
|
23
|
-
def truncate
|
24
|
-
option_or_default(:truncate)
|
25
|
-
end
|
26
|
-
|
27
|
-
def wrap?
|
28
|
-
wrapper.present?
|
29
|
-
end
|
30
|
-
|
31
|
-
def wrapper
|
32
|
-
option_or_default(:wrapper)
|
33
|
-
end
|
34
|
-
|
35
|
-
def item_options
|
36
|
-
options.fetch(:item_options, {})
|
37
|
-
end
|
38
|
-
|
39
|
-
def wrapper_options
|
40
|
-
options.fetch(:wrapper_options, {})
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def option_or_default(option)
|
46
|
-
options.fetch(option, Crumpet.config.send(option.to_sym).clone)
|
47
|
-
end
|
48
12
|
end
|
49
13
|
end
|
data/lib/crumpet/renderer.rb
CHANGED
@@ -12,15 +12,15 @@ module Crumpet
|
|
12
12
|
def render
|
13
13
|
case option_or_default(:format)
|
14
14
|
when :html
|
15
|
-
output =
|
15
|
+
output = crumbs.map{ |crumb| render_html(crumb) }.join(option_or_default(:separator)).html_safe
|
16
16
|
output = content_tag(option_or_default(:container).to_sym, output, build_container_options) if option_or_default(:container).present?
|
17
17
|
output
|
18
18
|
when :xml
|
19
|
-
output =
|
19
|
+
output = crumbs.map{ |crumb| render_xml(crumb) }.join
|
20
20
|
output = content_tag(:crumbs, output)
|
21
21
|
output
|
22
22
|
when :json
|
23
|
-
|
23
|
+
crumbs.map{ |crumb| render_json(crumb) }.to_json
|
24
24
|
else
|
25
25
|
raise NotImplementedError, "unsupported format: #{option_or_default(:format)}"
|
26
26
|
end
|
@@ -28,8 +28,8 @@ module Crumpet
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
def
|
32
|
-
Crumpet.
|
31
|
+
def crumbs
|
32
|
+
Crumpet.crumbs
|
33
33
|
end
|
34
34
|
|
35
35
|
def render_html(crumb)
|
@@ -38,7 +38,7 @@ module Crumpet
|
|
38
38
|
wrapper_options = build_wrapper_options(crumb)
|
39
39
|
|
40
40
|
output = link?(crumb) ? link_to(name, crumb.url, item_options) : content_tag(:span, name, item_options)
|
41
|
-
output = content_tag(crumb
|
41
|
+
output = content_tag(crumb_option_or_default(crumb, :wrapper), output, wrapper_options) if wrap?(crumb)
|
42
42
|
output
|
43
43
|
end
|
44
44
|
|
@@ -57,8 +57,8 @@ module Crumpet
|
|
57
57
|
|
58
58
|
def render_name(crumb)
|
59
59
|
name = crumb.name
|
60
|
-
name = name.truncate(crumb
|
61
|
-
name = h(name) if
|
60
|
+
name = name.truncate(crumb_option_or_default(crumb, :truncate)) if truncate?(crumb)
|
61
|
+
name = h(name) if escape?(crumb)
|
62
62
|
name.html_safe
|
63
63
|
end
|
64
64
|
|
@@ -71,8 +71,8 @@ module Crumpet
|
|
71
71
|
|
72
72
|
item_options[:class] = Array(item_options.fetch(:class, []))
|
73
73
|
item_options[:class] << option_or_default(:default_crumb_class).presence
|
74
|
-
item_options[:class] << option_or_default(:first_crumb_class).presence if crumb ==
|
75
|
-
item_options[:class] << option_or_default(:last_crumb_class).presence if crumb ==
|
74
|
+
item_options[:class] << option_or_default(:first_crumb_class).presence if crumb == crumbs.first
|
75
|
+
item_options[:class] << option_or_default(:last_crumb_class).presence if crumb == crumbs.last
|
76
76
|
item_options[:class].compact!
|
77
77
|
item_options[:class].uniq!
|
78
78
|
item_options.delete(:class) if item_options[:class].blank?
|
@@ -109,11 +109,27 @@ module Crumpet
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def link?(crumb)
|
112
|
-
|
112
|
+
crumb.url.present? && ( crumb_option_or_default(crumb, :link) && ( option_or_default(:link_last_crumb) || crumb != crumbs.last ) )
|
113
|
+
end
|
114
|
+
|
115
|
+
def truncate?(crumb)
|
116
|
+
crumb_option_or_default(crumb, :truncate)
|
117
|
+
end
|
118
|
+
|
119
|
+
def wrap?(crumb)
|
120
|
+
crumb_option_or_default(crumb, :wrapper).present?
|
121
|
+
end
|
122
|
+
|
123
|
+
def escape?(crumb)
|
124
|
+
crumb_option_or_default(crumb, :escape).present?
|
113
125
|
end
|
114
126
|
|
115
127
|
def option_or_default(option)
|
116
128
|
options.fetch(option, Crumpet.config.send(option.to_sym)).clone
|
117
129
|
end
|
130
|
+
|
131
|
+
def crumb_option_or_default(crumb, option)
|
132
|
+
crumb.options.fetch(option, option_or_default(option))
|
133
|
+
end
|
118
134
|
end
|
119
135
|
end
|
data/lib/crumpet/version.rb
CHANGED
data/lib/crumpet/view_helpers.rb
CHANGED
data/lib/crumpet.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crumpet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Colegate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|