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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 263ca392c4f1caf806ddcb5ef3231d93d8b6d45b
4
- data.tar.gz: e09f028bc7c04648cf48faa44b3d11e4ed5aa6c1
3
+ metadata.gz: 5600920b37b6799b8b026fa536b4a292461b3d27
4
+ data.tar.gz: 2de8938a45752ecee763249dba4f219f8ce8002b
5
5
  SHA512:
6
- metadata.gz: b500d7d3cb695aad53c74140291ff10903a2b93724d310b9210bbb9559fd12a1c5ec1df17a18032f714699daa633af977132a8c9cec734b3250b123a36c45d68
7
- data.tar.gz: 7fa4f9ff2792542e2e572256f696162d57d662929317aceea1b68177a3be38fce922d4fc00f0a88426736d145c170c85d4a5a4c6fde0be24c05c7ba0d3681eba
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
- reset_html
47
- @scope = Scope.new instance, doc.search("[data-scope='#{name}']")
46
+ root_doc = doc.search("[data-scope='#{name}']")
47
+ @scope = Scope.new instance, config, root_doc
48
48
 
49
- @scope.root_doc.instance_eval(&block) if block
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
- proc = Proc.new { dom }
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dominate
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/dominate.rb CHANGED
@@ -3,6 +3,7 @@ require "nokogiri-styles"
3
3
  require "tilt"
4
4
  require "dominate/version"
5
5
  require "dominate/inflectors"
6
+ require "dominate/instance"
6
7
  require "dominate/html"
7
8
  require "dominate/scope"
8
9
  require "dominate/dom"
@@ -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
@@ -1,5 +1,5 @@
1
1
  dom.scope(:from_file) do |node|
2
2
  node.each do |n|
3
- n.add_child '<div>added via .dom file</div>'
3
+ n.add_child "<div>added via #{name} file</div>"
4
4
  end
5
5
  end
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.1
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