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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/dom_render.rb +68 -10
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7f8c63e3f254085108ed095154892acc6ad684
|
4
|
+
data.tar.gz: fa0efd0bf59da50ef3203eb65a8f17487e5a3535
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
@
|
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
|
-
|
32
|
-
|
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
|
-
|
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.
|
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-
|
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
|