roda-component 0.1.2 → 0.1.3
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/lib/roda/component.rb +12 -11
- data/lib/roda/component/dom.rb +9 -20
- data/lib/roda/component/version.rb +1 -1
- data/test/dummy/components/chat.rb +6 -4
- data/test/dummy/components/login.rb +5 -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: 5bef9cd915de03f311fd62891aedbfebccd50451
|
4
|
+
data.tar.gz: 5480b90c5e44cac8ad05b50e7e1cfe0863e127f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c980094da6effd8e22d4bcbc12a251513cfbdf194c513707eabebad40ae456cc05cf7742dbd8aa11621d1f0d23b8c3543c0cbbc503ae534d9e58d84750b741b
|
7
|
+
data.tar.gz: 55bb0afb501e7d3ec17177e19b99398305a2ad6eac0333a861d4b3f2660e256af34e8f4e4a384d4eab1f5bff9fe24793a712143f3c7023e4bbade42ffe511a54
|
data/lib/roda/component.rb
CHANGED
@@ -151,16 +151,16 @@ class Roda
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def HTML raw_html
|
154
|
-
if
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
154
|
+
if raw_html[/\A<!DOCTYPE/] || raw_html[/\A<html/]
|
155
|
+
Nokogiri::HTML(raw_html)
|
156
|
+
else
|
157
|
+
parsed_html = Nokogiri::HTML.fragment(raw_html)
|
158
|
+
|
159
|
+
if parsed_html.children.length == 1
|
160
|
+
parsed_html.children.first
|
159
161
|
else
|
160
|
-
|
162
|
+
parsed_html
|
161
163
|
end
|
162
|
-
else
|
163
|
-
warn 'No HTML parsing lib loaded. Please require Nokogiri or Oga'
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -177,7 +177,7 @@ class Roda
|
|
177
177
|
if args.first.to_s != 'server'
|
178
178
|
events.on(*args, &block)
|
179
179
|
else
|
180
|
-
on_server
|
180
|
+
on_server(&block)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
@@ -206,7 +206,7 @@ class Roda
|
|
206
206
|
# the reason we ave the raw html is so that we can use it client side.
|
207
207
|
def tmpl name, dom, remove = true
|
208
208
|
cache[:tmpl][name] = { dom: remove ? dom.remove : dom }
|
209
|
-
cache[:tmpl][name][:html] = cache[:tmpl][name][:dom].
|
209
|
+
cache[:tmpl][name][:html] = cache[:tmpl][name][:dom].to_html
|
210
210
|
cache[:tmpl][name]
|
211
211
|
end
|
212
212
|
alias :add_tmpl :tmpl
|
@@ -251,7 +251,7 @@ class Roda
|
|
251
251
|
def dom
|
252
252
|
if server?
|
253
253
|
# TODO: duplicate cache[:dom] so we don't need to parse all the html again
|
254
|
-
@_dom ||= DOM.new(cache[:dom].dom.
|
254
|
+
@_dom ||= DOM.new(cache[:dom].dom.to_html)
|
255
255
|
else
|
256
256
|
@_dom ||= DOM.new(Element)
|
257
257
|
end
|
@@ -260,6 +260,7 @@ class Roda
|
|
260
260
|
|
261
261
|
# Grab the template from the cache, use the nokogiri dom or create a
|
262
262
|
# jquery element for server side
|
263
|
+
# issue: can't use the cached dom because duping doesn't work.
|
263
264
|
def tmpl name
|
264
265
|
if t = cache[:tmpl][name]
|
265
266
|
DOM.new t[:html]
|
data/lib/roda/component/dom.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
class Roda
|
2
4
|
class Component
|
3
|
-
class DOM
|
5
|
+
class DOM < SimpleDelegator
|
4
6
|
attr_accessor :dom, :raw_html
|
5
7
|
|
6
8
|
def initialize html
|
7
|
-
@raw_html = html
|
9
|
+
@raw_html = html.dup
|
8
10
|
|
9
11
|
if server?
|
10
|
-
@dom = Component::HTML(
|
12
|
+
@dom = Component::HTML(raw_html)
|
11
13
|
else
|
12
|
-
@dom =
|
14
|
+
@dom = raw_html.is_a?(String) ? Element[raw_html] : raw_html
|
13
15
|
end
|
16
|
+
|
17
|
+
super dom
|
14
18
|
end
|
15
19
|
|
16
20
|
def find string, &block
|
@@ -34,11 +38,7 @@ class Roda
|
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
|
-
|
38
|
-
self
|
39
|
-
else
|
40
|
-
node
|
41
|
-
end
|
41
|
+
node
|
42
42
|
end
|
43
43
|
|
44
44
|
def html= content
|
@@ -67,17 +67,6 @@ class Roda
|
|
67
67
|
@node || dom
|
68
68
|
end
|
69
69
|
|
70
|
-
# This allows you to use all the nokogiri or opal jquery methods if a
|
71
|
-
# global one isn't set
|
72
|
-
def method_missing method, *args, &block
|
73
|
-
# respond_to?(symbol, include_all=false)
|
74
|
-
if dom.respond_to? method, true
|
75
|
-
dom.send method, *args, &block
|
76
|
-
else
|
77
|
-
super
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
70
|
private
|
82
71
|
|
83
72
|
def server? &block
|
@@ -27,10 +27,12 @@ class ChatComponent < Roda::Component
|
|
27
27
|
end
|
28
28
|
|
29
29
|
on :join do |data|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
if client?
|
31
|
+
`console.log(#{data});`
|
32
|
+
puts 'joined'
|
33
|
+
else
|
34
|
+
user_details
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
on :leave do |data|
|
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.3
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|