z4app 0.1.3 → 0.1.5
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 +4 -4
- data/lib/z4app/version.rb +1 -1
- data/lib/z4app.rb +112 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b7bc57600f4e146c9d09e6205205a4e80c0a809531a5e6eb5242029f97df53b
|
4
|
+
data.tar.gz: 7f7ab4e8799ed72cb10e82c7a6cd82174391f8b48cbf1b9ea55aed9270ec98d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e04eda590cc1b8081b98e6429fb77edb28f1641c2b3e14228627847fa55657518fe85068a2cd3a1f28f939eb2ed6b38c45eaadf010cc8ffedf25cc0f9d9e0db3
|
7
|
+
data.tar.gz: 3cd906c0346dedad870d55ce8088e6c84200ed34a4d320c686610c63883f537ce71b65cbd2192e220672182552f58d103805a9ce9ec908270677023a3bfd495b
|
data/lib/z4app/version.rb
CHANGED
data/lib/z4app.rb
CHANGED
@@ -13,6 +13,104 @@ require_relative "z4app/version"
|
|
13
13
|
module Z4app
|
14
14
|
class Error < StandardError; end
|
15
15
|
|
16
|
+
class Embed
|
17
|
+
def initialize script
|
18
|
+
@o = []
|
19
|
+
self.instance_eval script
|
20
|
+
end
|
21
|
+
def result params={}
|
22
|
+
a = [
|
23
|
+
%[<div id='embed'>],
|
24
|
+
@o.join(""),
|
25
|
+
%[</div>]
|
26
|
+
]
|
27
|
+
return ERB.new(a.join("")).result(binding)
|
28
|
+
end
|
29
|
+
# insert param into embed.
|
30
|
+
def param key
|
31
|
+
return %[<%= params[:#{key}] %>]
|
32
|
+
end
|
33
|
+
# insert text input.
|
34
|
+
def input key, h={}
|
35
|
+
hh = { pattern: '.*', title: 'required.' }.merge(h)
|
36
|
+
@o << %[<h1 class='e'><input name="embed[#{key}]" pattern='#{hh[:pattern]}' title='#{hh[:title]}' placeholder="#{key}"></h1>]
|
37
|
+
end
|
38
|
+
# insert email field.
|
39
|
+
def email k
|
40
|
+
@o << %[<h1 class='e'><input type='email' name='embed[#{k}]' placeholder='#{k}' pattern='.+@.+' title='valid email.'></h1>]
|
41
|
+
end
|
42
|
+
# insert url field.
|
43
|
+
def url k
|
44
|
+
@o << %[<h1 class='e'><input type='url' name='embed[#{k}] placeholder='#{k}' pattern='https://.*' title='valid url.'></h1>]
|
45
|
+
end
|
46
|
+
# insert phone field.
|
47
|
+
def tel k
|
48
|
+
@o << %[<h1 class='e'><input type='tel' name='embed[#{k}] placeholder='#{k}' pattern='\d{10}' title='valid phone number.'></h1>]
|
49
|
+
end
|
50
|
+
# insert textarea.
|
51
|
+
def textarea key, h={}
|
52
|
+
hh = { placeholder: '', value: ''}.merge(h)
|
53
|
+
@o << %[<textarea name='embed[#{key}]' placeholder='#{hh[:placeholder]}'>#{hh[:value]}</textarea>]
|
54
|
+
end
|
55
|
+
# insert color.
|
56
|
+
def color k
|
57
|
+
@o << %[<h1 class='e'><input type='color' id='e_#{e}' name='embed[#{k}]'><label for='e_#{k}'>#{k}</label></h1>]
|
58
|
+
end
|
59
|
+
# insert date.
|
60
|
+
def date k
|
61
|
+
@o << %[<h1 class='e'><input type='date' name='embed[#{k}]'></h1>]
|
62
|
+
end
|
63
|
+
# insert time.
|
64
|
+
def time k
|
65
|
+
@o << %[<h1 class='e'><input type='datetime-local' name='embed[#{k}]'></h1>]
|
66
|
+
end
|
67
|
+
# insert radio button.
|
68
|
+
def radio k
|
69
|
+
@o << %[<h1 class='e'><input type="radio" id="e_#{k}" name="embed[#{k}]" value="true"><label for="e_#{k}">#{k}</label></h1>]
|
70
|
+
end
|
71
|
+
# insert checkbox.
|
72
|
+
def check k
|
73
|
+
@o << %[<h1 class='e'><input type="checkbox" id="e_#{k}" name="embed[#{k}]" value="true"><label for="e_#{k}">#{k}</label></h1>]
|
74
|
+
end
|
75
|
+
# insert selector.
|
76
|
+
def select k, *opts
|
77
|
+
o = []
|
78
|
+
[opts].flatten.each {|e| o << %[<option value="#{e}">#{e}</option>] }
|
79
|
+
@o << %[<h1 class='e'><select name="embed[#{k}]">#{o.join("")}</select></h1>]
|
80
|
+
end
|
81
|
+
# insert number field.
|
82
|
+
def number k, h={}
|
83
|
+
hh = { min: 0, max: 100, value: 1 }.merge(h)
|
84
|
+
@o << %[<h1 class='e'><input type="number" name="embed[#{k}]" value='#{hh[:value]}' min='#{hh[:min]}' max='#{hh[:max]}' placeholder='#{k}'></h1>]
|
85
|
+
end
|
86
|
+
# insert plain text.
|
87
|
+
def text t
|
88
|
+
@o << %[<h2 class='e'>#{t}</h2>]
|
89
|
+
end
|
90
|
+
# set goto field.
|
91
|
+
def goto g, h={}
|
92
|
+
a = []; h.each_pair { |k,v| a << %[#{k}=#{v}] }
|
93
|
+
@o << %[<input type='hidden' name='goto' value='/#{g}?#{a.join("&")}'>]
|
94
|
+
end
|
95
|
+
# add submit button.
|
96
|
+
def submit p
|
97
|
+
@o << %[<h1 class='e'><button id='send'>#{p}</button></h1>]
|
98
|
+
end
|
99
|
+
# set stack push object.
|
100
|
+
def stack c, o
|
101
|
+
@o << %[<input type='hidden' name='action' value='#{c}'>]
|
102
|
+
@o << %[<input type='hidden' name='push' value='#{o}'>]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# generate html content.
|
108
|
+
def self.embed s, h={}
|
109
|
+
Embed.new(s).result(h)
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# overwrite event handlers
|
16
114
|
def self.on t, k, &b
|
17
115
|
@@APP[t][k] = b
|
18
116
|
end
|
@@ -21,7 +119,9 @@ module Z4app
|
|
21
119
|
obj: Hash.new { |h,k| h[k] = lambda { |*a| puts %[[z4app][obj] #{a}]; { time: Time.now.to_s }; } },
|
22
120
|
get: Hash.new { |h,k| h[k] = lambda { |*a| puts %[[z4app][get] #{a}]; { time: Time.now.to_s }; } },
|
23
121
|
post: Hash.new { |h,k| h[k] = lambda { |*a| puts %[[z4app][post] #{a}]; { time: Time.now.to_s }; } }
|
24
|
-
}
|
122
|
+
}
|
123
|
+
|
124
|
+
# The web-app server
|
25
125
|
class APP < Sinatra::Base
|
26
126
|
include Z4app
|
27
127
|
configure do
|
@@ -36,7 +136,8 @@ module Z4app
|
|
36
136
|
|
37
137
|
# handle dumb shit
|
38
138
|
['robots.txt', 'favicon.ico'].each { |e| get("/#{e}") {}}
|
39
|
-
|
139
|
+
|
140
|
+
# pwa requirement
|
40
141
|
get('/manifest.webmanifest') {
|
41
142
|
content_type 'application/manifest+json'
|
42
143
|
h = {
|
@@ -48,6 +149,7 @@ module Z4app
|
|
48
149
|
return JSON.generate(h)
|
49
150
|
}
|
50
151
|
|
152
|
+
# pwa requirement
|
51
153
|
get('/service-worker.js') {
|
52
154
|
content_type 'application/javascript'
|
53
155
|
erb :service_worker, layout: false
|
@@ -70,7 +172,8 @@ module Z4app
|
|
70
172
|
content_type "application/json"
|
71
173
|
return JSON.generate(@@APP[:obj][params[:o].to_sym].call(params[:i].to_sym, request))
|
72
174
|
}
|
73
|
-
|
175
|
+
|
176
|
+
# handle form post
|
74
177
|
post('/:v') {
|
75
178
|
@here = @@APP[:post][params[:v].to_sym].call(params, request)
|
76
179
|
if params.has_key? :goto
|
@@ -80,24 +183,19 @@ module Z4app
|
|
80
183
|
end
|
81
184
|
}
|
82
185
|
|
83
|
-
# handle post
|
186
|
+
# handle json post
|
84
187
|
post('/') {
|
85
188
|
content_type = 'application/json'
|
86
189
|
return JSON.generate(@@APP[:post][:index].call(params, request))
|
87
190
|
}
|
88
191
|
end
|
89
|
-
|
192
|
+
# start server
|
90
193
|
def self.init!
|
91
|
-
|
92
|
-
end
|
93
|
-
def self.proc
|
94
|
-
@@PROC
|
95
|
-
end
|
96
|
-
def self.app
|
97
|
-
@@APP
|
194
|
+
Process.detach(fork { APP.run! { puts "[z4app][init] OK." } })
|
98
195
|
end
|
99
196
|
end
|
100
197
|
|
198
|
+
# load app script if available
|
101
199
|
if File.exist? 'app.rb'
|
102
200
|
load 'app.rb'
|
103
201
|
puts "[z4app][config] app."
|
@@ -105,4 +203,5 @@ else
|
|
105
203
|
puts "[z4app][config] default."
|
106
204
|
end
|
107
205
|
|
108
|
-
|
206
|
+
# start app
|
207
|
+
@app = Z4app.init!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: z4app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Olson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webrick
|