cuca 0.07 → 0.12
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 +7 -0
- data/CHANGELOG +10 -0
- data/README.md +51 -0
- data/application_skeleton/app/test.rb +16 -0
- data/application_skeleton/conf/config.rb +8 -1
- data/application_skeleton/public/dispatch-fwdev.cgi +3 -1
- data/application_skeleton/public/dispatch.cgi +1 -1
- data/application_skeleton/public/dispatch.fcgi +1 -1
- data/application_skeleton/scripts/server-lighttpd-fcgi.rb +43 -4
- data/application_skeleton/scripts/server-lighttpd.rb +58 -5
- data/application_skeleton/scripts/server-webrick.rb +1 -1
- data/application_skeleton/tests/functional/basic.rb +32 -0
- data/bin/cuca +7 -3
- data/lib/cuca.rb +1 -1
- data/lib/cuca/app.rb +44 -31
- data/lib/cuca/cgi_emu.rb +17 -6
- data/lib/cuca/const.rb +1 -1
- data/lib/cuca/controller.rb +0 -2
- data/lib/cuca/generator/view.rb +7 -5
- data/lib/cuca/mimetypes.rb +2 -0
- data/lib/cuca/sessionpage.rb +18 -4
- data/lib/cuca/stdlib/README +2 -0
- data/lib/cuca/stdlib/form.rb +1 -1
- data/lib/cuca/stdlib/listwidget/dblist.rb +13 -2
- data/lib/cuca/stdlib/listwidget/querydef.rb +11 -17
- data/lib/cuca/test/helpers.rb +55 -2
- data/lib/cuca/urlmap.rb +18 -9
- data/tests/all.rb +4 -1
- data/tests/controller.rb +26 -9
- data/tests/test_app/app/test.rb +0 -0
- data/tests/urlmap.rb +7 -0
- data/tests/widget.rb +2 -2
- metadata +106 -128
- data/README +0 -43
- data/application_skeleton/public/dispatch.cgi-old +0 -18
- data/application_skeleton/public/dispatch.fcgi-old +0 -25
- data/application_skeleton/scripts/rack-test.rb +0 -52
- data/application_skeleton/scripts/server-rack-thin.rb +0 -40
- data/application_skeleton/scripts/server-rack-webrick.rb +0 -22
- data/lib/cuca/stdlib/old_arform.rb +0 -254
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
|
4
|
-
$cuca_path = File.dirname(__FILE__)+"/../"
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'cuca'
|
8
|
-
|
9
|
-
require "fcgi"
|
10
|
-
|
11
|
-
Signal.trap("INT") do
|
12
|
-
$stderr.puts "INT caught"
|
13
|
-
exit
|
14
|
-
end
|
15
|
-
|
16
|
-
application = Cuca::App.new
|
17
|
-
|
18
|
-
FCGI.each_cgi do |cgi|
|
19
|
-
CGI::fix_env(cgi.env_table)
|
20
|
-
start = (Time.now.to_f * 1000).to_i
|
21
|
-
application.cgicall(cgi)
|
22
|
-
stop = (Time.now.to_f * 1000).to_i
|
23
|
-
dur_msec = stop - start
|
24
|
-
application.logger.info("App::cgicall (#{cgi.path_info}: #{dur_msec} msec [= #{(1000 / dur_msec).to_i} pages / second]")
|
25
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rack'
|
4
|
-
require 'rack/session/cookie'
|
5
|
-
|
6
|
-
|
7
|
-
class Middle
|
8
|
-
def initialize(app)
|
9
|
-
@app = app
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(env)
|
13
|
-
$stderr.puts "CAll for MIDDLE"
|
14
|
-
status, headers, body = @app.call(env)
|
15
|
-
[400, headers, [body.first.upcase]]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Cuca
|
20
|
-
def initialize(app)
|
21
|
-
@app = app
|
22
|
-
end
|
23
|
-
|
24
|
-
def call(env)
|
25
|
-
$stderr.puts "CAll for CUCA"
|
26
|
-
$stderr.puts "#{@app.inspect}"
|
27
|
-
@app.call(env)
|
28
|
-
[200, {'Content-Type' => 'text/html'}, ['some Dynamic Website']]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
class App < Rack::Builder
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
app = App.new
|
40
|
-
app.use Cuca
|
41
|
-
|
42
|
-
app.use Middle
|
43
|
-
puts app.to_app.inspect
|
44
|
-
|
45
|
-
|
46
|
-
Rack::Handler::Thin.run(
|
47
|
-
Rack::ShowExceptions.new(
|
48
|
-
Rack::Lint.new(
|
49
|
-
app.to_app
|
50
|
-
)
|
51
|
-
), :Port => 1234)
|
52
|
-
|
@@ -1,40 +0,0 @@
|
|
1
|
-
$: << '/home/bones/workspace/cuca_svn/cuca/lib'
|
2
|
-
require 'cuca'
|
3
|
-
require 'rubygems'
|
4
|
-
# require 'cuca'
|
5
|
-
require 'rack/request'
|
6
|
-
require 'rack/response'
|
7
|
-
require 'rack/showexceptions'
|
8
|
-
require 'rack/handler'
|
9
|
-
require 'rack/handler/thin'
|
10
|
-
require 'rack/lint'
|
11
|
-
|
12
|
-
|
13
|
-
class MakeError
|
14
|
-
def initialize(app)
|
15
|
-
@app = app
|
16
|
-
end
|
17
|
-
|
18
|
-
def call(env)
|
19
|
-
status, headers, body = @app.call(env)
|
20
|
-
[500, headers,body]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
app = Cuca::App.new
|
27
|
-
app.use MakeError
|
28
|
-
|
29
|
-
|
30
|
-
Rack::Handler::Thin.run \
|
31
|
-
Rack::ShowExceptions.new(app),
|
32
|
-
:Port => 1234
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# Rack::Handler::WEBrick.run \
|
37
|
-
# Rack::ShowExceptions.new(Rack::Lint.new(Cuca::App.new)),
|
38
|
-
# :Port => 1234
|
39
|
-
|
40
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
$: << '/home/bones/workspace/cuca_svn/cuca/lib'
|
2
|
-
require 'cuca'
|
3
|
-
require 'rubygems'
|
4
|
-
# require 'cuca'
|
5
|
-
require 'rack/request'
|
6
|
-
require 'rack/response'
|
7
|
-
require 'rack/showexceptions'
|
8
|
-
require 'rack/handler'
|
9
|
-
require 'rack/handler/webrick'
|
10
|
-
require 'rack/lint'
|
11
|
-
|
12
|
-
Rack::Handler::WEBrick.run \
|
13
|
-
Rack::ShowExceptions.new(Cuca::App.new),
|
14
|
-
:Port => 1234
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# Rack::Handler::WEBrick.run \
|
19
|
-
# Rack::ShowExceptions.new(Rack::Lint.new(Cuca::App.new)),
|
20
|
-
# :Port => 1234
|
21
|
-
|
22
|
-
|
@@ -1,254 +0,0 @@
|
|
1
|
-
require 'cuca/stdlib/form'
|
2
|
-
require 'cuca/stdlib/formerrors'
|
3
|
-
require 'cuca/generator/markaby'
|
4
|
-
|
5
|
-
# == Form's for ActiveRecord
|
6
|
-
# AR Form build a form by providing one model of ActiveRecord.
|
7
|
-
# Likly that you want to overwrite the form method to
|
8
|
-
# run a custom layout.
|
9
|
-
#
|
10
|
-
# This Widget will call <form_name>_submit(model) if Form is submitted
|
11
|
-
# and validation passed. You still have to ::save the model.
|
12
|
-
#
|
13
|
-
# = Example:
|
14
|
-
#
|
15
|
-
# ARForm('user_edit', User.find_by_username('bones'),
|
16
|
-
# :disable_on_update => ['username', 'created'])
|
17
|
-
#
|
18
|
-
class ARFormWidget < FormWidget
|
19
|
-
|
20
|
-
include Cuca::Generator::Markaby
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# valid options
|
26
|
-
# * :disabled_on_create => ['field_name_1', 'field_name_2', ..]
|
27
|
-
# switch off fields on new records
|
28
|
-
# * :diabled_on_update => ['field_name_1', 'field_name_2', ..]
|
29
|
-
# switch off fields on existing records
|
30
|
-
def output(form_name, model, options = {})
|
31
|
-
@model = model
|
32
|
-
@disabled_on_update = options[:disabled_on_update] || []
|
33
|
-
@disabled_on_create = options[:disabled_on_create] || []
|
34
|
-
@hidden_on_update = options[:hidden_on_update] || []
|
35
|
-
@hidden_on_create = options[:hidden_on_create] || []
|
36
|
-
super(form_name, options)
|
37
|
-
end
|
38
|
-
|
39
|
-
def on_submit
|
40
|
-
controller.send(@form_name+'_submit', @model) unless controller.nil?
|
41
|
-
|
42
|
-
# this is to reload the form with the new values in case the formname_submit did
|
43
|
-
# save something:
|
44
|
-
clear
|
45
|
-
# form
|
46
|
-
end
|
47
|
-
|
48
|
-
def validate
|
49
|
-
form if @_content.empty? # password fields might write hints to the validator...
|
50
|
-
clear
|
51
|
-
@form_erros = {}
|
52
|
-
p = request_parameters.dup
|
53
|
-
p.delete(@submit_name)
|
54
|
-
|
55
|
-
if @model.new_record? then
|
56
|
-
@disabled_on_create.each { |d| p.delete(d) }
|
57
|
-
@hidden_on_create.each { |d| p.delete(d) }
|
58
|
-
else
|
59
|
-
@disabled_on_update.each { |d| p.delete(d) }
|
60
|
-
@hidden_on_update.each { |d| p.delete(d) }
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
# don't save empty passwords!!
|
65
|
-
@password_fields ||= []
|
66
|
-
@password_fields.each do |pwf|
|
67
|
-
p.delete(pwf) if p[pwf].chomp.empty?
|
68
|
-
end
|
69
|
-
# $stderr.puts p.inspect
|
70
|
-
@model.attributes = p
|
71
|
-
|
72
|
-
return true if @model.valid?
|
73
|
-
|
74
|
-
@model.errors.each do |k,v|
|
75
|
-
@form_errors[k] = v
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# to make a 2 digit string out a number
|
80
|
-
private
|
81
|
-
def twodig(n)
|
82
|
-
n.to_s.length == 1 ? "0"+n.to_s : n.to_s
|
83
|
-
end
|
84
|
-
|
85
|
-
def field_enable?(fname)
|
86
|
-
if @model.new_record? then
|
87
|
-
return @disabled_on_create.include?(fname) ? false : true
|
88
|
-
else
|
89
|
-
return @disabled_on_update.include?(fname) ? false : true
|
90
|
-
end
|
91
|
-
end
|
92
|
-
def field_hidden?(fname)
|
93
|
-
if @model.new_record? then
|
94
|
-
return @hidden_on_create.include?(fname) ? true : false
|
95
|
-
else
|
96
|
-
return @hidden_on_update.include?(fname) ? true : false
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
private
|
102
|
-
def fe_text(name, value,enabled)
|
103
|
-
"<input type='text' name='#{name}' value='#{value}' #{'disabled' unless enabled}>"
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
def fe_textarea(name, value, enabled, rows=4, cols = 50)
|
108
|
-
"<textarea name='#{name}' rows='#{rows}' cols='#{cols}'>#{value}</textarea>"
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
# the fe-password is special: will never contain a value and will not save the
|
113
|
-
# password if nothing was typed into the field
|
114
|
-
private
|
115
|
-
def fe_password(name,enabled)
|
116
|
-
@password_fields ||= []
|
117
|
-
@password_fields << name
|
118
|
-
r = "<input type='password' name='#{name}' #{'disabled' unless enabled}>"
|
119
|
-
if !@model.new_record? then
|
120
|
-
r << "<br><small>Leave empty to keep current password</small>"
|
121
|
-
end
|
122
|
-
return r
|
123
|
-
end
|
124
|
-
|
125
|
-
# this is to build a select box, example:
|
126
|
-
# fe_select('gender', [['f', 'female'],['m','Male']], true) or
|
127
|
-
# fe_select('gender', ['f','m'], true)
|
128
|
-
private
|
129
|
-
def fe_select(name, options, enabled)
|
130
|
-
r = "<select name='#{name}' #{'disabled' unless enabled}>\n"
|
131
|
-
options.each do |o|
|
132
|
-
ov = o.instance_of?(Array) ? o[0] : o
|
133
|
-
sel = ''
|
134
|
-
sel = ' selected' if @model.send(name.intern) == ov
|
135
|
-
if o.instance_of?(Array) then
|
136
|
-
r+="<option value='#{o[0]}'#{sel}>#{o[1]}</option>\n"
|
137
|
-
else
|
138
|
-
r+="<option value='#{o}'#{sel}>#{o}</option>\n"
|
139
|
-
end
|
140
|
-
end
|
141
|
-
r+="</option>\n"
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
def fe_datetime(name, v,enabled)
|
146
|
-
v = Time.now unless v
|
147
|
-
r = <<-EOS
|
148
|
-
<input type='text' name='#{name}' id='i_#{name}' value='#{v.year}/#{twodig(v.month)}/#{twodig(v.day)} #{v.hour}:#{v.min}' #{'disabled' unless enabled}>
|
149
|
-
EOS
|
150
|
-
if enabled then
|
151
|
-
r << <<-EOS
|
152
|
-
<input type='submit' id='s_#{name}' value='...'>
|
153
|
-
<script type="text/javascript">
|
154
|
-
Calendar.setup({
|
155
|
-
inputField : "i_#{name}", // id of the input field
|
156
|
-
ifFormat : "%Y/%m/%d %H:%M", // format of the input field
|
157
|
-
showsTime : true, // will display a time selector
|
158
|
-
button : "s_#{name}", // trigger for the calendar (button ID)
|
159
|
-
singleClick : true, // double-click mode
|
160
|
-
step : 1 // show all years in drop-down boxes (instead of every other year as default)
|
161
|
-
});
|
162
|
-
</script>
|
163
|
-
</input>
|
164
|
-
EOS
|
165
|
-
end
|
166
|
-
return r
|
167
|
-
end
|
168
|
-
|
169
|
-
# select date.. no time
|
170
|
-
def fe_date(name, v,enabled)
|
171
|
-
v = Time.now unless v
|
172
|
-
r = <<-EOS
|
173
|
-
<input type='text' name='#{name}' id='i_#{name}' value='#{v.year}/#{twodig(v.month)}/#{twodig(v.day)}' #{'disabled' unless enabled}>
|
174
|
-
EOS
|
175
|
-
if enabled then
|
176
|
-
r << <<-EOS
|
177
|
-
<input type='submit' id='s_#{name}' value='...'>
|
178
|
-
<script type="text/javascript">
|
179
|
-
Calendar.setup({
|
180
|
-
inputField : "i_#{name}", // id of the input field
|
181
|
-
ifFormat : "%Y/%m/%d", // format of the input field
|
182
|
-
showsTime : false, // will display a time selector
|
183
|
-
button : "s_#{name}", // trigger for the calendar (button ID)
|
184
|
-
singleClick : true, // double-click mode
|
185
|
-
step : 1 // show all years in drop-down boxes (instead of every other year as default)
|
186
|
-
});
|
187
|
-
</script>
|
188
|
-
</input>
|
189
|
-
EOS
|
190
|
-
end
|
191
|
-
return r
|
192
|
-
end
|
193
|
-
|
194
|
-
def fe_bool(name,v,enabled)
|
195
|
-
r = ''
|
196
|
-
r << "<select name='#{name}' #{'disabled' unless enabled}>\n"
|
197
|
-
r << "<option #{"selected" if v} value='t'>true</option>\n"
|
198
|
-
r << "<option #{"selected" if !v} value='f'>false</option>\n"
|
199
|
-
r << "</select>\n"
|
200
|
-
end
|
201
|
-
|
202
|
-
def fe_int(name,v,enabled)
|
203
|
-
"<input type='text' name='#{name}' value='#{v}' #{'disabled' unless enabled} size=5>"
|
204
|
-
end
|
205
|
-
|
206
|
-
def fe(type, name, value='')
|
207
|
-
return '' if field_hidden?(name)
|
208
|
-
enabled = field_enable?(name)
|
209
|
-
r = ""
|
210
|
-
case(type)
|
211
|
-
when :string
|
212
|
-
r << fe_text(name,value,enabled)
|
213
|
-
when :boolean
|
214
|
-
r << fe_bool(name,value,enabled)
|
215
|
-
when :integer
|
216
|
-
r << fe_int(name,value,enabled)
|
217
|
-
when :datetime
|
218
|
-
r << fe_datetime(name,value,enabled)
|
219
|
-
when :date
|
220
|
-
r << fe_date(name,value,enabled)
|
221
|
-
when :password
|
222
|
-
r << fe_password(name, enabled)
|
223
|
-
end
|
224
|
-
return r
|
225
|
-
end
|
226
|
-
|
227
|
-
# build a form element for column name
|
228
|
-
def fe_for(column_name, hint='')
|
229
|
-
col = @model.column_for_attribute(column_name)
|
230
|
-
fe(col.type, col.name, @model.send(column_name.intern))
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
# you might want to replace this method
|
235
|
-
public
|
236
|
-
def form
|
237
|
-
r = mabtext { FormErrors(@form_errors) }
|
238
|
-
r << "<form action='#{@post_to}' method='POST'>\n"
|
239
|
-
r << "<table>"
|
240
|
-
@model.class.columns.each do |col|
|
241
|
-
next if field_hidden?(col.name)
|
242
|
-
k = col.name
|
243
|
-
v = @model.send(k.intern) # this allows us to overwrite accessors
|
244
|
-
r << "<tr><td>#{k}</td><td>#{fe(col.type,k,v)}</td></tr>"
|
245
|
-
end
|
246
|
-
r << "<tr><td><br/></td></tr>"
|
247
|
-
r << "<tr><td></td><td><input type='submit' value=#{@model.new_record? ? 'Save' : 'Update'} name='#{@submit_name}'></td></tr>"
|
248
|
-
r << "</table>\n</form>\n"
|
249
|
-
@_content = r
|
250
|
-
end
|
251
|
-
|
252
|
-
|
253
|
-
end
|
254
|
-
|