dom_render 0.2.3 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7b47dc68cc997f50c128a0089c1cf9a242f666b6
4
- data.tar.gz: 044f66c0048d94a9f036307781358532fa155bef
2
+ SHA256:
3
+ metadata.gz: e1b8a550981b1641a8219c576237838a4287a9d359450568bdbafe2a817c0bcb
4
+ data.tar.gz: 5b38fc7ad769585477c12b8e459e38799899884a386ac4874a4558587f148141
5
5
  SHA512:
6
- metadata.gz: 257f404542e8bb05dfdd5e19390064f09f51a794bcd4b223cb5b4cedfc6f501a0047e95d6859fa30e55cb9698b84665c480416528aba761e8e14af0da34e458a
7
- data.tar.gz: 0b63f32ee3c28b86c790ae15eba6d1dcb794a5ac2c7dd9101d94e245232477c112b33d1e00a46d9bc0f4466c00547d1d2e0908f720a4ca663fc1a6d71bb985fc
6
+ metadata.gz: 9a62df3febafd99a11dfe1e251645fcfcfb0c481a7768f76bf614547e211d74d52c31b083654d7fe2f3030baa83859f70ac827c13bdba117540c5b2840f4b103
7
+ data.tar.gz: 0f3d40b15a47651cbf5948e12dcfe469e65f485c876dd1435c5df165258383518b9b81ba6f003dcc6d40b2e720f6a12f4a66603799904efffaf267f637464a9c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,12 +4,54 @@
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
+ using ColouredText
47
+
10
48
  attr_reader :to_a
11
49
 
12
- def initialize(x)
50
+ def initialize(x, debug: false)
51
+
52
+ @debug = debug
53
+
54
+ raise "DomRender#initialize: supplied parameter cannot be nil" unless x
13
55
 
14
56
  doc = if x.kind_of? Rexle then
15
57
  x
@@ -17,45 +59,83 @@ class DomRender
17
59
  Rexle.new x.gsub(/\n/,'')
18
60
  end
19
61
 
20
- @to_a = render doc.root
62
+ @a = render doc.root
21
63
  end
22
64
 
23
65
  def render(x)
24
66
 
25
- style = x.attributes.has_key?(:style) ? fetch_style(x.attributes) : {}
26
- args = [x]
27
- args.concat([x.attributes, style])
67
+ puts 'inside render'.info if @debug
28
68
 
29
- r = method(x.name.to_sym).call(*args)
69
+ style = x.attributes.has_key?(:style) ? fetch_style(x.attributes) : {}
70
+ puts 'style: ' + style.inspect if @debug
71
+ puts 'x.name: ' + x.name.to_sym.inspect if @debug
72
+ r = method(x.name.to_sym).call(x, x.attributes.merge(style))
73
+ puts 'r: ' + r.inspect if @debug
30
74
 
31
- if r.last.empty? then
32
- r[0..-2]
33
- else
75
+ return [] unless r and r.length > 0
76
+
77
+ # jr051216 the following statement was commented out because it caused a
78
+ # bug when reading style attributes by exploding the coordinates array
79
+ #if r.last.nil? or r.last.empty? then
80
+ # r[0..-2].flatten(1)
81
+ #else
34
82
  r
35
- end
83
+ #end
36
84
  end
37
85
 
38
86
  def render_all(x)
39
87
 
88
+ puts 'x.children: ' + x.children.inspect if @debug
40
89
  len = x.children.length - 1
41
90
 
42
- x.children.map.with_index do |obj,i|
91
+ r = x.children.map.with_index do |obj,i|
43
92
 
44
93
  if obj.is_a? String then
45
- i == 0 ? obj.lstrip.sub(/\s+$/,' ') : obj.rstrip.sub(/^\s+/,' ')
94
+ if obj.strip.length > 0 then
95
+ i == 0 ? obj.lstrip.sub(/\s+$/,' ') : obj.sub(/^\s+/,' ')
96
+ else
97
+ ''
98
+ end
46
99
  elsif obj.is_a? Rexle::Element
47
- render obj
100
+
101
+ puts 'obj: ' + obj.inspect
102
+ a = render obj
103
+ puts ('_a: ' + a.inspect).debug if @debug
104
+
105
+ a.length > 1 ? a : nil
48
106
  end
49
107
 
50
108
  end
51
109
 
110
+ r.compact
111
+
112
+ end
113
+
114
+ def script(e, attributes)
115
+ []
116
+ end
117
+
118
+ def style(e, attributes)
119
+ []
120
+ end
121
+
122
+ def to_a(inspect: false, verbose: false)
123
+
124
+ #if inspect or verbose then
125
+ # scan @a
126
+ # puts
127
+ #else
128
+ @a
129
+ #end
130
+
52
131
  end
53
132
 
54
133
  private
55
134
 
56
135
  def fetch_style(attributes={})
57
-
58
- attributes[:style].split(';').inject({}) do |r, x|
136
+
137
+ attributes[:style].split(';').inject({}) do |r, x|
138
+
59
139
  k, v = x.split(':',2)
60
140
  r.merge(k.to_sym => v)
61
141
  end
@@ -66,7 +146,7 @@ class DomRender
66
146
  # e.g. "1em 1.5em" #=> ['1em','1.5em','1em','1.5em']
67
147
  #
68
148
  def expand_shorthand(s)
69
-
149
+ puts 'inside expand'
70
150
  a = s.scan(/\d+(?:\.\d+)?\s*(?:em|px)?/)
71
151
 
72
152
  case a.length
@@ -78,6 +158,5 @@ class DomRender
78
158
  end
79
159
 
80
160
  end
81
-
82
-
83
- end
161
+
162
+ end
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.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10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R
24
+ xABhhHoHkpT+00xNelU8G/CHVXvOQS754/RXPRUG/0/lQaa1IMMn3fq1CqECAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU1Y7wazuZ
26
+ oTUcjfACjYNJtPXZZ0YwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAMhe+HKUvLOt3slpK+U7wQLCGxNN8Vcii+uq2bU/A
29
+ ponA/f1onQ5YzR1i33UHmiSHJq4rieZ6dhKOOaO70b3Qpd1EFfES93c4vrbMng7I
30
+ iXZlTPBL98PT9YPs4E48FNdE3Bmrx9vx57faZTebAGIf7hCEkf6vkfoc1npQuX6K
31
+ P/sn12C1kuOYVXFoQ0wwbRKY4ciam8KCOAV3WC/EGPl1G/JmXsPnLGUrpHvETt4i
32
+ HL2xlP90Kl77mtfgc4iJCdK+z1rgy7zCMbDKFXrCiUgRCVnlFh8KSf/pXG4Mj6YZ
33
+ 2E5VIkQRRMeV9Iw++OAuZ3ncGyKWO0ZQ+Fv4+o5ecihcAjHnM4FiRB2xdE04nbT4
34
+ 06O3ljtplA/YNiLVSVIxYGEQk03c48zHE0nvQQLvNErl0fw+P+/OeUCp0oygcurZ
35
+ UOXZAsx7FyG8daWTRpj9raifrl9pxOv/urh3FMd+j0twYVRBesRbBj3LKz7sRI6H
36
+ dDQhWjwG/xapk9uTGle5FfUF
33
37
  -----END CERTIFICATE-----
34
- date: 2015-11-25 00:00:00.000000000 Z
38
+ date: 2020-06-07 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: rexle
@@ -39,22 +43,22 @@ dependencies:
39
43
  requirements:
40
44
  - - "~>"
41
45
  - !ruby/object:Gem::Version
42
- version: '1.3'
46
+ version: '1.5'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 1.3.9
49
+ version: 1.5.6
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
54
  - - "~>"
51
55
  - !ruby/object:Gem::Version
52
- version: '1.3'
56
+ version: '1.5'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 1.3.9
59
+ version: 1.5.6
56
60
  description:
57
- email: james@r0bertson.co.uk
61
+ email: james@jamesrobertson.eu
58
62
  executables: []
59
63
  extensions: []
60
64
  extra_rdoc_files: []
@@ -79,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
83
  - !ruby/object:Gem::Version
80
84
  version: '0'
81
85
  requirements: []
82
- rubyforge_project:
83
- rubygems_version: 2.4.8
86
+ rubygems_version: 3.0.3
84
87
  signing_key:
85
88
  specification_version: 4
86
89
  summary: Designed to render HTML
metadata.gz.sig CHANGED
Binary file