roda-component 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 215bb6602958dc06a8502a62335096657a0850c3
4
- data.tar.gz: b4371617ad7f91ed5e77f2aa359ce97f3f4526b4
3
+ metadata.gz: 8bcb71e1c19b6a5f891e8b09bf302420e228d002
4
+ data.tar.gz: e89514ca3ee82085f2bd873ebd35d3096d067034
5
5
  SHA512:
6
- metadata.gz: 9c93adfa28fff329aeda042c96cecdda13275eb5adb842040cf378d82aea9a2961f972cbae996c908a99182431fe19242628dbcc6199c32614f4d174c4e51b0f
7
- data.tar.gz: 0a0816a7b3eb6f3f554be124073e7bc8d3dd5eb9e271562b305d7435d2e6ef3bcdd9b3d6cd749aacb74ddb9b6eaaa8080ae7631299fc2d4af17f1e81ec45b0fd
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
@@ -214,10 +214,10 @@ class Roda
214
214
 
215
215
  # shortcut to comp opts
216
216
  def component_opts
217
- if server?
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
- !server?
295
+ RUBY_ENGINE == 'opal'
296
296
  end
297
297
  alias_method :client, :client?
298
298
  end
@@ -1,5 +1,5 @@
1
1
  class Roda
2
2
  class Component
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  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
- if request && !request.env['RODA_COMPONENT_FROM_FAYE']
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
- unless request.env.include? 'HTTP_X_RODA_COMPONENT_ON_SERVER'
129
- content = content.to_s
130
- content += load_component_js comp, action
131
- end
127
+ if comp_response.is_a? Roda::Component::DOM
128
+ comp_response = comp_response.to_xml
129
+ end
132
130
 
133
- content
134
- else
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
- return user_details unless client?
38
-
39
- `console.log(#{data});`
40
- puts 'leave'
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
@@ -11,7 +11,6 @@ class LayoutComp < Roda::Component
11
11
  <script type="text/javascript" src="/assets/components"></script>
12
12
  <script type="text/javascript" src="/faye/client.js"></script>
13
13
  EOF
14
-
15
14
  end
16
15
 
17
16
  def display data, &block
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.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-13 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal