jsajax_wizard 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: b0bd3b1c41b5d9bbb8500c3d0d0ebcb6d7a4c0324443e1e7e993df4ddda6537d
4
- data.tar.gz: 3dcc5ed2af475d525f39eb4e749e4396c1e2630c57a3c0b04d5ffc01e3cdb7f3
3
+ metadata.gz: 2e5f24b2ebcacd9a7ee478e85a59a75c2c35beec64d73b9a8760d8619a348dcf
4
+ data.tar.gz: 76c372f959a84223e54aead55212874516f7cf1f6d16bf751f592d5eef15ce28
5
5
  SHA512:
6
- metadata.gz: 92ae05fa525f340700c44ee70c13dda97a884af72fad9e55c2f21c6f16c7521831878bf7dc54da65adf02b20b65678fa58ddb73c59327fd07edca335fc94bfce
7
- data.tar.gz: 8632b42955a032d696560e017a397c1ab6805598e162a9eae55b90289b5df221b8458e1f3d0fe876629bdd67273ad333b442034ca2b0670436f0d5042f7d60a0
6
+ metadata.gz: 395c6ec4bb623457c154fd7bde1190f7e3bd6e9e31db65c814fb1db36e9974672652c67dea78c1582afb22a5d5aed8de4ce2415dcbdfe3a0d60f3132c921711c
7
+ data.tar.gz: c4b783ec09d4b5bb2e574b03f9c9f11f2e2de1bfa91a436da9e78a30131ed946e64aa48574892986e6eb43a3f1b5420248fdb0ef70067a56b3e60a440387dacf
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/jsajax_wizard.rb CHANGED
@@ -9,8 +9,9 @@ require 'rexle'
9
9
  require 'rexle-builder'
10
10
 
11
11
  class JsAjaxWizard
12
+ using ColouredText
12
13
 
13
- def initialize(html: '', debug: false)
14
+ def initialize(html='', debug: false)
14
15
 
15
16
  @html, @debug = html, debug
16
17
  @requests = []
@@ -22,25 +23,67 @@ class JsAjaxWizard
22
23
  end
23
24
 
24
25
  def to_html()
26
+
27
+ html = @html.empty? ? build_html : @html
28
+
29
+ puts 'html: ' + html.inspect if @debug
30
+
31
+ doc = Rexle.new(html)
32
+ puts 'doc.xml: ' + doc.xml(pretty: true) if @debug
33
+ add_events(doc)
34
+ doc.root.element('body').add(Rexle.new(build_js))
35
+
36
+ doc.xml
37
+ end
25
38
 
26
- a = RexleBuilder.build do |xml|
27
- xml.html do
28
- xml.head do
29
- xml.meta name: "viewport", content: \
30
- "width=device-width, initial-scale=1"
31
- xml.style "\nbody {font-family: Arial;}\n\n"
39
+ private
40
+
41
+ def add_events(doc)
42
+
43
+ @requests.each.with_index do |x,i|
44
+
45
+ element = x[1]
46
+
47
+ selector = if element[:id] then
48
+ '#' + element[:id]
49
+ elsif element[:type]
50
+ "*[type=%s]" % element[:type]
51
+ end
52
+
53
+ if @debug then
54
+ puts "selector: *|%s|*" % selector.inspect
55
+ puts 'doc: ' + doc.xml(pretty: true).inspect
56
+ end
57
+
58
+ e = doc.at_css(selector)
59
+ puts ('e: ' + e.inspect).debug if @debug
60
+
61
+ func = 'ajaxCall' + (i+1).to_s
62
+ event = e.attributes[:type] == 'button' ? func + '()' : func + '(this)'
63
+
64
+ puts ('element: ' + element.inspect).debug if @debug
65
+
66
+ key = if element[:event] then
67
+
68
+ if element[:event].to_sym == :on_enter then
69
+ event = func + '(event.keyCode, this)'
70
+ :onkeyup
71
+ else
72
+ element[:event].to_sym
32
73
  end
33
- xml.body build_html + "\n" + build_js()
74
+
75
+ else
76
+ e.attributes[:type] == 'button' ? :onclick : :onkeyup
34
77
  end
78
+
79
+ e.attributes[key] = event
80
+
35
81
  end
36
-
37
- doc = Rexle.new(a)
38
82
 
83
+ doc
39
84
  end
40
85
 
41
- private
42
-
43
- def build_html()
86
+ def build_elements()
44
87
 
45
88
  html = @requests.map.with_index do |x,i|
46
89
 
@@ -51,14 +94,11 @@ class JsAjaxWizard
51
94
 
52
95
  a = if e[:type].to_s == 'button' then
53
96
 
54
- e[:event] = :onclick unless e[:event]
55
- ["<button type='button' %s='ajaxCall%s()'>Change Content</button>" \
56
- % [e[:event].to_s, i+1]]
97
+ ["<button type='button''>Change Content</button>"]
57
98
 
58
99
  elsif e[:type].to_s == 'text' then
59
100
 
60
- e[:event] = :onkeyup unless e[:event]
61
- ["<input type='text' %s='ajaxCall%s(this)'/>" % [e[:event].to_s, i+1]]
101
+ ["<input type='text'/>"]
62
102
 
63
103
  else
64
104
  ''
@@ -69,9 +109,26 @@ class JsAjaxWizard
69
109
 
70
110
  end
71
111
 
72
- html.join("\n")
112
+ r = html.join("\n")
113
+ puts 'r: ' + r.inspect if @debug
114
+ r
73
115
 
74
116
  end
117
+
118
+ def build_html()
119
+
120
+ RexleBuilder.build do |xml|
121
+ xml.html do
122
+ xml.head do
123
+ xml.meta name: "viewport", content: \
124
+ "width=device-width, initial-scale=1"
125
+ xml.style "\nbody {font-family: Arial;}\n\n"
126
+ end
127
+ xml.body build_elements
128
+ end
129
+ end
130
+
131
+ end
75
132
 
76
133
  def build_js()
77
134
 
@@ -99,11 +156,26 @@ EOF
99
156
  server, element, target_element = x
100
157
 
101
158
  a << if element[:type] == 'text' then
159
+
160
+ if element[:event].to_sym == :on_enter then
102
161
  "
103
- function ajaxCall#{i+1}() {
104
- ajaxRequest('#{server}', ajaxResponse#{i+1})
162
+ function ajaxCall#{i+1}(keyCode, e) {
163
+
164
+ if (keyCode==13){
165
+ ajaxRequest('#{server}' + e.value, ajaxResponse#{i+1})
166
+ }
167
+
168
+
169
+ }
170
+ "
171
+ else
172
+ "
173
+ function ajaxCall#{i+1}(e) {
174
+ ajaxRequest('#{server}' + e.value, ajaxResponse#{i+1})
105
175
  }
106
176
  "
177
+ end
178
+
107
179
  else
108
180
  "
109
181
  function ajaxCall#{i+1}() {
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsajax_wizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  pZTsghadsRxoGiI7mehrgxkeLLA7q3Zpafsvw3mLrERdifNsVFNBUDMjfE/OnJq8
36
36
  EOz+UVQEw8EJ9wHqaJYIbHBq
37
37
  -----END CERTIFICATE-----
38
- date: 2019-08-08 00:00:00.000000000 Z
38
+ date: 2019-08-09 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rexle
metadata.gz.sig CHANGED
Binary file