roda-component 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/Makefile +2 -1
- data/lib/roda/component.rb +4 -4
- data/lib/roda/component/version.rb +1 -1
- data/lib/roda/plugins/component.rb +18 -15
- data/test/dummy/app.rb +3 -3
- data/test/dummy/components/chat.rb +7 -5
- data/test/dummy/components/layout.rb +0 -1
- data/test/dummy/dummy.db +0 -0
- 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: 8bcb71e1c19b6a5f891e8b09bf302420e228d002
|
4
|
+
data.tar.gz: e89514ca3ee82085f2bd873ebd35d3096d067034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6253081b5d4ad072f4ed5c1523888ac6804b6475224cd637fa071f3839d55e0bd013113799ca1cb43378237869792261a18e7c69234ec1369253c8b7af807a21
|
7
|
+
data.tar.gz: 430473a6561d6912746dd692d2b5ceab95c3cd4ff5dfdfc0233ed4a9f3d2a73db7f4861fea1d6e07080ce59aa6c76a0f9a2731a68abdc04dffa3aeaae6044dc5
|
data/Makefile
CHANGED
@@ -21,7 +21,8 @@ install:
|
|
21
21
|
|
22
22
|
server:
|
23
23
|
bundle
|
24
|
-
cd test/dummy && touch dummy.db && rm dummy.db && bundle exec thin start -p 8080
|
24
|
+
# cd test/dummy && touch dummy.db && rm dummy.db && bundle exec thin start -p 8080
|
25
|
+
cd test/dummy && touch dummy.db && bundle exec thin start -p 8080
|
25
26
|
|
26
27
|
test:
|
27
28
|
bundle exec pry-test --async
|
data/lib/roda/component.rb
CHANGED
@@ -214,10 +214,10 @@ class Roda
|
|
214
214
|
|
215
215
|
# shortcut to comp opts
|
216
216
|
def component_opts
|
217
|
-
if
|
218
|
-
app.component_opts
|
219
|
-
else
|
217
|
+
if client?
|
220
218
|
$component_opts
|
219
|
+
else
|
220
|
+
super
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -292,7 +292,7 @@ class Roda
|
|
292
292
|
alias_method :server, :server?
|
293
293
|
|
294
294
|
def client?
|
295
|
-
|
295
|
+
RUBY_ENGINE == 'opal'
|
296
296
|
end
|
297
297
|
alias_method :client, :client?
|
298
298
|
end
|
@@ -55,7 +55,11 @@ class Roda
|
|
55
55
|
|
56
56
|
module InstanceMethods
|
57
57
|
def component_opts
|
58
|
-
self.class.component_opts
|
58
|
+
@_component_opts || self.class.component_opts.dup
|
59
|
+
end
|
60
|
+
|
61
|
+
def loaded_component_js
|
62
|
+
request.env['loaded_component_js'] ||= []
|
59
63
|
end
|
60
64
|
|
61
65
|
def load_component name
|
@@ -91,7 +95,7 @@ class Roda
|
|
91
95
|
end
|
92
96
|
EOF
|
93
97
|
|
94
|
-
("<script>" + Opal.compile(js) + "</script>")
|
98
|
+
loaded_component_js << ("<script>" + Opal.compile(js) + "</script>")
|
95
99
|
end
|
96
100
|
|
97
101
|
def component name, options = {}, &block
|
@@ -118,25 +122,24 @@ class Roda
|
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
121
|
-
|
122
|
-
if comp_response.is_a? Roda::Component::DOM
|
123
|
-
content = comp_response.to_xml
|
124
|
-
else
|
125
|
-
content = comp_response
|
126
|
-
end
|
125
|
+
load_component_js comp, action
|
127
126
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
127
|
+
if comp_response.is_a? Roda::Component::DOM
|
128
|
+
comp_response = comp_response.to_xml
|
129
|
+
end
|
132
130
|
|
133
|
-
|
134
|
-
|
135
|
-
comp_response
|
131
|
+
if comp_response.is_a?(String) && js = options.delete(:js)
|
132
|
+
comp_response << component_js
|
136
133
|
end
|
134
|
+
|
135
|
+
comp_response
|
137
136
|
end
|
138
137
|
alias :comp :component
|
139
138
|
alias :roda_component :component
|
139
|
+
|
140
|
+
def component_js
|
141
|
+
loaded_component_js.join('\n').to_s
|
142
|
+
end
|
140
143
|
end
|
141
144
|
|
142
145
|
module ClassMethods
|
data/test/dummy/app.rb
CHANGED
@@ -78,10 +78,10 @@ class TestApp < Roda
|
|
78
78
|
r.run Rack::Directory.new("#{path}/../public/chat/font-awesome-4.1.0/fonts")
|
79
79
|
end
|
80
80
|
|
81
|
-
r.root { component(:chat) }
|
81
|
+
r.root { component(:chat, js: true) }
|
82
82
|
|
83
|
-
r.on('login') { component(:login) }
|
84
|
-
r.on('logout') { component(:login, call: :logout) }
|
83
|
+
r.on('login') { component(:login, js: true) }
|
84
|
+
r.on('logout') { component(:login, call: :logout, js: true) }
|
85
85
|
|
86
86
|
r.on 'session/:key/:value' do |key, value|
|
87
87
|
session[key] = value
|
@@ -27,17 +27,19 @@ class ChatComponent < Roda::Component
|
|
27
27
|
end
|
28
28
|
|
29
29
|
on :join do |data|
|
30
|
-
return user_details unless client
|
30
|
+
return user_details unless client
|
31
31
|
|
32
32
|
`console.log(#{data});`
|
33
33
|
puts 'joined'
|
34
34
|
end
|
35
35
|
|
36
36
|
on :leave do |data|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
if client?
|
38
|
+
`console.log(#{data});`
|
39
|
+
puts 'leave'
|
40
|
+
else
|
41
|
+
user_details
|
42
|
+
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def user_details
|
data/test/dummy/dummy.db
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda-component
|
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
|
- cj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|