gtk2html 0.2.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: 2c71c9bf3bcd28dc51ea164bda94b482e0ce3ee7
4
- data.tar.gz: 1a42d43901620e37f640e58af6bf6f3a813214b1
3
+ metadata.gz: c3c83b7cc3a743e07cb251e5cd12f1ec77726c1d
4
+ data.tar.gz: 7ef2fe8b12107278ac1a120dfe8752b47d05bdf9
5
5
  SHA512:
6
- metadata.gz: b5d3685e45170d735b58133c936684e42257f6008f0184f041d73f9eb7a90187f805001252d282cb04867f3e3142e7f80625942672130c3f3f6e05ae818d3e6b
7
- data.tar.gz: 3caf8a98e72ec960d47f137afc8414710d4bc40a9d2e139f1cf0010dec7338c3e188975598a2c15c1da6a554f741ad42af33e4839296c2706bdd3317592896f0
6
+ metadata.gz: abea0a4c76a50eefd65095c0fb0b9c1803456a939fae247a87f2300337d251a1c158ec6fc87770da9fb81eff42f9ebf5793f7a62747d8e9774ca024af5fd7026
7
+ data.tar.gz: 28b09a3d12a556e3b299b3f2c354822f22667b68672f8ae31b6d40053807a3d825086be785277e5c9c5e3c3ec6f7aa0ff7cf232140941719b447f968c492943a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -6,42 +6,7 @@ require 'gtk2svg'
6
6
  require 'htmle'
7
7
 
8
8
 
9
- module InspectArray
10
-
11
- def scan(a, i=0)
12
-
13
- if a.first.is_a? Symbol
14
-
15
- puts a.inspect
16
-
17
- else
18
-
19
- puts (' ' * i) + '['
20
-
21
- a.each.with_index do |row, j|
22
-
23
- if row.is_a? String or row.is_a? Symbol then
24
- print (' ' * (i+1)) + row.inspect
25
- print ',' unless a.length - 1 == j
26
- puts
27
- elsif row.first.is_a? Symbol or row.first.is_a? String
28
- puts (' ' * (i+1)) + '['
29
- puts (' ' * (i+2)) + row.inspect[1..-2]
30
- print (' ' * (i+1)) + ']'
31
- print ',' unless a.length - 1 == j
32
- puts
33
- else
34
- scan(row,i+1)
35
- print ',' unless a.length - 1 == j
36
- puts
37
- end
38
- end
39
-
40
- print indent = (' ' * i) + ']'
41
- end
42
- end
43
-
44
- end
9
+ # module InspectArray is located in dom_render.rb
45
10
 
46
11
 
47
12
  module Gtk2HTML
@@ -123,8 +88,24 @@ module Gtk2HTML
123
88
  end
124
89
 
125
90
  end
91
+
92
+ r3 = %i(height width).inject(r2) do |r,x|
93
+
94
+ if r.has_key? x then
95
+
96
+ v = r[x]
97
+
98
+ # note: there is 16px in 1em, see http://pxtoem.com/
99
+ r[x] = v =~ /em$/i ? v.to_f * 16 : v.to_f
100
+ r
101
+
102
+ else
103
+ r
104
+ end
105
+
106
+ end
126
107
 
127
- r2
108
+ r3
128
109
 
129
110
  end
130
111
 
@@ -145,9 +126,11 @@ module Gtk2HTML
145
126
 
146
127
  def initialize(instructions, width: 320, height: 240)
147
128
 
148
- @pcoords = [0, 0, width, height]
149
- @a = lay_out(instructions)
150
-
129
+ pcoords = [0, 0, width, height]
130
+ @pcoords = [0,0,0,0]
131
+ a = lay_out(instructions, pcoords)
132
+ @a = del_pcoords a
133
+
151
134
  end
152
135
 
153
136
  def to_a(inspect: false, verbose: false)
@@ -155,6 +138,7 @@ module Gtk2HTML
155
138
  if inspect or verbose then
156
139
  scan @a
157
140
  puts
141
+ @a
158
142
  else
159
143
  @a
160
144
  end
@@ -163,56 +147,103 @@ module Gtk2HTML
163
147
 
164
148
 
165
149
  private
150
+
151
+ def del_pcoords(a)
152
+
153
+ if a.first.is_a? Array then
154
+ a.map {|row| del_pcoords row }
155
+ else
156
+ a.pop
157
+ a
158
+ end
159
+ end
166
160
 
167
- def lay_out(a)
168
-
161
+ def lay_out(a, pcoords=[])
162
+
169
163
  if a.first.is_a? Symbol then
170
-
171
- @text_style = %i(font-size color).inject({}){|r,x| r.merge(x => a[4][x]) }
172
-
173
- set_row(a)
164
+
165
+ @text_style = %i(font-size color).inject({})\
166
+ {|r,x| r.merge(x => a[4][x]) }
167
+ set_row(a, pcoords)
174
168
 
175
169
  elsif a.first.is_a? String then
176
- a.concat [@pcoords.take(2), @text_style]
177
- elsif a.first.is_a? Array and a.first.empty?
178
- a.delete a.first
179
- lay_out a
180
- else
170
+
171
+ [a.first, @pcoords.take(2), @text_style, pcoords]
172
+
173
+ elsif a.first.is_a? Array
174
+
175
+ if a.first.empty? then
176
+ a.delete a.first
177
+ lay_out a, pcoords
178
+ else
179
+
180
+ if a.first.first.is_a? Symbol then
181
+
182
+ item, children = a
183
+
184
+ r = lay_out(item, pcoords)
185
+
186
+ pcoords = r[-1]
187
+
188
+ if children then
181
189
 
182
- a.map do |row|
190
+ r2 = lay_out(children, pcoords)
191
+ r = [r,r2]
192
+ end
183
193
 
184
- if a.first.is_a? String then
185
- a.concat [@pcoords.take(2), style]
194
+ #r << pcoords
195
+
186
196
  else
187
- lay_out(row)
197
+ a.map {|row| lay_out(row, pcoords) }
188
198
  end
199
+
189
200
  end
190
201
 
191
- end
202
+ else
203
+
204
+ a.map {|row| lay_out(row, pcoords) }
192
205
 
206
+ end
207
+
193
208
  end
194
209
 
195
- def set_row(row)
196
-
210
+ def set_row(row, pcoords)
211
+
197
212
  name, margin, raw_coords, padding, style = row
213
+
214
+ coords = raw_coords.map.with_index {|x,i| x ? x : pcoords[i]}
198
215
 
199
- coords = raw_coords.map.with_index {|x,i| x ? x : @pcoords[i]}
216
+ width, height = style[:width], style[:height]
200
217
 
201
218
  x1 = coords[0] + margin[0]
202
219
  y1 = coords[1] + margin[1]
203
- x2 = coords[2] - margin[2]
204
- y2 = coords[3] - margin[3]
220
+
221
+ if width then
205
222
 
206
- new_coords = [x1, y1, x2, y2]
223
+ x2 = x1 + width.to_f
224
+ x2 += margin[2]
225
+ else
226
+ x2 = coords[2] - margin[2]
227
+ end
207
228
 
208
- curpos = new_coords.zip(padding).map{|x| x.inject(&:+)}
229
+ if height then
230
+
231
+ y2 = y1 + height.to_f
232
+ y2 += margin[3]
233
+
234
+ else
235
+ y2 = coords[3] - margin[3]
236
+ end
237
+
238
+ new_coords = [x1, y1, x2, y2]
209
239
 
210
240
  @pcoords[0] = x1 + padding[0]
211
241
  @pcoords[1] = y1 + padding[1]
212
242
  @pcoords[2] = x2 - padding[2]
213
243
  @pcoords[3] = y2 - padding[3]
214
-
215
- r = [name, margin, new_coords, padding, style]
244
+ pcoords = @pcoords.clone
245
+
246
+ [name, margin, new_coords, padding, style, pcoords]
216
247
 
217
248
  end
218
249
 
@@ -244,7 +275,7 @@ module Gtk2HTML
244
275
  end
245
276
 
246
277
  def draw_layout(text, coords, style)
247
-
278
+
248
279
  x, y = coords
249
280
 
250
281
  text ||= ''
@@ -264,7 +295,7 @@ module Gtk2HTML
264
295
  end
265
296
 
266
297
  def render(a)
267
- draw [a]
298
+ draw a
268
299
  end
269
300
 
270
301
  def script(args)
@@ -275,49 +306,63 @@ module Gtk2HTML
275
306
  private
276
307
 
277
308
  def draw(a)
278
-
309
+
279
310
  return unless a
280
311
 
281
- a.each do |row|
312
+ if a.first.is_a? Symbol then
282
313
 
283
- next unless row
314
+ name, margin, coords, padding, style, _, *children = a
315
+ method(name).call(margin, coords, padding, style)
316
+ draw children
317
+
318
+ elsif a.first.is_a? String and not a.first.empty?
284
319
 
285
- x = row
320
+ coords, style = a[1..-1]#remaining
321
+ method(:draw_layout).call(a.first, coords, style)
322
+
323
+ else
324
+
325
+ a.each do |row|
286
326
 
287
- case row[0].class.to_s.to_sym
327
+ next unless row
288
328
 
289
- when :Symbol
290
-
291
- name, margin, coords, padding, style, *children = x
292
-
293
- @latest_style = style
294
- method(name).call(margin, coords, padding, style)
295
- draw children
296
-
297
- when :String then
329
+ x = row
330
+
331
+ case row[0].class.to_s.to_sym
332
+
333
+ when :Symbol
334
+
335
+ name, margin, coords, padding, style, _, *children = x
336
+
337
+ method(name).call(margin, coords, padding, style)
338
+ draw children
339
+
340
+ when :String then
298
341
 
299
- next if x.empty?
342
+ next if x.empty?
300
343
 
301
- coords, style = row[1..-1]#remaining
302
- method(:draw_layout).call(x,coords, style)
344
+ coords, style = row[1..-1]#remaining
345
+
346
+ method(:draw_layout).call(*row)
303
347
 
304
- when :Array
348
+ when :Array
305
349
 
306
- if row[-1][0].is_a? String then
307
- method(:draw_layout).call(*row[-1])
308
- else
350
+ if row[-1][0].is_a? String then
351
+ method(:draw_layout).call(*row[-1])
352
+ else
353
+ draw row[-1]
354
+ end
355
+ else
356
+
357
+ name, *args = x
358
+
359
+ method(name).call(args)
309
360
  draw row[-1]
310
361
  end
311
- else
312
-
313
- name, *args = x
314
362
 
315
- method(name).call(args)
316
- draw row[-1]
317
363
  end
318
-
319
364
  end
320
-
365
+
321
366
  end
322
367
 
323
368
  def set_colour(c)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  XW00gFE4S5Cq4J0/5Y8BLyxXWUTTXHeLXwfiIfffKOUtTUjlivG+dvqexj8Qbbv9
32
32
  bW25tpA1jigdbQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-11-29 00:00:00.000000000 Z
34
+ date: 2015-12-01 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gtk2svg
metadata.gz.sig CHANGED
Binary file