z4app 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/z4app/version.rb +1 -1
- data/lib/z4app.rb +113 -12
- 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
|
@@ -31,10 +131,13 @@ module Z4app
|
|
31
131
|
set :views, 'views/'
|
32
132
|
set :server, 'webrick'
|
33
133
|
end
|
134
|
+
|
135
|
+
on_start { puts "[z4app] OK." }
|
34
136
|
|
35
137
|
# handle dumb shit
|
36
138
|
['robots.txt', 'favicon.ico'].each { |e| get("/#{e}") {}}
|
37
139
|
|
140
|
+
# pwa requirement
|
38
141
|
get('/manifest.webmanifest') {
|
39
142
|
content_type 'application/manifest+json'
|
40
143
|
h = {
|
@@ -46,6 +149,7 @@ module Z4app
|
|
46
149
|
return JSON.generate(h)
|
47
150
|
}
|
48
151
|
|
152
|
+
# pwa requirement
|
49
153
|
get('/service-worker.js') {
|
50
154
|
content_type 'application/javascript'
|
51
155
|
erb :service_worker, layout: false
|
@@ -68,7 +172,8 @@ module Z4app
|
|
68
172
|
content_type "application/json"
|
69
173
|
return JSON.generate(@@APP[:obj][params[:o].to_sym].call(params[:i].to_sym, request))
|
70
174
|
}
|
71
|
-
|
175
|
+
|
176
|
+
# handle form post
|
72
177
|
post('/:v') {
|
73
178
|
@here = @@APP[:post][params[:v].to_sym].call(params, request)
|
74
179
|
if params.has_key? :goto
|
@@ -78,24 +183,19 @@ module Z4app
|
|
78
183
|
end
|
79
184
|
}
|
80
185
|
|
81
|
-
# handle post
|
186
|
+
# handle json post
|
82
187
|
post('/') {
|
83
188
|
content_type = 'application/json'
|
84
189
|
return JSON.generate(@@APP[:post][:index].call(params, request))
|
85
190
|
}
|
86
191
|
end
|
87
|
-
|
192
|
+
# start server
|
88
193
|
def self.init!
|
89
|
-
|
90
|
-
end
|
91
|
-
def self.proc
|
92
|
-
@@PROC
|
93
|
-
end
|
94
|
-
def self.app
|
95
|
-
@@APP
|
194
|
+
Process.detach(fork { APP.run! { puts "[z4app][init] OK." } })
|
96
195
|
end
|
97
196
|
end
|
98
197
|
|
198
|
+
# load app script if available
|
99
199
|
if File.exist? 'app.rb'
|
100
200
|
load 'app.rb'
|
101
201
|
puts "[z4app][config] app."
|
@@ -103,4 +203,5 @@ else
|
|
103
203
|
puts "[z4app][config] default."
|
104
204
|
end
|
105
205
|
|
106
|
-
|
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
|