dom_render 0.2.3 → 0.3.0

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: 7b47dc68cc997f50c128a0089c1cf9a242f666b6
4
- data.tar.gz: 044f66c0048d94a9f036307781358532fa155bef
3
+ metadata.gz: 4e7f8c63e3f254085108ed095154892acc6ad684
4
+ data.tar.gz: fa0efd0bf59da50ef3203eb65a8f17487e5a3535
5
5
  SHA512:
6
- metadata.gz: 257f404542e8bb05dfdd5e19390064f09f51a794bcd4b223cb5b4cedfc6f501a0047e95d6859fa30e55cb9698b84665c480416528aba761e8e14af0da34e458a
7
- data.tar.gz: 0b63f32ee3c28b86c790ae15eba6d1dcb794a5ac2c7dd9101d94e245232477c112b33d1e00a46d9bc0f4466c00547d1d2e0908f720a4ca663fc1a6d71bb985fc
6
+ metadata.gz: 61be666908940480bddcc617c073ba00208f28bcb1b74da35db57cdec7ef5f51dc9370b03b749b25218b1e3286f00dd068939ce3b2862c74415dcbb8220f2c56
7
+ data.tar.gz: 3f6b2b2b11a169277d9ddac096b0f6527397e2c59104a6fb1af2ddfed96e4be2978853557abbe8418e444a60035561fb9325b3367f86e0b70f27f6ad5c717869
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/dom_render.rb CHANGED
@@ -4,20 +4,59 @@
4
4
 
5
5
  require 'rexle'
6
6
 
7
+ module InspectArray
8
+
9
+ def scan(a, i=0)
10
+
11
+ if a.first.is_a? Symbol
12
+
13
+ puts a.inspect
14
+
15
+ else
16
+
17
+ puts (' ' * i) + '['
18
+
19
+ a.each.with_index do |row, j|
20
+
21
+ if row.is_a? String or row.is_a? Symbol then
22
+ print (' ' * (i+1)) + row.inspect
23
+ print ',' unless a.length - 1 == j
24
+ puts
25
+ elsif row.first.is_a? Symbol or row.first.is_a? String
26
+ puts (' ' * (i+1)) + '['
27
+ puts (' ' * (i+2)) + row.inspect[1..-2]
28
+ print (' ' * (i+1)) + ']'
29
+ print ',' unless a.length - 1 == j
30
+ puts
31
+ else
32
+ scan(row,i+1)
33
+ print ',' unless a.length - 1 == j
34
+ puts
35
+ end
36
+ end
7
37
 
8
- class DomRender
38
+ print indent = (' ' * i) + ']'
39
+ end
40
+ end
41
+
42
+ end
9
43
 
44
+ class DomRender
45
+ include InspectArray
46
+
10
47
  attr_reader :to_a
11
48
 
12
49
  def initialize(x)
13
50
 
51
+ raise "DomRender#initialize: supplied parameter cannot be nil" unless x
52
+
14
53
  doc = if x.kind_of? Rexle then
15
54
  x
16
55
  else
17
56
  Rexle.new x.gsub(/\n/,'')
18
57
  end
19
58
 
20
- @to_a = render doc.root
59
+ @a = render doc.root
21
60
  end
22
61
 
23
62
  def render(x)
@@ -28,8 +67,10 @@ class DomRender
28
67
 
29
68
  r = method(x.name.to_sym).call(*args)
30
69
 
31
- if r.last.empty? then
32
- r[0..-2]
70
+ return unless r and r.length > 0
71
+
72
+ if r.last.nil? or r.last.empty? then
73
+ r[0..-2].flatten(1)
33
74
  else
34
75
  r
35
76
  end
@@ -39,23 +80,41 @@ class DomRender
39
80
 
40
81
  len = x.children.length - 1
41
82
 
42
- x.children.map.with_index do |obj,i|
83
+ r = x.children.map.with_index do |obj,i|
43
84
 
44
85
  if obj.is_a? String then
45
- i == 0 ? obj.lstrip.sub(/\s+$/,' ') : obj.rstrip.sub(/^\s+/,' ')
86
+ if obj.strip.length > 0 then
87
+ i == 0 ? obj.lstrip.sub(/\s+$/,' ') : obj.sub(/^\s+/,' ')
88
+ else
89
+ ''
90
+ end
46
91
  elsif obj.is_a? Rexle::Element
47
92
  render obj
48
93
  end
49
94
 
50
95
  end
51
96
 
97
+ r.compact
98
+
99
+ end
100
+
101
+ def to_a(inspect: false, verbose: false)
102
+
103
+ if inspect or verbose then
104
+ scan @a
105
+ puts
106
+ else
107
+ @a
108
+ end
109
+
52
110
  end
53
111
 
54
112
  private
55
113
 
56
114
  def fetch_style(attributes={})
57
-
58
- attributes[:style].split(';').inject({}) do |r, x|
115
+
116
+ attributes[:style].split(';').inject({}) do |r, x|
117
+
59
118
  k, v = x.split(':',2)
60
119
  r.merge(k.to_sym => v)
61
120
  end
@@ -78,6 +137,5 @@ class DomRender
78
137
  end
79
138
 
80
139
  end
81
-
82
-
140
+
83
141
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dom_render
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  ipCgMpSHSTGoxQ/dI853bcb+vPkAqS69GEcZgtvAmCQs5E4KC1seYLuP3qtuatL9
32
32
  dbkCMOVMy0htMQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-11-25 00:00:00.000000000 Z
34
+ date: 2015-11-29 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rexle
metadata.gz.sig CHANGED
Binary file