roda-component 0.1.2 → 0.1.3

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: 8bcb71e1c19b6a5f891e8b09bf302420e228d002
4
- data.tar.gz: e89514ca3ee82085f2bd873ebd35d3096d067034
3
+ metadata.gz: 5bef9cd915de03f311fd62891aedbfebccd50451
4
+ data.tar.gz: 5480b90c5e44cac8ad05b50e7e1cfe0863e127f3
5
5
  SHA512:
6
- metadata.gz: 6253081b5d4ad072f4ed5c1523888ac6804b6475224cd637fa071f3839d55e0bd013113799ca1cb43378237869792261a18e7c69234ec1369253c8b7af807a21
7
- data.tar.gz: 430473a6561d6912746dd692d2b5ceab95c3cd4ff5dfdfc0233ed4a9f3d2a73db7f4861fea1d6e07080ce59aa6c76a0f9a2731a68abdc04dffa3aeaae6044dc5
6
+ metadata.gz: 1c980094da6effd8e22d4bcbc12a251513cfbdf194c513707eabebad40ae456cc05cf7742dbd8aa11621d1f0d23b8c3543c0cbbc503ae534d9e58d84750b741b
7
+ data.tar.gz: 55bb0afb501e7d3ec17177e19b99398305a2ad6eac0333a861d4b3f2660e256af34e8f4e4a384d4eab1f5bff9fe24793a712143f3c7023e4bbade42ffe511a54
@@ -151,16 +151,16 @@ class Roda
151
151
  end
152
152
 
153
153
  def HTML raw_html
154
- if defined? Oga
155
- Oga.parse_html(raw_html)
156
- elsif defined? Nokogiri
157
- if raw_html[/\A<!DOCTYPE/]
158
- Nokogiri::HTML(raw_html)
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
- Nokogiri::HTML.fragment(raw_html)
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 &block
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].to_xml
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.to_s)
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]
@@ -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(html.dup)
12
+ @dom = Component::HTML(raw_html)
11
13
  else
12
- @dom = html.is_a?(String) ? Element[html.dup] : html
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
- if server?
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
@@ -1,5 +1,5 @@
1
1
  class Roda
2
2
  class Component
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -27,10 +27,12 @@ class ChatComponent < Roda::Component
27
27
  end
28
28
 
29
29
  on :join do |data|
30
- return user_details unless client
31
-
32
- `console.log(#{data});`
33
- puts 'joined'
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|
@@ -16,6 +16,11 @@ class LoginComponent < Roda::Component
16
16
  end
17
17
  end
18
18
 
19
+ def logout
20
+ logout(Models::User)
21
+ request.redirect 'login'
22
+ end
23
+
19
24
  on :server do
20
25
  def login_with params
21
26
  signup = params.delete('signup')
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.2
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-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal