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 +4 -4
- data/lib/dominate/dom.rb +13 -3
- data/lib/dominate/version.rb +1 -1
- data/test/dominate_test.rb +1 -0
- data/test/dummy/app.slim +3 -0
- data/test/dummy/index.html +23 -25
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 027d7683d6936a5b2288d2385c123c521b50e762
|
4
|
+
data.tar.gz: 2a714a9548917eee30ab5a64cbc1a16acb0180fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
6
|
-
|
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
|
-
|
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]
|
data/lib/dominate/version.rb
CHANGED
data/test/dominate_test.rb
CHANGED
data/test/dummy/app.slim
ADDED
data/test/dummy/index.html
CHANGED
@@ -1,28 +1,26 @@
|
|
1
|
-
|
2
|
-
<
|
3
|
-
|
1
|
+
<!-- @partial header -->
|
2
|
+
<span>This should not show</span>
|
3
|
+
<!-- /partial header -->
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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.
|
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
|