dominate 0.1.5 → 0.1.6
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 +4 -4
- data/lib/dominate/dom.rb +4 -21
- data/lib/dominate/html.rb +29 -0
- data/lib/dominate/version.rb +1 -1
- data/lib/dominate.rb +5 -4
- data/test/dominate_test.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a7bcd918c55a4b1bc2182aa3af2d1c99815e86f
|
4
|
+
data.tar.gz: 70a234db125eef1641b0eead1332eb009a3f1e79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2272c1f3a61ede1f6c123370a339d21b1f515d3f5472978690e295da235378ae43c3d407500b3fa572ba8a644de641efc43099be93eea3799ed6183518744738
|
7
|
+
data.tar.gz: 09003081a2758df05c5c268379a5fd23194b403089165cebf98c3f4164957235ecf8f4886f3f7f75b7308a66936a0d08777ad5d7b9f4454dd663fa7c4833b327
|
data/lib/dominate/dom.rb
CHANGED
@@ -5,7 +5,6 @@ module Dominate
|
|
5
5
|
YIELD_REGEX = /<!--(?:\s*|)@yield(?:\s*|)-->/
|
6
6
|
PARTIAL_REGEX = /<!--(?:\s*|)@partial(?:\s*|)([a-zA-Z0-9\-_]*)(?:\s*|)-->/
|
7
7
|
PARTIAL_REGEX_WITHIN = /<!--(?:\s*|)@partial(?:\s*|)([a-zA-Z0-9\-_]*)(?:\s*|)-->(.*?)<!--(?:\s*|)\/partial(?:\s*|)([a-zA-Z0-9\-_]*)(?:\s*|)-->/m
|
8
|
-
VIEW_TYPES = %w(html slim haml erb md markdown mkd mab)
|
9
8
|
|
10
9
|
def initialize raw_html, instance = false, config = {}
|
11
10
|
@raw_html = raw_html
|
@@ -22,7 +21,7 @@ module Dominate
|
|
22
21
|
updated_html = doc.inner_html.gsub(PARTIAL_REGEX_WITHIN) do |m|
|
23
22
|
match = m.strip.match(PARTIAL_REGEX)
|
24
23
|
partial = match[1]
|
25
|
-
|
24
|
+
HTML.load "#{view_path}/#{partial}"
|
26
25
|
end
|
27
26
|
|
28
27
|
set_doc updated_html if updated_html
|
@@ -31,14 +30,14 @@ module Dominate
|
|
31
30
|
if match = e.to_html.strip.match(PARTIAL_REGEX)
|
32
31
|
partial = match[1]
|
33
32
|
e.swap Nokogiri::HTML.fragment(
|
34
|
-
|
33
|
+
HTML.load "#{view_path}/#{partial}"
|
35
34
|
)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
39
|
def load_layout
|
41
|
-
html =
|
40
|
+
html = HTML.load config.layout
|
42
41
|
inner_html = doc.inner_html
|
43
42
|
set_doc html.gsub YIELD_REGEX, inner_html
|
44
43
|
end
|
@@ -76,23 +75,7 @@ module Dominate
|
|
76
75
|
end
|
77
76
|
|
78
77
|
def view_path
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
def load_view path
|
83
|
-
html = false
|
84
|
-
|
85
|
-
VIEW_TYPES.each do |type|
|
86
|
-
file = "#{path}.#{type}"
|
87
|
-
|
88
|
-
if File.file? file
|
89
|
-
template = Tilt.new file
|
90
|
-
html = template.render
|
91
|
-
break
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
html
|
78
|
+
config.view_path
|
96
79
|
end
|
97
80
|
end
|
98
81
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Dominate
|
2
|
+
module HTML
|
3
|
+
extend self
|
4
|
+
|
5
|
+
VIEW_TYPES = %w(html slim haml erb md markdown mkd mab)
|
6
|
+
|
7
|
+
def file file, instance = false, config = {}
|
8
|
+
c = (Dominate.config.to_h.merge config).to_deep_ostruct
|
9
|
+
html = load "#{c.view_path}/#{file}"
|
10
|
+
Dom.new html, instance, config
|
11
|
+
end
|
12
|
+
|
13
|
+
def load path
|
14
|
+
html = false
|
15
|
+
|
16
|
+
VIEW_TYPES.each do |type|
|
17
|
+
file = "#{path}.#{type}"
|
18
|
+
|
19
|
+
if File.file? file
|
20
|
+
template = Tilt.new file
|
21
|
+
html = template.render
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
html
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/dominate/version.rb
CHANGED
data/lib/dominate.rb
CHANGED
@@ -2,6 +2,7 @@ require "nokogiri"
|
|
2
2
|
require "tilt"
|
3
3
|
require "dominate/version"
|
4
4
|
require "dominate/inflectors"
|
5
|
+
require "dominate/html"
|
5
6
|
require "dominate/scope"
|
6
7
|
require "dominate/dom"
|
7
8
|
|
@@ -10,10 +11,6 @@ module Dominate
|
|
10
11
|
|
11
12
|
attr_accessor :config, :reset_config
|
12
13
|
|
13
|
-
def HTML html, instance = false, data = {}
|
14
|
-
Dom.new html, instance, data
|
15
|
-
end
|
16
|
-
|
17
14
|
def setup
|
18
15
|
yield config
|
19
16
|
end
|
@@ -26,4 +23,8 @@ module Dominate
|
|
26
23
|
def reset_config!
|
27
24
|
@config = OpenStruct.new
|
28
25
|
end
|
26
|
+
|
27
|
+
def HTML html, instance = false, options = {}
|
28
|
+
Dom.new html, instance, options
|
29
|
+
end
|
29
30
|
end
|
data/test/dominate_test.rb
CHANGED
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.
|
4
|
+
version: 0.1.6
|
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-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- dominate.gemspec
|
138
138
|
- lib/dominate.rb
|
139
139
|
- lib/dominate/dom.rb
|
140
|
+
- lib/dominate/html.rb
|
140
141
|
- lib/dominate/inflectors.rb
|
141
142
|
- lib/dominate/scope.rb
|
142
143
|
- lib/dominate/version.rb
|