htmlcom 0.3.0 → 0.3.1
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/htmlcom.rb +105 -15
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5c56bbfd02df1b1aa0af4dd6408b34301964015bcefed1a8a6a88b89c98d42d
|
4
|
+
data.tar.gz: 6dee7c3818848ce0428cfb5b3df0a2c7cf79b5b4139d22fde8389212dd6e7694
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31bdddd64984e4a344436918bb09e1a79acc0bb58d15a6878f8a0c28afa30da1b3486c7d68bf3464b4288faec8a7c55351f5f6bc33037dd7186bf0deb8be4c92
|
7
|
+
data.tar.gz: 46dfd28e68b5f40cabfbde02c854b2bfefaf1fbca2b7455945822b5b9635ea0f8ff45bb538130ecc987ae6e80137ab87b4b7f7c3d2dec4910fe37946a0e314ee
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/htmlcom.rb
CHANGED
@@ -22,6 +22,7 @@ require 'rexle-builder'
|
|
22
22
|
# InputElement # used by the HTML input element
|
23
23
|
# Dropdown # an HTML element
|
24
24
|
# Textarea # an HTML element
|
25
|
+
# FormBuilder
|
25
26
|
|
26
27
|
module HtmlCom
|
27
28
|
|
@@ -332,20 +333,30 @@ EOF
|
|
332
333
|
|
333
334
|
class Element
|
334
335
|
|
335
|
-
def initialize(
|
336
|
-
|
336
|
+
def initialize(obj)
|
337
|
+
|
338
|
+
@doc = build(obj)
|
339
|
+
puts '@doc.xml : ' + @doc.xml.inspect
|
340
|
+
if @id then
|
341
|
+
elem = @doc.root.element(@tag + '/' + @htmltag)
|
342
|
+
puts 'elem: ' +elem.inspect
|
343
|
+
elem.attributes[:name] = @id
|
344
|
+
elem.attributes[:id] = @id
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
348
|
+
|
349
|
+
def html_element()
|
350
|
+
@doc.root.element(@tag + '/' + @htmltag)
|
337
351
|
end
|
338
352
|
|
339
353
|
def to_doc()
|
340
354
|
@doc
|
341
355
|
end
|
342
356
|
|
343
|
-
def build(
|
344
|
-
|
345
|
-
|
346
|
-
doc = Rexle.new(RexleBuilder.new(h).to_a)
|
347
|
-
puts doc.xml pretty: true
|
348
|
-
doc
|
357
|
+
def build(rawobj)
|
358
|
+
obj = rawobj.is_a?(Hash) ? RexleBuilder.new(rawobj).to_a : rawobj
|
359
|
+
Rexle.new(obj)
|
349
360
|
end
|
350
361
|
|
351
362
|
end
|
@@ -364,12 +375,6 @@ EOF
|
|
364
375
|
super({@tag.to_sym => rawobj})
|
365
376
|
end
|
366
377
|
|
367
|
-
if @id then
|
368
|
-
elem = @doc.root.element(@tag + '/' + @htmltag)
|
369
|
-
elem.attributes[:name] = @id
|
370
|
-
elem.attributes[:id] = @id
|
371
|
-
end
|
372
|
-
|
373
378
|
end
|
374
379
|
|
375
380
|
end
|
@@ -388,11 +393,15 @@ EOF
|
|
388
393
|
list = options.map {|option| {option: option}}
|
389
394
|
super({_select: list})
|
390
395
|
|
396
|
+
values = options.map(&:downcase)
|
397
|
+
@doc.root.xpath('dropdown/select/option').each.with_index do |e,i|
|
398
|
+
e.attributes[:value] = values[i]
|
399
|
+
end
|
400
|
+
|
391
401
|
elsif options.is_a? Hash then
|
392
402
|
|
393
403
|
list = options.values.map {|option| {option: option}}
|
394
404
|
values = options.keys
|
395
|
-
puts 'list: ' + list.inspect
|
396
405
|
super({_select: list})
|
397
406
|
|
398
407
|
@doc.root.xpath('dropdown/select/option').each.with_index do |e,i|
|
@@ -418,4 +427,85 @@ EOF
|
|
418
427
|
|
419
428
|
end
|
420
429
|
|
430
|
+
class Form < Element
|
431
|
+
|
432
|
+
def initialize(inputs=nil, id: nil, method: :get, action: '')
|
433
|
+
|
434
|
+
@tag = 'form'
|
435
|
+
@htmltag = 'form'
|
436
|
+
@id = id
|
437
|
+
|
438
|
+
super([:root, {}, [@tag,{}, [@htmltag, {}]]])
|
439
|
+
form = @doc.root.element(@tag + '/' + @htmltag)
|
440
|
+
form.add inputs if inputs
|
441
|
+
form.attributes[:method] = method.to_s
|
442
|
+
form.attributes[:action] = action
|
443
|
+
|
444
|
+
end
|
445
|
+
|
446
|
+
end
|
447
|
+
|
448
|
+
|
449
|
+
# e.g. inputs = {txt: [:textarea], audiotype: [:dropdown, 'gsm'], voice: [:dropdown, 'Stuart']}
|
450
|
+
# options = {audiotype: ['gsm', 'wav'], voice: %w(Stuart Kirsty Andrew)}
|
451
|
+
#
|
452
|
+
# fb = HtmlCom::FormBuilder.new(inputs: inputs, options: options)
|
453
|
+
# puts fb.to_html
|
454
|
+
|
455
|
+
class FormBuilder
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
def initialize(inputs: {}, options: {}, id: 'form1', method: :get, action: '', debug: false)
|
460
|
+
|
461
|
+
@debug = debug
|
462
|
+
|
463
|
+
h = inputs.map do |key, value|
|
464
|
+
|
465
|
+
if debug then
|
466
|
+
puts 'id: ' + key.inspect
|
467
|
+
puts 'klass: ' + value.first.inspect
|
468
|
+
end
|
469
|
+
|
470
|
+
[key, [value.first]]
|
471
|
+
end.to_h
|
472
|
+
|
473
|
+
options.each do |key, value|
|
474
|
+
h[key] << value
|
475
|
+
end
|
476
|
+
|
477
|
+
klass = {dropdown: HtmlCom::Dropdown, textarea: HtmlCom::Textarea}
|
478
|
+
|
479
|
+
@form = HtmlCom::Form.new(id: id, method: method, action: action)
|
480
|
+
|
481
|
+
h.each do |key, value|
|
482
|
+
|
483
|
+
id = key
|
484
|
+
type, content = value
|
485
|
+
action = case type
|
486
|
+
when :dropdown
|
487
|
+
'Select'
|
488
|
+
else
|
489
|
+
'Enter'
|
490
|
+
end
|
491
|
+
|
492
|
+
obj = klass[type].new content, id: id, label: action + ' ' + id.to_s
|
493
|
+
|
494
|
+
obj.to_doc.root.element(type.to_s).elements.each do |e|
|
495
|
+
@form.html_element.add e
|
496
|
+
end
|
497
|
+
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
def to_doc()
|
502
|
+
@form.to_doc
|
503
|
+
end
|
504
|
+
|
505
|
+
def to_html()
|
506
|
+
@form.to_doc.root.xml pretty: true
|
507
|
+
end
|
508
|
+
|
509
|
+
end
|
510
|
+
|
421
511
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmlcom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
JNdZs/7/k4vQlgqYQ3HnoA6GgIanmCgNkediqllxv/epLyIkW2DSJGcYXM8QjSEk
|
37
37
|
+4RQ8UHDCOWHpFPlT5Pgc0wPc7KyXosRYHg=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date: 2022-07-
|
39
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: jsmenubuilder
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,4 @@
|
|
1
|
-
|
2
|
-
�
|
1
|
+
����8~t�Hg�BiM�ia��1=r��@qZ����ӓ��GuJ������.=T���M�9%� |:��A�^������;�pu��91�XP��v�Xo9�S#}���2���8=��d3���7��[ō��A��Yu$rηG�4re:�n ��)< �����������=D~�$���Ht�5e�pYh����7�j�|P�����|�����´�
|
2
|
+
R*C��]�Ҹ�B:����� C@�X��'F�(�)��4���[ Fa
|
3
|
+
������>����*�c�2�W�N0D���,��L��L����v
|
4
|
+
��Y�7�]^�2!�,�b2���փ��,aXc?Sgz�i
|