cuca 0.07 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +10 -0
  3. data/README.md +51 -0
  4. data/application_skeleton/app/test.rb +16 -0
  5. data/application_skeleton/conf/config.rb +8 -1
  6. data/application_skeleton/public/dispatch-fwdev.cgi +3 -1
  7. data/application_skeleton/public/dispatch.cgi +1 -1
  8. data/application_skeleton/public/dispatch.fcgi +1 -1
  9. data/application_skeleton/scripts/server-lighttpd-fcgi.rb +43 -4
  10. data/application_skeleton/scripts/server-lighttpd.rb +58 -5
  11. data/application_skeleton/scripts/server-webrick.rb +1 -1
  12. data/application_skeleton/tests/functional/basic.rb +32 -0
  13. data/bin/cuca +7 -3
  14. data/lib/cuca.rb +1 -1
  15. data/lib/cuca/app.rb +44 -31
  16. data/lib/cuca/cgi_emu.rb +17 -6
  17. data/lib/cuca/const.rb +1 -1
  18. data/lib/cuca/controller.rb +0 -2
  19. data/lib/cuca/generator/view.rb +7 -5
  20. data/lib/cuca/mimetypes.rb +2 -0
  21. data/lib/cuca/sessionpage.rb +18 -4
  22. data/lib/cuca/stdlib/README +2 -0
  23. data/lib/cuca/stdlib/form.rb +1 -1
  24. data/lib/cuca/stdlib/listwidget/dblist.rb +13 -2
  25. data/lib/cuca/stdlib/listwidget/querydef.rb +11 -17
  26. data/lib/cuca/test/helpers.rb +55 -2
  27. data/lib/cuca/urlmap.rb +18 -9
  28. data/tests/all.rb +4 -1
  29. data/tests/controller.rb +26 -9
  30. data/tests/test_app/app/test.rb +0 -0
  31. data/tests/urlmap.rb +7 -0
  32. data/tests/widget.rb +2 -2
  33. metadata +106 -128
  34. data/README +0 -43
  35. data/application_skeleton/public/dispatch.cgi-old +0 -18
  36. data/application_skeleton/public/dispatch.fcgi-old +0 -25
  37. data/application_skeleton/scripts/rack-test.rb +0 -52
  38. data/application_skeleton/scripts/server-rack-thin.rb +0 -40
  39. data/application_skeleton/scripts/server-rack-webrick.rb +0 -22
  40. data/lib/cuca/stdlib/old_arform.rb +0 -254
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2642f8b68bb957ae09ac2c04c73533bb3812d15a
4
+ data.tar.gz: 13ddcc6f74af2fc5efb19c513caabc89eb9256c1
5
+ SHA512:
6
+ metadata.gz: 5d2e104a1abbb3a428c34c20cf10b5fe6618c159fd855829466f84123e6b63211536acc4e081d2892aa60552651346f00330cded2c37121ac9fd8e592289eccb
7
+ data.tar.gz: 4b4e8e0d019ffd3290805571faef4bbe3f34af5494972bde6f4d5fc12cfb123d22390f70c6d0e5dd825ac9b80feaeae037dabce54bd9ba430be4f8f8572462f7
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ * 2014/12/31 - 0.11
2
+ - Few fixes & cleanup
3
+ - Ruby 2.1.0 support
4
+
5
+ * 2013/xx/xx - 0.10
6
+ - Ruby 1.9 support
7
+ - functional tests
8
+
9
+ * 2009 - 2013 ... big gap of changes done without publishing anything... ;)
10
+
1
11
  * 2009/xx/xx - 0.07
2
12
  - 'stop' option :cancel_execution added. This can be raised in before filters
3
13
  and will avoid that the run/get/post... methods are called.
@@ -0,0 +1,51 @@
1
+ # Cuca - a web application framework
2
+
3
+ Cuca is another web application framework written in Ruby. It's made to
4
+ build applications with focus on functionality - less design. You can
5
+ create and application without writing HTML. Once written Widgets
6
+ (a smart screen element) can be reused thorough your project with
7
+ minimum effort allowing to build fast and secure web applications.
8
+
9
+ It implements the following concepts:
10
+ * A Widget is a screen element. Can be a full page or part of it.
11
+ The Controller and the Layout are Widgets, too.
12
+ * A Controller deals with one request URI (get, post or both) and can set variables
13
+ other widgets can make use of. It can also define a Layout and filters.
14
+ * A Layout wraps the output of a controller and finally return the
15
+ built web page.
16
+ * A Generator (NOT "code generator") can be used within any Widget to help building the web content.
17
+ Cuca comes with a Markaby and eruby Generator.
18
+ * A Session can used optionally to keep stateful data.
19
+
20
+ Cuca was written for internal use in 2008 and as per 2013 we keep using and improving it.
21
+
22
+ ### It implements the following concepts:
23
+ * A Widget is a screen element. Can be a full page or part of it.
24
+ The Controller and the Layout are Widgets, too.
25
+ * A Controller deals with one request URI (get, post or both) and can set variables
26
+ other widgets can make use of. It can also define a Layout and filters.
27
+ * A Layout wraps the output of a controller and finally return the
28
+ built web page.
29
+ * A Generator (NOT "code generator") can be used within any Widget to help building the web content.
30
+ Cuca comes with a Markaby and eruby Generator.
31
+ * A Session can used optionally to keep stateful data.
32
+
33
+ ## Installation & Getting started
34
+
35
+ Download and install from the internet:
36
+
37
+ gem install --remote cuca
38
+
39
+ ## Create an application skeleton:
40
+
41
+ cuca my_project # this will create a new project
42
+ cd my_project
43
+ ruby ./script/server-webrick.rb
44
+
45
+ Open http://localhost:2000/
46
+
47
+
48
+ ## Read on
49
+
50
+ Check the rdoc once installed
51
+
@@ -0,0 +1,16 @@
1
+
2
+
3
+ class TestController < ApplicationController
4
+
5
+ def get
6
+ @_content = 'GET: '
7
+ @_content << query_parameters.inspect
8
+ end
9
+
10
+ def post
11
+ @_content = "POST: "
12
+ @_content << request_parameters.inspect
13
+ end
14
+
15
+ end
16
+
@@ -24,6 +24,9 @@ Cuca::App.configure do |config|
24
24
  ### in lower levels of your directory layout.
25
25
  config.include_directories = %w{_controllers _layouts _models _widgets}
26
26
 
27
+ # How to name the controller class in a file (make sure this matches include_directories if you want autoload
28
+ # config.controller_naming = lambda { |f| f.capitalize+"Controller" } # <= the default
29
+
27
30
  ### This would be an autoload configuration
28
31
  # config.include_directories = [
29
32
  # { :dir => '_controllers', :class_naming => lambda { |f| f.capitalize+'Controller' } },
@@ -42,7 +45,11 @@ Cuca::App.configure do |config|
42
45
 
43
46
  ### the view generator will look for external templates here:
44
47
  # config.view_directory = 'app/_views'
45
-
48
+
49
+ ### Force encoding of views to this one, if undefined default external
50
+ ### encoding will be used. Encoding name must be accepted by Ruby Encoding class
51
+ # config.view_encoding = 'UTF-8'
52
+
46
53
  ### 404 (file not found) and 500 system error page (relative to the public folder)
47
54
  # config.http_404 = '404.html'
48
55
  # config.http_500 = '500.html'
@@ -1,5 +1,7 @@
1
- #!/usr/bin/ruby1.9.1
1
+ #!/usr/bin/env ruby
2
2
 
3
+
4
+ ### Define framework path
3
5
  FRAMEWORK_PATH = '/home/bones/workspace/cuca_svn/cuca/lib'
4
6
 
5
7
  $cuca_path = File.dirname(__FILE__)+"/../"
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby1.9
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  $cuca_path = File.dirname(__FILE__)+"/../"
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
 
4
4
  $cuca_path = File.dirname(__FILE__)+"/../"
@@ -1,13 +1,52 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This will create a simple FastCGI lighttpd config file and run against the cuca application
4
+ #
5
+
6
+ require 'ostruct'
7
+ require 'optparse'
8
+
9
+ options = OpenStruct.new
10
+ options.dispatcher = 'dispatch.fcgi'
11
+ options.port = 2000
12
+ options.lighttpd = 'lighttpd'
13
+
14
+ op = OptionParser.new do |opts|
15
+ opts.banner = "Usage: server-lighttpd-fcgi.rb [options]"
16
+ opts.on("-pPORT", "--port=NAME", "TCP Port to listen on (2000)") do |x|
17
+ options.port = x
18
+ end
19
+
20
+ opts.on("-lPROGRAM", "--lighttpd=PROGRAM", "The lighttpd binary (/usr/sbin/lighttpd)") do |d|
21
+ options.lighttpd = d
22
+ end
23
+
24
+ opts.on("-dDISPATCHER", "--dispatcher=DISPATCHER", "The cgi program in public/ directory (dispatch.cgi)") do |d|
25
+ options.dispatcher = d
26
+ end
27
+ opts.on("-h", "--help", "Help") do
28
+ puts opts
29
+ exit 0
30
+ end
31
+ end.parse!(ARGV)
32
+
33
+
34
+ cuca_path = File.expand_path(File.dirname(__FILE__))+"/../"
35
+
36
+ if !File.exist?(cuca_path + "/public/" + options.dispatcher) then
37
+ STDERR.puts "Can't find dispatcher #{options.dispatcher} in public directory, use -d"
38
+ exit 1
39
+ end
40
+
2
41
 
3
42
  cuca_path = File.expand_path(File.dirname(__FILE__)+"/../")
4
43
  document_root = "#{cuca_path}/public/"
5
44
  error_log = "#{cuca_path}/log/error.log"
6
45
  access_log = "#{cuca_path}/log/access.log"
7
46
  pid_file = '/tmp/lighttpd.pid'
8
- dispatcher = "dispatch.fcgi"
9
- server_port = 2000
10
- server_program = "/usr/sbin/lighttpd"
47
+ dispatcher = options.dispatcher
48
+ server_port = options.port
49
+ server_program = options.lighttpd
11
50
 
12
51
  config = <<-EOF
13
52
 
@@ -1,12 +1,65 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This will create a simple CGI lighttpd config file and run against the cuca application
4
+ #
5
+ # Takes one optional argument the full path the the ruby interpreter to use
6
+ #
7
+
8
+ require 'ostruct'
9
+ require 'optparse'
10
+
11
+ options = OpenStruct.new
12
+ options.ruby_interpreter = '/usr/bin/ruby'
13
+ options.dispatcher = 'dispatch.cgi'
14
+ options.port = 2000
15
+ options.lighttpd = 'lighttpd'
16
+
17
+ op = OptionParser.new do |opts|
18
+ opts.banner = "Usage: server-lighttpd.rb [options]"
19
+ opts.on("-pPORT", "--port=NAME", "TCP Port to listen on (2000)") do |x|
20
+ options.port = x
21
+ end
22
+ opts.on("-iRUBY", "--interpreter=RUBY", "The ruby binary (/usr/bin/ruby)") do |d|
23
+ options.ruby_interpreter = d
24
+ end
25
+ opts.on("-lPROGRAM", "--lighttpd=PROGRAM", "The lighttpd binary (/usr/sbin/lighttpd)") do |d|
26
+ options.lighttpd = d
27
+ end
28
+
29
+ opts.on("-dDISPATCHER", "--dispatcher=DISPATCHER", "The cgi program in public/ directory (dispatch.cgi)") do |d|
30
+ options.dispatcher = d
31
+ end
32
+ opts.on("-h", "--help", "Help") do
33
+ puts opts
34
+ exit 0
35
+ end
36
+ end.parse!(ARGV)
37
+
38
+
39
+ if !File.exist?(options.ruby_interpreter) then
40
+ STDERR.puts "Can't find ruby interpreter, use -i"
41
+ exit 1
42
+ end
43
+
44
+ #if !File.exist?(options.lighttpd) then
45
+ # STDERR.puts "Can't find lighttpd binary use -l"
46
+ # exit 1
47
+ #end
2
48
 
3
49
  cuca_path = File.expand_path(File.dirname(__FILE__))+"/../"
50
+
51
+ if !File.exist?(cuca_path + "/public/" + options.dispatcher) then
52
+ STDERR.puts "Can't find dispatcher #{options.dispatcher} in public directory, use -d"
53
+ exit 1
54
+ end
55
+
56
+
4
57
  document_root = "#{cuca_path}/public/"
5
58
  error_log = "#{cuca_path}/log/error.log"
6
59
  access_log = "#{cuca_path}/log/access.log"
7
60
  pid_file = '/tmp/lighttpd.pid'
8
- server_program = "/usr/sbin/lighttpd"
9
- server_port = 2000
61
+ server_program = options.lighttpd
62
+ server_port = options.port
10
63
 
11
64
  config = <<-EOF
12
65
 
@@ -17,7 +70,7 @@ server.modules = (
17
70
  "mod_cgi"
18
71
  )
19
72
 
20
- cgi.assign = ( ".cgi" => "/usr/bin/ruby" )
73
+ cgi.assign = ( ".cgi" => "#{options.ruby_interpreter}" )
21
74
 
22
75
  server.document-root = "#{document_root}"
23
76
 
@@ -25,7 +78,7 @@ server.port = #{server_port}
25
78
 
26
79
  server.errorlog = "#{error_log}"
27
80
 
28
- server.error-handler-404 = "/dispatch.cgi"
81
+ server.error-handler-404 = "/#{options.dispatcher}"
29
82
  # server.error-handler-404 = "/error-404.html"
30
83
 
31
84
  index-file.names = ( "index.html" )
@@ -20,7 +20,7 @@ class CucaHandler < WEBrick::HTTPServlet::CGIHandler
20
20
  end
21
21
 
22
22
  server = WEBrick::HTTPServer.new(:Port => 2000)
23
- server.mount("/", CucaHandler, File.expand_path(File.dirname(__FILE__))+"/../public/dispatch-fwdev.cgi")
23
+ server.mount("/", CucaHandler, File.expand_path(File.dirname(__FILE__))+"/../public/dispatch.cgi")
24
24
 
25
25
  trap("INT"){ server.shutdown }
26
26
  server.start
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+
3
+ $cuca_path = File.dirname(__FILE__)+"/../../"
4
+
5
+ require 'cuca'
6
+ require 'cuca/test/helpers'
7
+
8
+ class TC_TestWidget < Test::Unit::TestCase
9
+
10
+ include Cuca::Test::Helpers
11
+
12
+ def test_index
13
+ # x = get('/index', { :test => 'me' })
14
+ # puts x.inspect
15
+
16
+ # x = get('/test')
17
+ # puts x.inspect
18
+
19
+ x = post('/test')
20
+ puts x.inspect
21
+ puts
22
+ puts
23
+ x = post('/test', { :post_var => 'post_value' } )
24
+ puts x.inspect
25
+ puts
26
+ puts
27
+
28
+
29
+ end
30
+
31
+ end
32
+
data/bin/cuca CHANGED
@@ -3,7 +3,11 @@
3
3
  # This is a simple script to install the cuca application skeleton
4
4
  # provided by the cuca gems.
5
5
  #
6
- require 'ftools'
6
+ begin
7
+ require 'ftools'
8
+ rescue LoadError
9
+ end
10
+
7
11
  require 'fileutils'
8
12
 
9
13
  if ARGV.size == 0 then
@@ -29,12 +33,12 @@ Dir.glob("#{framework_path}/**/*").each do |file|
29
33
 
30
34
  if File.directory?(file) then
31
35
  puts "(mkdir) #{fname}"
32
- File.makedirs(dname)
36
+ FileUtils.mkdir_p(dname)
33
37
  next
34
38
  end
35
39
 
36
40
  puts "(install) #{fname}"
37
- File.install(file, dname)
41
+ FileUtils.install(file, dname)
38
42
 
39
43
  if fname.include?('/scripts/server') || fname.include?('/public/dispatch') || fname.include?('/scripts/console') then
40
44
  puts "(chmod) #{fname} (755)"
@@ -19,7 +19,7 @@ end
19
19
  def init_save_require(filename)
20
20
  begin
21
21
  require filename
22
- rescue => e
22
+ rescue LoadError => e
23
23
  title = "INIT Error [#{filename}]: #{e}"
24
24
  $stderr.puts title
25
25
  err = ''
@@ -5,7 +5,7 @@ require 'cuca/config'
5
5
  def cuca_register_autoload(object, file)
6
6
  autoload(object, file)
7
7
  end
8
-
8
+
9
9
 
10
10
  module Cuca
11
11
 
@@ -21,16 +21,24 @@ class Sandbox
21
21
  controller_class = mod::const_get(controller_class_name)
22
22
  controller = controller_class.send(:new, :assigns=>assigns)
23
23
  $controller_object = controller
24
-
25
- controller.run_before_filters
26
24
 
25
+ controller.run_before_filters
27
26
 
28
- controller.send('_do'.intern, 'run', subcall)
29
27
  case request_method
30
- when 'POST'
28
+ when 'POST'
29
+ controller.send('_do'.intern, 'run', subcall)
31
30
  controller.send('_do'.intern, 'post', subcall)
32
- when 'GET'
31
+ when 'GET'
32
+ controller.send('_do'.intern, 'run', subcall)
33
33
  controller.send('_do'.intern, 'get', subcall)
34
+ when 'PUT'
35
+ controller.send('_do'.intern, 'put', subcall)
36
+ when 'PATCH'
37
+ controller.send('_do'.intern, 'patch', subcall)
38
+ when 'HEAD'
39
+ controller.send('_do'.intern, 'head', subcall)
40
+ when 'DELETE'
41
+ controller.send('_do'.intern, 'delete', subcall)
34
42
  end
35
43
 
36
44
  controller.run_after_filters
@@ -40,11 +48,11 @@ class Sandbox
40
48
  end
41
49
 
42
50
  # == Cuca Application
43
- #
44
- # A Cuca::App object will be created directly by the dispatcher - which again is the
51
+ #
52
+ # A Cuca::App object will be created directly by the dispatcher - which again is the
45
53
  # direct cgi or fastcgi script that get run by the webserver.
46
- # Normally you just create a Cuca::App object and run the cgicall method with optional with
47
- # a cgi object as paramenter.
54
+ # Normally you just create a Cuca::App object and run the cgicall method with optional with
55
+ # a cgi object as paramenter.
48
56
  # Before doing that you must set $cuca_path to the root of your application directory structure.
49
57
  class App
50
58
 
@@ -72,7 +80,7 @@ class App
72
80
  @public_path.freeze
73
81
  @log_path.freeze
74
82
  @logger = Logger.new("#{@log_path}/messages")
75
- @logger.level = App::config['logger_level'] || Logger::WARN
83
+ @logger.level = App.config['log_level'] || Logger::WARN
76
84
  end
77
85
 
78
86
 
@@ -82,7 +90,7 @@ class App
82
90
  private
83
91
  def init_call(path_info)
84
92
  require 'cuca/urlmap'
85
-
93
+
86
94
  begin
87
95
  @urlmap = URLMap.new(@app_path, path_info)
88
96
 
@@ -91,7 +99,7 @@ class App
91
99
  return
92
100
  end
93
101
  end
94
-
102
+
95
103
  # will do a 'require' on all .rb files in path
96
104
  private
97
105
  def include_files(path)
@@ -131,13 +139,13 @@ class App
131
139
  def all_support_directories(path_tree)
132
140
  path_tree.each do |t|
133
141
  (App::config['include_directories'] || []).each do |id|
134
- if id.instance_of?(Hash) then
142
+ if id.instance_of?(Hash) then
135
143
  yield "#{t}/#{id[:dir]}", id[:class_naming]
136
- else
144
+ else
137
145
  yield "#{t}/#{id}", nil
138
146
  end
139
147
  end
140
- end
148
+ end
141
149
  end
142
150
 
143
151
  public
@@ -147,7 +155,7 @@ class App
147
155
  autoload_files(dir, proc)
148
156
  else
149
157
  include_files(dir)
150
- end
158
+ end
151
159
  end
152
160
  end
153
161
 
@@ -176,7 +184,7 @@ class App
176
184
  public
177
185
  def cgicall(cgi = nil)
178
186
  @cgi = cgi || CGI.new
179
-
187
+
180
188
  #
181
189
  # 1st priority: Serve a file if it exists in the 'public' folder
182
190
  #
@@ -224,8 +232,12 @@ class App
224
232
  load_support_files(@urlmap)
225
233
 
226
234
  # 4th: Now let's run the actual page script code
227
- controller_class_name = @urlmap.action.capitalize+"Controller"
228
-
235
+ if Cuca::App.config['controller_naming'] then
236
+ controller_class_name = Cuca::App.config['controller_naming'].call(@urlmap.action)
237
+ else
238
+ controller_class_name = @urlmap.action.capitalize+"Controller"
239
+ end
240
+
229
241
  # Clear all hints
230
242
  Widget::clear_hints()
231
243
 
@@ -237,13 +249,13 @@ class App
237
249
  begin
238
250
  # load controller
239
251
  begin
240
- controller_module.module_eval(File.open(script).read, script) unless \
252
+ controller_module.module_eval(File.read(script), script) unless \
241
253
  controller_module.const_defined?(controller_class_name.intern)
242
- rescue SyntaxError => e
243
- err = get_error("Load Error", e,
254
+ rescue SyntaxError,LoadError => e
255
+ err = get_error("Can not load script", e,
244
256
  Cuca::App.config['display_errors'], Cuca::App.config['http_500'])
245
257
  @cgi.out('status' => 'SERVER_ERROR') { err }
246
- return
258
+ return
247
259
  end
248
260
 
249
261
  # Catch a common user error
@@ -252,12 +264,13 @@ class App
252
264
 
253
265
 
254
266
  # run controller
255
- (status, mime, content, headers) = Sandbox.run(controller_class_name,
256
- @urlmap.action_module, @urlmap.assigns,
267
+ (status, mime, content, headers) = Sandbox.run(controller_class_name,
268
+ @urlmap.action_module, @urlmap.assigns,
257
269
  @cgi.request_method, @urlmap.subcall)
258
270
 
259
271
  logger.debug "CGICall OK: #{status}/#{mime}"
260
-
272
+
273
+
261
274
  @cgi.out(headers.merge( { 'type' => mime, 'status' => status} )) {content}
262
275
 
263
276
  rescue SyntaxError => e
@@ -267,7 +280,7 @@ class App
267
280
 
268
281
  logger.info "CGICall Syntax Error"
269
282
  return
270
-
283
+
271
284
 
272
285
  rescue Cuca::ApplicationException => e
273
286
  err = get_error("Application Error", e,
@@ -278,13 +291,13 @@ class App
278
291
  return
279
292
 
280
293
  rescue => e
281
- err = get_error("System Error", e,
294
+ err = get_error("System Error", e,
282
295
  Cuca::App.config['display_errors'], Cuca::App.config['http_500'])
283
296
  @cgi.out('status' => 'SERVER_ERROR') { err }
284
297
 
285
298
  logger.info "CGICall System Error"
286
- return
287
-
299
+ return
300
+
288
301
  end
289
302
  end
290
303