dominate 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dominate/dom.rb +4 -4
- data/lib/dominate/html.rb +1 -2
- data/lib/dominate/instance.rb +13 -0
- data/lib/dominate/scope.rb +4 -4
- data/lib/dominate/version.rb +1 -1
- data/lib/dominate.rb +1 -0
- data/test/dominate_test.rb +2 -2
- data/test/dummy/flat.dom +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5600920b37b6799b8b026fa536b4a292461b3d27
|
4
|
+
data.tar.gz: 2de8938a45752ecee763249dba4f219f8ce8002b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1fad8e73677983c7e365e32ebae730ab5bd07380a1d778abd6cf8c56380eb2cac832757ca1f5de3975a0be68235898f708e14dda1103682a34ee89b035ff5bb
|
7
|
+
data.tar.gz: 4afc8ea69b29be8dca0eb010c7a8e333ed59680dbd8b6a237a28e608fd88c859948c68778903dba27a618d319da3c94cf5b98d5f9150e3333491747d7480df1c
|
data/lib/dominate/dom.rb
CHANGED
@@ -43,10 +43,10 @@ module Dominate
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def scope name, &block
|
46
|
-
|
47
|
-
@scope
|
46
|
+
root_doc = doc.search("[data-scope='#{name}']")
|
47
|
+
@scope = Scope.new instance, config, root_doc
|
48
48
|
|
49
|
-
|
49
|
+
Instance.new(instance, config).instance_exec(root_doc, &block) if block
|
50
50
|
|
51
51
|
self
|
52
52
|
end
|
@@ -66,7 +66,7 @@ module Dominate
|
|
66
66
|
|
67
67
|
def apply_instance
|
68
68
|
reset_html
|
69
|
-
Scope.new(instance, doc).apply_instance
|
69
|
+
Scope.new(instance, config, doc).apply_instance
|
70
70
|
end
|
71
71
|
|
72
72
|
private
|
data/lib/dominate/html.rb
CHANGED
@@ -11,8 +11,7 @@ module Dominate
|
|
11
11
|
dom = Dom.new html, instance, config
|
12
12
|
|
13
13
|
if File.file? path + '.dom'
|
14
|
-
|
15
|
-
dom = instance.instance_eval File.read(path + '.dom')
|
14
|
+
dom = Instance.new(instance, c).instance_eval File.read(path + '.dom')
|
16
15
|
end
|
17
16
|
|
18
17
|
dom
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Dominate
|
2
|
+
class Instance < Struct.new(:instance, :config)
|
3
|
+
def method_missing method, *args, &block
|
4
|
+
if config.respond_to? method
|
5
|
+
config.send method
|
6
|
+
elsif instance.respond_to? method
|
7
|
+
instance.send method
|
8
|
+
else
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/dominate/scope.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Dominate
|
2
|
-
class Scope < Struct.new :instance, :root_doc
|
2
|
+
class Scope < Struct.new :instance, :config, :root_doc
|
3
3
|
|
4
4
|
def apply data, &block
|
5
5
|
root_doc.each do |doc|
|
@@ -100,11 +100,11 @@ module Dominate
|
|
100
100
|
def value_for value, data, elem
|
101
101
|
if value.is_a? Proc
|
102
102
|
if value.parameters.length == 0
|
103
|
-
instance.instance_exec(&value).to_s
|
103
|
+
Instance.new(instance, config).instance_exec(&value).to_s
|
104
104
|
elsif value.parameters.length == 1
|
105
|
-
instance.instance_exec(data, &value).to_s
|
105
|
+
Instance.new(instance, config).instance_exec(data, &value).to_s
|
106
106
|
elsif value.parameters.length == 2
|
107
|
-
instance.instance_exec(data, elem, &value).to_s
|
107
|
+
Instance.new(instance, config).instance_exec(data, elem, &value).to_s
|
108
108
|
end
|
109
109
|
else
|
110
110
|
value.to_s
|
data/lib/dominate/version.rb
CHANGED
data/lib/dominate.rb
CHANGED
data/test/dominate_test.rb
CHANGED
@@ -95,14 +95,14 @@ scope 'dominate' do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
test 'flat' do
|
98
|
-
dom = Dominate::HTML.file 'flat'
|
98
|
+
dom = Dominate::HTML.file 'flat', false, name: '.dom'
|
99
99
|
dom.scope(:flat).apply ['moo', 'cow']
|
100
100
|
assert dom.html['Moo']
|
101
101
|
assert dom.html['Cow']
|
102
102
|
end
|
103
103
|
|
104
104
|
test 'styles' do
|
105
|
-
dom = Dominate::HTML.file 'flat'
|
105
|
+
dom = Dominate::HTML.file 'flat', false, name: '.dom'
|
106
106
|
|
107
107
|
dom.scope(:flat).apply ['moo', 'cow'] do |node|
|
108
108
|
styles = node.styles
|
data/test/dummy/flat.dom
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dominate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/dominate/dom.rb
|
154
154
|
- lib/dominate/html.rb
|
155
155
|
- lib/dominate/inflectors.rb
|
156
|
+
- lib/dominate/instance.rb
|
156
157
|
- lib/dominate/scope.rb
|
157
158
|
- lib/dominate/version.rb
|
158
159
|
- test/dominate_test.rb
|