dominate 0.1.9 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d5d37eabfd65d6bd519003486b87e4ac7ea4bf6
4
- data.tar.gz: dfae5d88ed94082bd23a32aa495aaf34fe44a653
3
+ metadata.gz: 05dda3c35e6592183e3cb60ee94882fea9424cd6
4
+ data.tar.gz: 4311505c6d7c4a933edf55cbd53e9c20fa97a3b5
5
5
  SHA512:
6
- metadata.gz: 68a11c463f8915f524ad5231468b6a27415243a72992b6acad30a2588b7a92908c6f91d581f3ea25058b2d3ec10a0e8d944e968574920a1a5662bb4141b5174a
7
- data.tar.gz: b040316b0a2fbffce11e2ad04be543830e824893130857bef19149fa425bc57a0dd4f119953ce9b61cfc8b7d545e73aacb70123a24a548b2f1c41710ba16ebaa
6
+ metadata.gz: a2b56d19ccffeaf822ba92c2f5b717dee7b29df5c18feade071c97b1fcfbcf973986b32cf7a4a7d96863c1dbe9dbc5d263cdc47af47af1c80a9b20ed7ceb8a70
7
+ data.tar.gz: 6a83e8f870993cff4a7808fa1930caa645238d87903eb70e73c02a30f225b5675b591cefacf29c63f734412d4d6511dda34cd853265ae6e028530074a146c823
data/lib/dominate/dom.rb CHANGED
@@ -42,9 +42,13 @@ module Dominate
42
42
  set_doc html.gsub YIELD_REGEX, inner_html
43
43
  end
44
44
 
45
- def scope name
45
+ def scope name, &block
46
46
  reset_html
47
- Scope.new instance, doc.search("[data-scope='#{name}']")
47
+ @scope = Scope.new instance, doc.search("[data-scope='#{name}']")
48
+
49
+ @scope.root_doc.instance_eval(&block) if block
50
+
51
+ self
48
52
  end
49
53
 
50
54
  def html
@@ -54,6 +58,12 @@ module Dominate
54
58
  end
55
59
  end
56
60
 
61
+ def apply data, &block
62
+ @scope.apply data, &block
63
+
64
+ self
65
+ end
66
+
57
67
  def apply_instance
58
68
  reset_html
59
69
  Scope.new(instance, doc).apply_instance
data/lib/dominate/html.rb CHANGED
@@ -6,8 +6,16 @@ module Dominate
6
6
 
7
7
  def file file, instance = false, config = {}
8
8
  c = (Dominate.config.to_h.merge config).to_deep_ostruct
9
- html = load "#{c.view_path}/#{file}"
10
- Dom.new html, instance, config
9
+ path = "#{c.view_path}/#{file}"
10
+ html = load path
11
+ dom = Dom.new html, instance, config
12
+
13
+ if File.file? path + '.dom'
14
+ proc = Proc.new { dom }
15
+ dom = eval(File.read(path + '.dom'), proc.binding)
16
+ end
17
+
18
+ dom
11
19
  end
12
20
 
13
21
  def load path
@@ -1,3 +1,3 @@
1
1
  module Dominate
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -49,7 +49,7 @@ scope 'dominate' do
49
49
  end
50
50
 
51
51
  test 'blocks' do |a|
52
- a.dom.scope(:admin_only).each do |node|
52
+ a.dom.scope(:admin_only) do |node|
53
53
  unless a.current_user.admin
54
54
  node.remove
55
55
  end
@@ -111,5 +111,6 @@ scope 'dominate' do
111
111
  end
112
112
 
113
113
  assert dom.html['#000']
114
+ assert dom.html['added via .dom file']
114
115
  end
115
116
  end
@@ -0,0 +1,5 @@
1
+ dom.scope(:from_file) do |node|
2
+ node.each do |n|
3
+ n.add_child '<div>added via .dom file</div>'
4
+ end
5
+ end
data/test/dummy/flat.slim CHANGED
@@ -1,2 +1,4 @@
1
- ul data-scope='flat'
2
- li data-prop='capitalize'
1
+ .container
2
+ ul data-scope='flat'
3
+ li data-prop='capitalize'
4
+ .from-file data-scope='from_file'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dominate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-02 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -157,6 +157,7 @@ files:
157
157
  - lib/dominate/version.rb
158
158
  - test/dominate_test.rb
159
159
  - test/dummy/app.slim
160
+ - test/dummy/flat.dom
160
161
  - test/dummy/flat.slim
161
162
  - test/dummy/footer.slim
162
163
  - test/dummy/header.html
@@ -189,6 +190,7 @@ summary: Templating Engine.
189
190
  test_files:
190
191
  - test/dominate_test.rb
191
192
  - test/dummy/app.slim
193
+ - test/dummy/flat.dom
192
194
  - test/dummy/flat.slim
193
195
  - test/dummy/footer.slim
194
196
  - test/dummy/header.html