dominate 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: 94e99ad536f854bdb002dc3616eedacb5181e478
4
- data.tar.gz: 371127d9331c6c85ed5447868c00642d38e2dece
3
+ metadata.gz: 027d7683d6936a5b2288d2385c123c521b50e762
4
+ data.tar.gz: 2a714a9548917eee30ab5a64cbc1a16acb0180fa
5
5
  SHA512:
6
- metadata.gz: 15e58c2904a7c493f7195995cfac87e1cbcd590a088a2f33ec0801f4cc7a118de0d349a0def8221f621ca648d898b6812b420e0860cd541137d2e8abd36eb542
7
- data.tar.gz: cd353c41c3c81b7698550e838dbffdf59b17acf432826911f72ce236de8e8ab101778886dd13cc3ab10993765c6fb20aef5034fccd6f356e21c33d888ae252d9
6
+ metadata.gz: 0bdd687486a08e26a29815b5a7c519c30a1b75874b6ab8306eebbb2009ae2b2505f805e3f3448a3255061845613f9fe48d74377ab532e0c1ba6a62f3dfe979c9
7
+ data.tar.gz: 10c1329d9c4a36da9c375d16cf6aa9b264210a6ec41ebab4f96446529936d10fb3983d66836f7f0e66dbb66756874d3cac08dcbe98187aae7c22f3c8a34c623a
data/lib/dominate/dom.rb CHANGED
@@ -2,8 +2,9 @@ module Dominate
2
2
  class Dom
3
3
  attr_accessor :raw_html, :instance, :doc
4
4
 
5
- PARTIAL_REGEX = /<!--\s*@partial\s*([a-zA-Z0-9\-_]*)\s*-->/
6
- VIEW_TYPES = %w(html slim haml erb)
5
+ PARTIAL_REGEX = /<!--(?:\s*|)@partial(?:\s*|)([a-zA-Z0-9\-_]*)(?:\s*|)-->/
6
+ PARTIAL_REGEX_WITHIN =/<!--(?:\s*|)@partial(?:\s*|)([a-zA-Z0-9\-_]*)(?:\s*|)-->(.*?)<!--(?:\s*|)\/partial(?:\s*|)([a-zA-Z0-9\-_]*)(?:\s*|)-->/m
7
+ VIEW_TYPES = %w(html slim haml erb md markdown mkd mab)
7
8
 
8
9
  def initialize raw_html, instance = false
9
10
  @raw_html = raw_html
@@ -12,13 +13,22 @@ module Dominate
12
13
  if raw_html.match(/<html.*>/)
13
14
  @doc = Nokogiri::HTML::Document.parse raw_html
14
15
  else
15
- @doc = Nokogiri::HTML.fragment raw_html
16
+ # need to wrap it in a div to make sure it has a root
17
+ @doc = Nokogiri::HTML.fragment "<div>#{raw_html}</div>"
16
18
  end
17
19
 
18
20
  load_partials if Dominate.config.view_path
19
21
  end
20
22
 
21
23
  def load_partials
24
+ updated_html = doc.inner_html.gsub(PARTIAL_REGEX_WITHIN) do |m|
25
+ match = m.strip.match(PARTIAL_REGEX)
26
+ partial = match[1]
27
+ load_view "#{view_path}/#{partial}"
28
+ end
29
+
30
+ doc.inner_html = updated_html if updated_html
31
+
22
32
  doc.traverse do |e|
23
33
  if match = e.to_html.strip.match(PARTIAL_REGEX)
24
34
  partial = match[1]
@@ -1,3 +1,3 @@
1
1
  module Dominate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -78,5 +78,6 @@ scope 'dominate' do
78
78
 
79
79
  a.dom.scope(:footer).apply data
80
80
  assert a.dom.html['Test Company']
81
+ assert a.dom.html['This should not show'] == nil
81
82
  end
82
83
  end
@@ -0,0 +1,3 @@
1
+ html
2
+ body
3
+ /! @content
@@ -1,28 +1,26 @@
1
- <html>
2
- <body>
3
- <!-- @partial header -->
1
+ <!-- @partial header -->
2
+ <span>This should not show</span>
3
+ <!-- /partial header -->
4
4
 
5
- <div>
6
- <h1 data-scope='admin_only'>Admin</h1>
7
- <span>current_user:
8
- <span data-instance="current_user.first_name">John</span>
9
- <span data-instance="current_user.last_name">Doe</span>
10
- </span>
11
- </div>
12
- <ul data-scope="list">
13
- <li>
14
- <a href="#" data-prop="todo">test</a>
15
- </li>
16
- <li>
17
- <a href="#" data-prop="todo">testing</a>
18
- </li>
19
- <li>
20
- <ul data-scope="list-nested">
21
- <li data-prop="todo"></li>
22
- </ul>
23
- </li>
5
+ <div>
6
+ <h1 data-scope='admin_only'>Admin</h1>
7
+ <span>current_user:
8
+ <span data-instance="current_user.first_name">John</span>
9
+ <span data-instance="current_user.last_name">Doe</span>
10
+ </span>
11
+ </div>
12
+ <ul data-scope="list">
13
+ <li>
14
+ <a href="#" data-prop="todo">test</a>
15
+ </li>
16
+ <li>
17
+ <a href="#" data-prop="todo">testing</a>
18
+ </li>
19
+ <li>
20
+ <ul data-scope="list-nested">
21
+ <li data-prop="todo"></li>
24
22
  </ul>
23
+ </li>
24
+ </ul>
25
25
 
26
- <!-- @partial footer -->
27
- </body>
28
- </html>
26
+ <!-- @partial footer -->
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
@@ -141,6 +141,7 @@ files:
141
141
  - lib/dominate/scope.rb
142
142
  - lib/dominate/version.rb
143
143
  - test/dominate_test.rb
144
+ - test/dummy/app.slim
144
145
  - test/dummy/footer.slim
145
146
  - test/dummy/header.html
146
147
  - test/dummy/index.html
@@ -171,6 +172,7 @@ specification_version: 4
171
172
  summary: Templating Engine.
172
173
  test_files:
173
174
  - test/dominate_test.rb
175
+ - test/dummy/app.slim
174
176
  - test/dummy/footer.slim
175
177
  - test/dummy/header.html
176
178
  - test/dummy/index.html