nitro 0.8.0 → 0.9.3
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.
- data/AUTHORS +3 -4
- data/ChangeLog +418 -0
- data/LICENSE +1 -1
- data/README +157 -89
- data/RELEASES +50 -0
- data/Rakefile +5 -7
- data/benchmark/nitro/bench.rb +5 -0
- data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
- data/benchmark/nitro/static-webrick-n-200.txt +43 -0
- data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
- data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
- data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
- data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
- data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
- data/bin/proto/README +2 -2
- data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
- data/bin/proto/conf/app.conf.rb +22 -0
- data/bin/proto/conf/lhttpd.conf +236 -0
- data/bin/proto/ctl +4 -0
- data/bin/proto/lib/README +5 -0
- data/bin/proto/log/README +3 -0
- data/bin/proto/root/fcgi.rb +6 -0
- data/bin/proto/root/index.xhtml +65 -7
- data/bin/proto/root/m/nitro.png +0 -0
- data/examples/blog/README +7 -5
- data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
- data/examples/blog/conf/app.conf.rb +56 -0
- data/examples/blog/conf/lhttpd.conf +236 -0
- data/examples/blog/ctl +4 -0
- data/examples/blog/lib/blog.rb +11 -136
- data/examples/blog/lib/blog/controller.rb +99 -0
- data/examples/blog/lib/blog/model.rb +39 -0
- data/examples/blog/log/README +3 -0
- data/examples/blog/root/comments.xhtml +2 -2
- data/examples/blog/root/fcgi.rb +6 -0
- data/examples/blog/root/index.xhtml +4 -5
- data/examples/blog/root/login.xhtml +2 -2
- data/examples/blog/root/style.xsl +9 -9
- data/examples/blog/root/view_entry.xhtml +2 -2
- data/examples/flash/conf/app.conf.rb +23 -0
- data/examples/flash/ctl +4 -0
- data/examples/flash/log/README +3 -0
- data/examples/flash/root/index.xhtml +0 -9
- data/examples/flash/root/show_inline_text.xhtml +10 -5
- data/examples/no_xsl_blog/README +12 -0
- data/examples/no_xsl_blog/conf/apache.conf +0 -0
- data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
- data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
- data/examples/no_xsl_blog/ctl +4 -0
- data/examples/no_xsl_blog/lib/blog.rb +20 -0
- data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
- data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
- data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
- data/examples/no_xsl_blog/log/README +3 -0
- data/examples/no_xsl_blog/root/comments.xhtml +41 -0
- data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
- data/examples/no_xsl_blog/root/fcgi.rb +6 -0
- data/examples/no_xsl_blog/root/index.xhtml +39 -0
- data/examples/no_xsl_blog/root/login.xhtml +21 -0
- data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
- data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
- data/examples/no_xsl_blog/root/m/down.gif +0 -0
- data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
- data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
- data/examples/no_xsl_blog/root/m/obull.gif +0 -0
- data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/rss.gif +0 -0
- data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
- data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
- data/examples/no_xsl_blog/root/style.css +301 -0
- data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
- data/examples/no_xsl_blog/root/view_entry.xml +12 -0
- data/examples/og/run.rb +2 -2
- data/examples/tiny/README +2 -2
- data/examples/tiny/conf/apache.conf +5 -0
- data/examples/tiny/conf/app.conf.rb +21 -0
- data/examples/tiny/conf/lhttpd.conf +236 -0
- data/examples/tiny/ctl +4 -0
- data/examples/tiny/log/README +3 -0
- data/examples/tiny/root/fcgi.rb +6 -0
- data/examples/tiny/root/index.xhtml +7 -4
- data/examples/tiny/root/nitro.png +0 -0
- data/lib/glue.rb +13 -9
- data/lib/glue/array.rb +1 -1
- data/lib/glue/cache.rb +1 -1
- data/lib/glue/flexob.rb +12 -0
- data/lib/glue/hash.rb +1 -1
- data/lib/glue/inflector.rb +2 -2
- data/lib/glue/logger.rb +4 -8
- data/lib/glue/misc.rb +14 -0
- data/lib/glue/number.rb +1 -1
- data/lib/glue/object.rb +26 -0
- data/lib/glue/pool.rb +1 -1
- data/lib/glue/property.rb +84 -91
- data/lib/glue/string.rb +1 -1
- data/lib/glue/time.rb +1 -1
- data/lib/glue/validation.rb +1 -1
- data/lib/nitro.rb +18 -6
- data/lib/nitro/adaptors/cgi.rb +291 -0
- data/lib/nitro/adaptors/fastcgi.rb +42 -0
- data/lib/nitro/adaptors/runner.rb +123 -0
- data/lib/nitro/adaptors/webrick.rb +110 -0
- data/lib/nitro/buffering.rb +43 -0
- data/lib/nitro/builders/form.rb +1 -1
- data/lib/nitro/builders/rss.rb +1 -1
- data/{bin → lib/nitro}/cluster.rb +26 -30
- data/lib/nitro/context.rb +82 -0
- data/lib/nitro/controller.rb +50 -0
- data/lib/nitro/cookie.rb +46 -0
- data/lib/nitro/dispatcher.rb +105 -0
- data/lib/nitro/filters.rb +9 -10
- data/lib/nitro/localization.rb +42 -0
- data/lib/nitro/mail.rb +11 -14
- data/lib/nitro/render.rb +275 -0
- data/lib/nitro/request.rb +128 -0
- data/lib/nitro/response.rb +38 -0
- data/lib/nitro/scaffold.rb +11 -11
- data/lib/nitro/session.rb +84 -0
- data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
- data/lib/nitro/ui/pager.rb +23 -26
- data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
- data/lib/nitro/uri.rb +1 -1
- data/lib/nitro/version.rb +10 -8
- data/lib/og.rb +66 -65
- data/lib/og/backend.rb +1 -1
- data/lib/og/backends/mysql.rb +48 -52
- data/lib/og/backends/psql.rb +34 -37
- data/lib/og/connection.rb +15 -15
- data/lib/og/enchant.rb +16 -9
- data/lib/og/meta.rb +127 -54
- data/lib/og/mock.rb +18 -18
- data/lib/og/version.rb +6 -4
- data/lib/parts/content.rb +4 -8
- data/test/glue/tc_logger.rb +3 -0
- data/test/glue/tc_property.rb +19 -3
- data/test/nitro/adaptors/tc_cgi.rb +63 -0
- data/test/nitro/adaptors/tc_webrick.rb +15 -0
- data/test/nitro/builders/tc_xml.rb +2 -2
- data/test/nitro/tc_context.rb +13 -0
- data/test/nitro/tc_controller.rb +47 -0
- data/test/nitro/tc_dispatcher.rb +64 -0
- data/test/nitro/tc_session.rb +20 -0
- data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
- data/test/root/blog/list.xhtml +6 -0
- data/test/tc_og.rb +41 -4
- metadata +115 -59
- data/bin/proto/app.rb +0 -20
- data/bin/proto/config.rb +0 -77
- data/examples/blog/app.rb +0 -21
- data/examples/blog/config.rb +0 -95
- data/examples/blog/env.rb +0 -22
- data/examples/flash/README +0 -34
- data/examples/flash/app.rb +0 -20
- data/examples/flash/config.rb +0 -38
- data/examples/flash/lib/flash.rb +0 -40
- data/examples/flash/tmp.swf +0 -0
- data/examples/tiny/app.rb +0 -19
- data/examples/tiny/config.rb +0 -29
- data/examples/tiny/root/nitro-small.png +0 -0
- data/lib/nitro/application.rb +0 -217
- data/lib/nitro/config.rb +0 -128
- data/lib/nitro/events.rb +0 -122
- data/lib/nitro/html.rb +0 -151
- data/lib/nitro/http.rb +0 -102
- data/lib/nitro/l10n.rb +0 -30
- data/lib/nitro/server.rb +0 -59
- data/lib/nitro/server/appserver.rb +0 -67
- data/lib/nitro/server/cookie.rb +0 -87
- data/lib/nitro/server/dispatcher.rb +0 -62
- data/lib/nitro/server/filters.rb +0 -75
- data/lib/nitro/server/filters/autologin.rb +0 -51
- data/lib/nitro/server/fragment.rb +0 -70
- data/lib/nitro/server/handlers.rb +0 -127
- data/lib/nitro/server/render.rb +0 -426
- data/lib/nitro/server/request.rb +0 -658
- data/lib/nitro/server/requestpart.rb +0 -54
- data/lib/nitro/server/script.rb +0 -387
- data/lib/nitro/server/server.rb +0 -57
- data/lib/nitro/server/session.rb +0 -220
- data/lib/nitro/server/user.rb +0 -46
- data/lib/nitro/server/webrick.rb +0 -180
- data/lib/nitro/service.rb +0 -26
- data/lib/xsl/ui.xsl +0 -51
- data/lib/xsl/xforms.xsl +0 -28
- data/test/nitro/server/tc_cookie.rb +0 -34
- data/test/nitro/server/tc_filters.rb +0 -38
- data/test/nitro/server/tc_request.rb +0 -70
- data/test/nitro/server/tc_requestpart.rb +0 -28
- data/test/nitro/server/tc_session.rb +0 -34
- data/test/nitro/tc_events.rb +0 -44
- data/test/nitro/tc_html.rb +0 -79
- data/test/nitro/tc_http.rb +0 -18
data/examples/blog/app.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby
|
|
2
|
-
|
|
3
|
-
# = Blog
|
|
4
|
-
#
|
|
5
|
-
# A simple Blog powered by Nitro.
|
|
6
|
-
#
|
|
7
|
-
# code:
|
|
8
|
-
# * George Moschovitis <gm@navel.gr>
|
|
9
|
-
#
|
|
10
|
-
# (c) 2004 Navel, all rights reserved.
|
|
11
|
-
# $Id: app.rb 197 2004-12-21 13:50:17Z gmosx $
|
|
12
|
-
|
|
13
|
-
# set to true for DEBUG mode.
|
|
14
|
-
$DBG = true
|
|
15
|
-
|
|
16
|
-
$LOAD_PATH.unshift "../../lib"
|
|
17
|
-
$LOAD_PATH.unshift "../../vendor"
|
|
18
|
-
|
|
19
|
-
require "config"
|
|
20
|
-
|
|
21
|
-
$app = N::WebrickServer.new.exec()
|
data/examples/blog/config.rb
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# = Blog Configuration
|
|
2
|
-
#
|
|
3
|
-
# You can find additional configuration variables in
|
|
4
|
-
# lib/n/config.rb. Just copy the variables you want to
|
|
5
|
-
# change in this file
|
|
6
|
-
#
|
|
7
|
-
# WARNING: if you want to change the backend dont forget
|
|
8
|
-
# to change it in the DEBUG and LIVE configurations.
|
|
9
|
-
#--
|
|
10
|
-
# George Moschovitis <gm@navel.gr>
|
|
11
|
-
# (c) 2004 Navel, all rights reserved.
|
|
12
|
-
# $Id: config.rb 197 2004-12-21 13:50:17Z gmosx $
|
|
13
|
-
#++
|
|
14
|
-
|
|
15
|
-
require 'nitro'
|
|
16
|
-
require 'glue/logger'
|
|
17
|
-
require 'glue/validation'
|
|
18
|
-
require 'nitro/config'
|
|
19
|
-
|
|
20
|
-
require 'og'
|
|
21
|
-
require 'nitro/markup'
|
|
22
|
-
require 'nitro/l10n'
|
|
23
|
-
require 'nitro/events'
|
|
24
|
-
require 'glue/mixins'
|
|
25
|
-
require 'nitro/sitemap'
|
|
26
|
-
|
|
27
|
-
require 'glue/number'
|
|
28
|
-
require 'glue/string'
|
|
29
|
-
require 'glue/array'
|
|
30
|
-
require 'glue/hash'
|
|
31
|
-
require 'nitro/html'
|
|
32
|
-
|
|
33
|
-
require 'nitro/server/webrick'
|
|
34
|
-
require 'nitro/server/shaders'
|
|
35
|
-
|
|
36
|
-
require 'nitro/builders/form'
|
|
37
|
-
|
|
38
|
-
require 'lib/blog'
|
|
39
|
-
|
|
40
|
-
$name = 'Nitro Blog'
|
|
41
|
-
|
|
42
|
-
$blog_username = 'George Moschovitis'
|
|
43
|
-
$blog_password = 'navelrulez'
|
|
44
|
-
|
|
45
|
-
$services = {
|
|
46
|
-
:index => N::BlogService
|
|
47
|
-
# 'users' => N::UsersService
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
$srv_address = $appsrv_address = "127.0.0.1"
|
|
51
|
-
$srv_url = "http://#$srv_address:#$srv_port"
|
|
52
|
-
|
|
53
|
-
if $DBG # DEBUG mode
|
|
54
|
-
|
|
55
|
-
$og = Og::Database.new(
|
|
56
|
-
:address => "localhost",
|
|
57
|
-
# :backend => "mysql",
|
|
58
|
-
:backend => "psql",
|
|
59
|
-
:database => "blog",
|
|
60
|
-
:user => "postgres",
|
|
61
|
-
:password => "navelrulez",
|
|
62
|
-
:connection_count => 3
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
# dont compress when debuging, more readable code.
|
|
66
|
-
$shader = N::XSLTShader.new("#$root_dir/style.xsl",
|
|
67
|
-
N::RubyShader.new
|
|
68
|
-
)
|
|
69
|
-
=begin
|
|
70
|
-
# lets play with the ULTRA-COOL breakpointer library.
|
|
71
|
-
require 'breakpoint'
|
|
72
|
-
Breakpoint.activate_drb
|
|
73
|
-
=end
|
|
74
|
-
|
|
75
|
-
else # LIVE mode
|
|
76
|
-
|
|
77
|
-
$appsrv_port = 8080
|
|
78
|
-
|
|
79
|
-
$og = Og::Database.new(
|
|
80
|
-
:address => "localhost",
|
|
81
|
-
# :backend => "mysql",
|
|
82
|
-
:backend => "psql",
|
|
83
|
-
:database => "blog",
|
|
84
|
-
:user => "postgres",
|
|
85
|
-
:password => "navelrulez",
|
|
86
|
-
:connection_count => 20
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
$shader = N::XSLTShader.new("#$root_dir/style.xsl",
|
|
90
|
-
N::RubyShader.new(
|
|
91
|
-
N::CompressShader.new
|
|
92
|
-
)
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
end
|
data/examples/blog/env.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# = Environment injection.
|
|
2
|
-
#
|
|
3
|
-
# Require this file in your script to gain access to the full
|
|
4
|
-
# AppServer environment. Typically used to attach an irb session to
|
|
5
|
-
# a running application process:
|
|
6
|
-
#
|
|
7
|
-
# irb -r env
|
|
8
|
-
#
|
|
9
|
-
# code:
|
|
10
|
-
# * George Moschovitis <gm@navel.gr>
|
|
11
|
-
#
|
|
12
|
-
# (c) 2004 Navel, all rights reserved.
|
|
13
|
-
# $Id: env.rb 187 2004-12-10 13:34:28Z gmosx $
|
|
14
|
-
|
|
15
|
-
$DBG = true
|
|
16
|
-
|
|
17
|
-
$LOAD_PATH.unshift '../../lib'
|
|
18
|
-
|
|
19
|
-
require 'config'
|
|
20
|
-
|
|
21
|
-
$app = N::AppServer.new.exec()
|
|
22
|
-
|
data/examples/flash/README
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
= Your application
|
|
2
|
-
|
|
3
|
-
Here comes the README file for your application.
|
|
4
|
-
|
|
5
|
-
== Configuration
|
|
6
|
-
|
|
7
|
-
Edit the file conf/webapp.rb as needed.
|
|
8
|
-
|
|
9
|
-
By default this skeleton app uses the PostgreSQL backend.
|
|
10
|
-
If you want to use a different backend dont forget to
|
|
11
|
-
change it for the DEBUG and LIVE configurations.
|
|
12
|
-
|
|
13
|
-
== Run
|
|
14
|
-
|
|
15
|
-
Exec the following command:
|
|
16
|
-
|
|
17
|
-
ruby app.rb --start
|
|
18
|
-
|
|
19
|
-
then point your browser to:
|
|
20
|
-
|
|
21
|
-
http://127.0.0.1:8080
|
|
22
|
-
|
|
23
|
-
(if you want to change the server address/port, edit the config.rb
|
|
24
|
-
file)
|
|
25
|
-
|
|
26
|
-
== Discussion
|
|
27
|
-
|
|
28
|
-
If you want to modify the skeleton app it is a nice idea to switch
|
|
29
|
-
to debug mode. Edit the following line in the file app.rb:
|
|
30
|
-
|
|
31
|
-
$DBG = true
|
|
32
|
-
|
|
33
|
-
In debug mode the view files (xhtml/xsl/etc) are automatically
|
|
34
|
-
reloaded.
|
data/examples/flash/app.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
# = YourApp
|
|
4
|
-
#
|
|
5
|
-
# A skeleton application.
|
|
6
|
-
#
|
|
7
|
-
# code:
|
|
8
|
-
# * George Moschovitis <gm@navel.gr>
|
|
9
|
-
#
|
|
10
|
-
# (c) 2004 Navel, all rights reserved.
|
|
11
|
-
# $Id: app.rb 189 2004-12-13 21:38:05Z gmosx $
|
|
12
|
-
|
|
13
|
-
# set to true for DEBUG mode.
|
|
14
|
-
$DBG = true
|
|
15
|
-
|
|
16
|
-
$LOAD_PATH.unshift '../../lib'
|
|
17
|
-
|
|
18
|
-
require 'config'
|
|
19
|
-
|
|
20
|
-
$app = N::WebrickServer.new.exec()
|
data/examples/flash/config.rb
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# = Dynamic Flash
|
|
2
|
-
#
|
|
3
|
-
# A simple app that demonstrates
|
|
4
|
-
#
|
|
5
|
-
# code:
|
|
6
|
-
# * George Moschovitis <gm@navel.gr>
|
|
7
|
-
#
|
|
8
|
-
# (c) 2004 Navel, all rights reserved.
|
|
9
|
-
# $Id: config.rb 189 2004-12-13 21:38:05Z gmosx $
|
|
10
|
-
|
|
11
|
-
require 'nitro'
|
|
12
|
-
require 'glue/logger'
|
|
13
|
-
require 'nitro/config'
|
|
14
|
-
|
|
15
|
-
require 'nitro/l10n'
|
|
16
|
-
require 'glue/mixins'
|
|
17
|
-
require 'nitro/sitemap'
|
|
18
|
-
|
|
19
|
-
require 'glue/number'
|
|
20
|
-
require 'glue/string'
|
|
21
|
-
require 'glue/array'
|
|
22
|
-
require 'glue/hash'
|
|
23
|
-
require 'nitro/html'
|
|
24
|
-
|
|
25
|
-
require 'nitro/server/webrick'
|
|
26
|
-
require 'nitro/server/shaders'
|
|
27
|
-
|
|
28
|
-
require 'lib/flash'
|
|
29
|
-
|
|
30
|
-
$name = 'Dynamic Flash Application'
|
|
31
|
-
|
|
32
|
-
$services = {
|
|
33
|
-
:index => N::FlashService
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
$srv_address = $appsrv_address = '127.0.0.1'
|
|
37
|
-
$srv_url = "http://#$srv_address:#$srv_port"
|
|
38
|
-
|
data/examples/flash/lib/flash.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
|
5
|
-
# $Id: flash.rb 189 2004-12-13 21:38:05Z gmosx $
|
|
6
|
-
|
|
7
|
-
require 'nitro/service'
|
|
8
|
-
require 'ming/ming'
|
|
9
|
-
|
|
10
|
-
module N
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# = FlashService
|
|
14
|
-
#
|
|
15
|
-
class FlashService < N::Service
|
|
16
|
-
include Ming
|
|
17
|
-
|
|
18
|
-
SOURCE_FILE = __FILE__
|
|
19
|
-
|
|
20
|
-
def show_text
|
|
21
|
-
create_flash
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def create_flash
|
|
27
|
-
m = SWFMovie.new
|
|
28
|
-
f = SWFBrowserFont.new('_serif')
|
|
29
|
-
t = SWFTextField.new
|
|
30
|
-
t.set_font(f)
|
|
31
|
-
t.add_string(@params['text'])
|
|
32
|
-
m.add(t)
|
|
33
|
-
@response.header['Content-Type'] = 'application/x-shockwave-flash'
|
|
34
|
-
m.save('tmp.swf')
|
|
35
|
-
@out = File.read('tmp.swf')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end # module
|
data/examples/flash/tmp.swf
DELETED
|
Binary file
|
data/examples/tiny/app.rb
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/local/bin/ruby
|
|
2
|
-
|
|
3
|
-
# = Tiny Example
|
|
4
|
-
#
|
|
5
|
-
# A simple Web Application to demonstrate the Engine.
|
|
6
|
-
#
|
|
7
|
-
# code:
|
|
8
|
-
# * George Moschovitis <gm@navel.gr>
|
|
9
|
-
#
|
|
10
|
-
# (c) 2004 Navel, all rights reserved.
|
|
11
|
-
# $Id: app.rb 185 2004-12-10 13:29:09Z gmosx $
|
|
12
|
-
|
|
13
|
-
$DBG = false
|
|
14
|
-
|
|
15
|
-
$LOAD_PATH.unshift "../../lib"
|
|
16
|
-
|
|
17
|
-
require "config"
|
|
18
|
-
|
|
19
|
-
$app = N::WebrickServer.new.exec()
|
data/examples/tiny/config.rb
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# = Tiny Configuration
|
|
2
|
-
#
|
|
3
|
-
# You can find additional configuration variables in
|
|
4
|
-
# lib/n/config.rb. Just copy the variables you want to
|
|
5
|
-
# change in this file
|
|
6
|
-
#
|
|
7
|
-
# code:
|
|
8
|
-
# * George Moschovitis <gm@navel.gr>
|
|
9
|
-
#
|
|
10
|
-
# (c) 2004 Navel, all rights reserved.
|
|
11
|
-
# $Id: config.rb 167 2004-11-23 14:03:10Z gmosx $
|
|
12
|
-
|
|
13
|
-
require "nitro"
|
|
14
|
-
require "glue/logger"
|
|
15
|
-
require "nitro/config"
|
|
16
|
-
|
|
17
|
-
require "glue/number"
|
|
18
|
-
require "glue/string"
|
|
19
|
-
require "glue/array"
|
|
20
|
-
require "glue/hash"
|
|
21
|
-
require "nitro/html"
|
|
22
|
-
|
|
23
|
-
require "nitro/server/webrick"
|
|
24
|
-
|
|
25
|
-
$name = "Tiny Example"
|
|
26
|
-
|
|
27
|
-
$srv_address = $appsrv_address = "127.0.0.1"
|
|
28
|
-
$srv_port = 8080
|
|
29
|
-
$srv_url = "http://#$srv_address:#$srv_port"
|
|
Binary file
|
data/lib/nitro/application.rb
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
# = Application
|
|
2
|
-
#
|
|
3
|
-
# The default Application object of the Framework.
|
|
4
|
-
#
|
|
5
|
-
# code:
|
|
6
|
-
# George Moschovitis <gm@navel.gr>
|
|
7
|
-
# Anastasios Koutoumanos <ak@navel.gr>
|
|
8
|
-
# Elias Athanasopoulos <elathan@navel.gr>
|
|
9
|
-
# Elias Karakoulakis <ekarak@ktismata.com>
|
|
10
|
-
#
|
|
11
|
-
# (c) 2004 Navel, all rights reserved.
|
|
12
|
-
# $Id: application.rb 174 2004-11-26 16:00:21Z gmosx $
|
|
13
|
-
|
|
14
|
-
require 'optparse'
|
|
15
|
-
require 'ostruct'
|
|
16
|
-
|
|
17
|
-
require "glue/logger"
|
|
18
|
-
require "nitro"
|
|
19
|
-
|
|
20
|
-
module N
|
|
21
|
-
|
|
22
|
-
# == Application
|
|
23
|
-
#
|
|
24
|
-
# The default Application object of the Framework.
|
|
25
|
-
#
|
|
26
|
-
class Application
|
|
27
|
-
# credentials of the application
|
|
28
|
-
attr_accessor :name, :title, :description, :version
|
|
29
|
-
|
|
30
|
-
# the status of the application
|
|
31
|
-
# use symbols to denote status.
|
|
32
|
-
# valid status symbols:
|
|
33
|
-
# * :run = The server is running
|
|
34
|
-
# * :stop = The server is stopped
|
|
35
|
-
attr_accessor :status
|
|
36
|
-
|
|
37
|
-
# startup time of the application
|
|
38
|
-
attr_accessor :create_time
|
|
39
|
-
|
|
40
|
-
# is the application daemonized?
|
|
41
|
-
attr_reader :daemonized
|
|
42
|
-
|
|
43
|
-
# the pid of the application
|
|
44
|
-
attr_reader :pid, :pidfile
|
|
45
|
-
|
|
46
|
-
# Intialize method
|
|
47
|
-
#
|
|
48
|
-
def initialize(name = "Unknown")
|
|
49
|
-
@name = name
|
|
50
|
-
@pidfile = "/tmp/#{@name}.pid"
|
|
51
|
-
@create_time = Time.now()
|
|
52
|
-
@status = :stop
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Parse the arguments passed to the application.
|
|
56
|
-
# Some standard arguments are handled by default.
|
|
57
|
-
#
|
|
58
|
-
def parse_arguments(args = ARGV)
|
|
59
|
-
|
|
60
|
-
opts = OptionParser.new { |opts|
|
|
61
|
-
opts.banner = "Usage: application.rb [action]"
|
|
62
|
-
|
|
63
|
-
opts.separator ""
|
|
64
|
-
opts.separator "Specific options:"
|
|
65
|
-
|
|
66
|
-
opts.on("-s", "--start",
|
|
67
|
-
"Start '#$name'.") {
|
|
68
|
-
start()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
opts.on("-S", "--stop",
|
|
72
|
-
"Stop '#$name'.") {
|
|
73
|
-
stop()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
opts.on("-r", "--restart",
|
|
77
|
-
"Restart '#$name'.") {
|
|
78
|
-
restart()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
opts.on("-d", "--daemon",
|
|
82
|
-
"Run '#$name' as a daemon.") {
|
|
83
|
-
daemonize()
|
|
84
|
-
start()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
opts.on_tail("-?", "--help", "Show this message.") {
|
|
88
|
-
puts opts
|
|
89
|
-
exit
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
opts.on_tail("-v", "--version", "Show version.") {
|
|
93
|
-
puts $srv_version
|
|
94
|
-
exit
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
begin
|
|
99
|
-
opts.parse!(args)
|
|
100
|
-
rescue => ex
|
|
101
|
-
puts ex
|
|
102
|
-
puts "Please, either specify a valid option or invoke the usage using -? or --help."
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
alias_method :exec, :parse_arguments
|
|
106
|
-
|
|
107
|
-
#
|
|
108
|
-
#
|
|
109
|
-
def start()
|
|
110
|
-
raise "Application allready started!" unless :stop == @status
|
|
111
|
-
|
|
112
|
-
begin
|
|
113
|
-
run()
|
|
114
|
-
rescue => ex
|
|
115
|
-
puts ex
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# to allow for chaining
|
|
119
|
-
return self
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# Override to properly restart the application
|
|
123
|
-
#
|
|
124
|
-
def restart()
|
|
125
|
-
stop()
|
|
126
|
-
start()
|
|
127
|
-
|
|
128
|
-
# to allow for chaining
|
|
129
|
-
return self
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Stop the application. Typically kills ths application daemon.
|
|
133
|
-
#
|
|
134
|
-
def stop
|
|
135
|
-
if dpid = daemon_pid()
|
|
136
|
-
begin
|
|
137
|
-
File.delete(@pidfile)
|
|
138
|
-
Process.kill("SIGKILL", dpid)
|
|
139
|
-
Logger.info "Successfully killed #{@name} instance, pid=#{dpid}"
|
|
140
|
-
rescue => ex
|
|
141
|
-
Logger.error "Cannot kill #{@name} instance, pid=#{dpid}"
|
|
142
|
-
Logger.error ex
|
|
143
|
-
end
|
|
144
|
-
else
|
|
145
|
-
Logger.error "Cannot locate pid of running instance!"
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# to allow for chaining
|
|
149
|
-
return self
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# Begin the application loop.
|
|
153
|
-
# Override this method in your application.
|
|
154
|
-
#
|
|
155
|
-
def run
|
|
156
|
-
# to allow for chaining
|
|
157
|
-
return self
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# Run the application as a daemon
|
|
161
|
-
# FIXME: handle logging for daemons.
|
|
162
|
-
# ???: How does this work !?!?
|
|
163
|
-
#
|
|
164
|
-
=begin
|
|
165
|
-
def daemonize
|
|
166
|
-
unless @daemonized
|
|
167
|
-
trap "SIGCLD", "IGNORE"
|
|
168
|
-
|
|
169
|
-
pid = fork()
|
|
170
|
-
|
|
171
|
-
if pid # parent process
|
|
172
|
-
@pid = pid
|
|
173
|
-
File.open(@pidfile, 'w') {|f| f << "#{pid}\n" }
|
|
174
|
-
exit!
|
|
175
|
-
else # child
|
|
176
|
-
Logger.info "Daemon for '#{@name}', process id: #{Process.pid}"
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
# change process group and lose control tty
|
|
180
|
-
Process.setpgrp()
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
@daemonized = true
|
|
184
|
-
|
|
185
|
-
return self
|
|
186
|
-
end
|
|
187
|
-
=end
|
|
188
|
-
def daemonize
|
|
189
|
-
unless @daemonized
|
|
190
|
-
exit!(0) if fork
|
|
191
|
-
Process::setsid
|
|
192
|
-
exit!(0) if fork
|
|
193
|
-
File::umask(0)
|
|
194
|
-
[ STDIN, STDOUT, STDERR ].each do |io|
|
|
195
|
-
io.reopen("/dev/null", "r+")
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
@daemonized = true
|
|
199
|
-
|
|
200
|
-
return self
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
# Returns the pid of the running daemon
|
|
205
|
-
#
|
|
206
|
-
def daemon_pid()
|
|
207
|
-
begin
|
|
208
|
-
return File.open(@pidfile).read.chomp.to_i
|
|
209
|
-
rescue
|
|
210
|
-
Logger.info "Could not read pid from #{@pidfile}"
|
|
211
|
-
return nil
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
end # module
|
|
217
|
-
|