cuba-tools 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cuba-tools.gemspec +1 -1
- data/lib/cuba/tools/widget/base.rb +15 -10
- data/lib/cuba/tools/widget/helpers.rb +9 -3
- data/lib/cuba/tools.rb +1 -0
- data/test/tools/widget_test.rb +6 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dddb504be2eddc1fcc13ab3fd58eb0a713ea24ce
|
4
|
+
data.tar.gz: 90fb4df33375f75721c0a077b833849ab11ac743
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16701025a97e9dcbeaf51d4918eeca22658314dd462cb1bbef2b5ba2ea50742df7607e7846d2964b399ea70fcce9d79451b7cad1cb78a7f9d749fcb5003316c6
|
7
|
+
data.tar.gz: 618fdb605de746a6c1db196218493424c4863e11aa2ae7c2cc8ceb7448d1e766a2bd4625ab410116296329c6bb35ba5dd017d9bbbc1122b6e3dafbc66998105c
|
data/cuba-tools.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "cuba-tools"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.4"
|
8
8
|
spec.authors = ["cj"]
|
9
9
|
spec.email = ["cjlazell@gmail.com"]
|
10
10
|
spec.description = %q{Contains a group of tools to extend cuba}
|
@@ -15,7 +15,7 @@ module Cuba::Tools
|
|
15
15
|
@events = events
|
16
16
|
@widget_state = false
|
17
17
|
|
18
|
-
events.add_observer self, :
|
18
|
+
events.add_observer self, :trigger_event
|
19
19
|
end
|
20
20
|
|
21
21
|
def set_state state
|
@@ -34,12 +34,21 @@ module Cuba::Tools
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def trigger
|
37
|
+
def trigger widget_event, data = {}
|
38
|
+
widget_name = data.delete(:for)
|
39
|
+
|
40
|
+
req.env[:loaded_widgets].each do |n, w|
|
41
|
+
w.trigger_event (widget_name || req.params['widget_name']), widget_event,
|
42
|
+
data.to_deep_ostruct
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def trigger_event widget_name, widget_event, data = {}
|
38
47
|
if class_events = self.class.events
|
39
48
|
class_events.each do |class_event, opts|
|
40
49
|
if class_event.to_s == widget_event.to_s && (
|
41
|
-
|
42
|
-
|
50
|
+
widget_name.to_s == name or
|
51
|
+
opts[:for].to_s == widget_name.to_s
|
43
52
|
)
|
44
53
|
if not opts[:with]
|
45
54
|
e = widget_event
|
@@ -111,23 +120,19 @@ module Cuba::Tools
|
|
111
120
|
end
|
112
121
|
|
113
122
|
def replace state, opts = {}
|
114
|
-
set_state state
|
115
|
-
|
116
123
|
if !state.is_a? String
|
117
124
|
opts[:state] = state
|
118
|
-
content =
|
125
|
+
content = render state, opts
|
119
126
|
selector = '#' + id_for(state)
|
120
127
|
else
|
121
128
|
if !opts.key?(:content) and !opts.key?(:with)
|
122
|
-
content =
|
129
|
+
content = render opts
|
123
130
|
else
|
124
131
|
content = opts[:content] || opts[:with]
|
125
132
|
end
|
126
133
|
selector = state
|
127
134
|
end
|
128
135
|
|
129
|
-
reset_state
|
130
|
-
|
131
136
|
res.write '$("' + selector + '").replaceWith("' + escape(content) + '");'
|
132
137
|
# scroll to the top of the page just as if we went to the url directly
|
133
138
|
# if opts[:scroll_to_top]
|
@@ -7,6 +7,14 @@ module Cuba::Tools
|
|
7
7
|
if path = Widget.config.view_path
|
8
8
|
Dir["#{path}/**/*.rb"].each { |rb| require rb }
|
9
9
|
end
|
10
|
+
|
11
|
+
if defined?(Slim) && defined?(Slim::Engine)
|
12
|
+
Slim::Engine.set_default_options \
|
13
|
+
disable_escape: true,
|
14
|
+
use_html_safe: false,
|
15
|
+
disable_capture: false,
|
16
|
+
pretty: false
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
def method_missing(meth, *args, &block)
|
@@ -30,9 +38,7 @@ module Cuba::Tools
|
|
30
38
|
html = block.call widget
|
31
39
|
|
32
40
|
mab do
|
33
|
-
div(defaults)
|
34
|
-
text! html
|
35
|
-
end
|
41
|
+
div(defaults) { html }
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
data/lib/cuba/tools.rb
CHANGED
data/test/tools/widget_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative '../cutest_helper'
|
2
2
|
require "slim"
|
3
3
|
require "cuba/render"
|
4
|
-
require 'cgi'
|
5
4
|
|
6
5
|
setup do
|
7
6
|
Cuba.reset!
|
@@ -16,6 +15,9 @@ setup do
|
|
16
15
|
Cuba.use Cuba::Tools::Widget::Middleware
|
17
16
|
Cuba.plugin Cuba::Tools::Widget::Helpers
|
18
17
|
Cuba.plugin Cuba::Render
|
18
|
+
Cuba.settings[:render][:options] ||= {
|
19
|
+
default_encoding: Encoding.default_external
|
20
|
+
}
|
19
21
|
Cuba.define do
|
20
22
|
def test_helper
|
21
23
|
'test_helper'
|
@@ -71,7 +73,7 @@ scope "cuba/tools/widget/middleware" do
|
|
71
73
|
'rack.input' => {},
|
72
74
|
'QUERY_STRING' => 'widget_name=some_widget&widget_event=test'
|
73
75
|
})
|
74
|
-
body =
|
76
|
+
body = resp.send('body').join
|
75
77
|
|
76
78
|
assert body[/moo/] != nil
|
77
79
|
assert body[/cow/] != nil
|
@@ -84,19 +86,14 @@ scope "cuba/tools/widget/middleware" do
|
|
84
86
|
'REQUEST_METHOD' => 'GET',
|
85
87
|
'rack.input' => {}
|
86
88
|
})
|
87
|
-
# TODO: figure out why the html isn't decoded properly
|
88
|
-
# body = CGI.unescapeHTML resp.send('body').join
|
89
89
|
body = resp.send('body').join
|
90
90
|
|
91
91
|
assert body['test_helper'] != nil
|
92
92
|
assert body['display'] != nil
|
93
|
-
assert body['some_widget_display'] != nil
|
93
|
+
assert body['id="some_widget_display"'] != nil
|
94
94
|
assert body['some partial'] != nil
|
95
95
|
assert body['some state'] != nil
|
96
96
|
assert body['user_widget_method'] != nil
|
97
|
-
|
98
|
-
# and this is failing
|
99
|
-
# assert body['id="some_widget_some_state"'] != nil
|
100
|
-
assert body['some_widget_some_state'] != nil
|
97
|
+
assert body['id="some_widget_some_state"'] != nil
|
101
98
|
end
|
102
99
|
end
|