dominate 0.1.5 → 0.1.6

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: 93f5b699571918d5a7f4a599d84f7d324ff88ef1
4
- data.tar.gz: a3bdcd9fd5ac1dd6145888d03958ebd4334166f0
3
+ metadata.gz: 8a7bcd918c55a4b1bc2182aa3af2d1c99815e86f
4
+ data.tar.gz: 70a234db125eef1641b0eead1332eb009a3f1e79
5
5
  SHA512:
6
- metadata.gz: 543d051c51e00fd274bc4cc4c331737aa22dc26889963e63763fde5ac7c9ba3609d2e8bb02ead32275b187c5954d8732ede7ad2d3b42de469f1d00cde6d23a7a
7
- data.tar.gz: c7809e76967b223dc8f1d0fb78ae2ec2b2178e3cce14ca6962606ece132feafaa4a732f4624cfa9e5a23e81b4eff77592505d29c07086378ed3000fc77df852b
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
- load_view "#{view_path}/#{partial}"
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
- load_view "#{view_path}/#{partial}"
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 = load_view config.layout
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
- Dominate.config.view_path
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
@@ -1,3 +1,3 @@
1
1
  module Dominate
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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
@@ -88,4 +88,9 @@ scope 'dominate' do
88
88
  assert a.dom.html['app layout']
89
89
  assert a.dom.html.scan(/body/).length == 2
90
90
  end
91
+
92
+ test 'file' do
93
+ dom = Dominate::HTML.file 'index'
94
+ assert dom.html['data-scope']
95
+ end
91
96
  end
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.5
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-01 00:00:00.000000000 Z
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