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/lib/nitro/config.rb
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
# = Configuration
|
|
2
|
-
#
|
|
3
|
-
# Configuration parameters.
|
|
4
|
-
#
|
|
5
|
-
# code:
|
|
6
|
-
# * George Moschovitis <gm@navel.gr>
|
|
7
|
-
#
|
|
8
|
-
# (c) 2004 Navel, all rights reserved.
|
|
9
|
-
# $Id: config.rb 167 2004-11-23 14:03:10Z gmosx $
|
|
10
|
-
|
|
11
|
-
require 'glue/logger'
|
|
12
|
-
require 'glue/hash'
|
|
13
|
-
require 'nitro/version'
|
|
14
|
-
require 'nitro/service'
|
|
15
|
-
require 'nitro/server/shaders'
|
|
16
|
-
|
|
17
|
-
# monitor scripts for changes
|
|
18
|
-
#--
|
|
19
|
-
# gmosx, FIXME: replace this with reload_scripts ??
|
|
20
|
-
#++
|
|
21
|
-
$srv_monitor_scripts = true
|
|
22
|
-
|
|
23
|
-
# The root (public) directory.
|
|
24
|
-
$root_dir = "root"
|
|
25
|
-
|
|
26
|
-
# the default file to view in a direcotry
|
|
27
|
-
$index_filename = "index.sx"
|
|
28
|
-
|
|
29
|
-
# seconds till the autologin cookie expires
|
|
30
|
-
# TODO: move to filter.
|
|
31
|
-
$srv_autologin_expires = 60*60*24*30
|
|
32
|
-
|
|
33
|
-
# session timeout (in seconds)
|
|
34
|
-
$srv_session_timeout = 35*60
|
|
35
|
-
|
|
36
|
-
# session timeout for anonymous user (in seconds)
|
|
37
|
-
$srv_anon_session_timeout = 30*60
|
|
38
|
-
|
|
39
|
-
# enable distributed state?
|
|
40
|
-
$drb_state = false
|
|
41
|
-
|
|
42
|
-
# use the default error page.
|
|
43
|
-
$error_page_url = nil
|
|
44
|
-
|
|
45
|
-
# default encoding for the app.
|
|
46
|
-
$encoding = 'iso-8859-1'
|
|
47
|
-
|
|
48
|
-
# Default template extesnion.
|
|
49
|
-
$template_ext = 'xhtml'
|
|
50
|
-
|
|
51
|
-
# Default xml template extension.
|
|
52
|
-
$xml_template_ext = 'xml'
|
|
53
|
-
|
|
54
|
-
# Default template.
|
|
55
|
-
$index_template = 'index.xhtml'
|
|
56
|
-
|
|
57
|
-
# default content type.
|
|
58
|
-
$default_content_type = 'text/html'
|
|
59
|
-
|
|
60
|
-
# The services map.
|
|
61
|
-
# :index represents the '/' mount point
|
|
62
|
-
$services = { :index => N::Service }
|
|
63
|
-
|
|
64
|
-
# The service method map.
|
|
65
|
-
$methods = N::SafeHash.new
|
|
66
|
-
|
|
67
|
-
# The shader. The default shader is very simple, here
|
|
68
|
-
# is a typical example of a production shader pipeline:
|
|
69
|
-
#
|
|
70
|
-
# <tt>
|
|
71
|
-
# $shader = N::XSLTShader.new("#$root_dir/style.xsl",
|
|
72
|
-
# N::RubyShader.new(
|
|
73
|
-
# N::CompressShader.new
|
|
74
|
-
# )
|
|
75
|
-
# )
|
|
76
|
-
# </tt>
|
|
77
|
-
$shader = N::RubyShader.new
|
|
78
|
-
|
|
79
|
-
if $DBG
|
|
80
|
-
|
|
81
|
-
puts "\nRunning DEBUG configuration.\n\n"
|
|
82
|
-
|
|
83
|
-
# Logger (redirect to STDERR)
|
|
84
|
-
|
|
85
|
-
Logger.set(Logger.new(STDERR))
|
|
86
|
-
Logger.get.level = Logger::DEBUG
|
|
87
|
-
|
|
88
|
-
# If set to true disables xsl caching. Usefull when debugging xsls.
|
|
89
|
-
|
|
90
|
-
$reload_xsl = true
|
|
91
|
-
|
|
92
|
-
# If set to true disables script compilation. Usefull when debugging
|
|
93
|
-
# statically included scripts.
|
|
94
|
-
|
|
95
|
-
$reload_scripts = true
|
|
96
|
-
|
|
97
|
-
# Standard server setup for debugging.
|
|
98
|
-
|
|
99
|
-
$srv_address = $appsrv_address = "127.0.0.1"
|
|
100
|
-
$srv_port = 8080
|
|
101
|
-
$appsrv_port = 8080
|
|
102
|
-
$srv_url = "http://#$srv_address:#$srv_port"
|
|
103
|
-
|
|
104
|
-
else
|
|
105
|
-
|
|
106
|
-
puts "\nRunning LIVE configuration.\n\n"
|
|
107
|
-
|
|
108
|
-
Logger.set(Logger.new("log/app.log", 10))
|
|
109
|
-
Logger.get.level = Logger::INFO
|
|
110
|
-
|
|
111
|
-
# If set to true disables xsl caching. Usefull when debugging xsls.
|
|
112
|
-
|
|
113
|
-
$reload_xsl = false
|
|
114
|
-
|
|
115
|
-
# If set to true disables script compilation. Usefull when debugging
|
|
116
|
-
# statically included scripts.
|
|
117
|
-
|
|
118
|
-
$reload_scripts = false
|
|
119
|
-
|
|
120
|
-
# Standard server setup for live server. You probably
|
|
121
|
-
# want to override this.
|
|
122
|
-
|
|
123
|
-
$srv_address = $appsrv_address = "127.0.0.1"
|
|
124
|
-
$srv_port = 8080
|
|
125
|
-
$appsrv_port = 9090
|
|
126
|
-
$srv_url = "http://#$srv_address:#$srv_port"
|
|
127
|
-
|
|
128
|
-
end
|
data/lib/nitro/events.rb
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# = Events
|
|
2
|
-
#
|
|
3
|
-
# A simple events mechanism.
|
|
4
|
-
#
|
|
5
|
-
# code:
|
|
6
|
-
# George Moschovitis <gm@navel.gr>
|
|
7
|
-
#
|
|
8
|
-
# (c) 2002-2003 Navel, all rights reserved.
|
|
9
|
-
# $Id: events.rb 98 2004-10-22 07:36:20Z gmosx $
|
|
10
|
-
|
|
11
|
-
module N;
|
|
12
|
-
|
|
13
|
-
# = EventManager
|
|
14
|
-
#
|
|
15
|
-
# A simple events mechanism.
|
|
16
|
-
#
|
|
17
|
-
# === Design:
|
|
18
|
-
#
|
|
19
|
-
# As always we try to keep the design simple:
|
|
20
|
-
# Events = strings (hiearchical notation)
|
|
21
|
-
# Handlers = named Procs
|
|
22
|
-
# The handlers are named so that we can remove them
|
|
23
|
-
# by name. Also usefull for documentation purposes.
|
|
24
|
-
#
|
|
25
|
-
# === TODO:
|
|
26
|
-
#
|
|
27
|
-
# Add a class of events to allow filtering of certain
|
|
28
|
-
# events. Perhaps name can be used for this!
|
|
29
|
-
#
|
|
30
|
-
# === Example:
|
|
31
|
-
#
|
|
32
|
-
# $ev.event("id/user/login", user)
|
|
33
|
-
# $ev.add_handler("id/user/login", "login-score", proc { |user|
|
|
34
|
-
# user["score"] += 1
|
|
35
|
-
# })
|
|
36
|
-
#
|
|
37
|
-
class EventManager
|
|
38
|
-
attr :events
|
|
39
|
-
attr_accessor :logger
|
|
40
|
-
|
|
41
|
-
def initialize(logger = nil)
|
|
42
|
-
@events = Hash.new
|
|
43
|
-
@logger = logger
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Register an event handler.
|
|
47
|
-
#
|
|
48
|
-
# === Input:
|
|
49
|
-
# event = the event
|
|
50
|
-
# name = the name of the handler
|
|
51
|
-
# proc = the proc of the hadler
|
|
52
|
-
#
|
|
53
|
-
def add_handler(event, name, proc)
|
|
54
|
-
unless event_handlers = @events[event]
|
|
55
|
-
@events[event] = event_handlers = Hash.new
|
|
56
|
-
end
|
|
57
|
-
event_handlers[name] = proc
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Remove the named handler from the event.
|
|
61
|
-
#
|
|
62
|
-
def remove_handler(event, name)
|
|
63
|
-
if event_handlers = @events[event]
|
|
64
|
-
event_handlers.delete(name)
|
|
65
|
-
else
|
|
66
|
-
Logger.debug "ev: cannot remove, handler #{name} not found for event #{event}" if $DBG
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Remove all handlers for the event.
|
|
71
|
-
#
|
|
72
|
-
# === Input:
|
|
73
|
-
# event = the event
|
|
74
|
-
# name = the name of the handler
|
|
75
|
-
#
|
|
76
|
-
def remove_all_handlers(event)
|
|
77
|
-
@events[event] = Hash.new
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Fire an event
|
|
81
|
-
#
|
|
82
|
-
# === Input:
|
|
83
|
-
# event = the event to fire
|
|
84
|
-
# param = parameters for the handler, use an array
|
|
85
|
-
# for multiple parameters.
|
|
86
|
-
#
|
|
87
|
-
def event(event, params)
|
|
88
|
-
if event_handlers = @events[event]
|
|
89
|
-
# call all event handler procs
|
|
90
|
-
for handler in event_handlers.values
|
|
91
|
-
# call the handler with the params.
|
|
92
|
-
handler.call(params)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
if @logger
|
|
96
|
-
if params.is_a?(Array)
|
|
97
|
-
pstr = params.collect{|i| i.to_s()}.join(", ")
|
|
98
|
-
else
|
|
99
|
-
pstr = params.to_s()
|
|
100
|
-
end
|
|
101
|
-
@logger.info("#{event}: #{pstr}")
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
alias_method :fire, :event
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# = Event
|
|
108
|
-
#
|
|
109
|
-
# Encapsulates an Event
|
|
110
|
-
#
|
|
111
|
-
class Event
|
|
112
|
-
@@manager = EventManager.new()
|
|
113
|
-
|
|
114
|
-
def self.add_handler(event, name, proc)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def self.fire(event, params)
|
|
118
|
-
@@manager.fire(event, params)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
end # module
|
data/lib/nitro/html.rb
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
# * Anastasios Koutoumanos <ak@navel.gr>
|
|
4
|
-
# * Elias Karakoulakis <ekarak@ktismata.com>
|
|
5
|
-
#
|
|
6
|
-
# (c) 2004 Navel, all rights reserved.
|
|
7
|
-
# $Id: html.rb 167 2004-11-23 14:03:10Z gmosx $
|
|
8
|
-
|
|
9
|
-
require "uri"
|
|
10
|
-
require "cgi"
|
|
11
|
-
|
|
12
|
-
module N;
|
|
13
|
-
|
|
14
|
-
# = HtmlUtils
|
|
15
|
-
#
|
|
16
|
-
# HTML utilities collection.
|
|
17
|
-
#
|
|
18
|
-
# === Design:
|
|
19
|
-
#
|
|
20
|
-
# Implement as a module to avoid class polution. You can still Ruby's
|
|
21
|
-
# advanced features to include the module in your class.
|
|
22
|
-
# Passing the object to act upon allows to check for nil, which isn't
|
|
23
|
-
# possible if you use self.
|
|
24
|
-
#
|
|
25
|
-
# The older text_sum, text_block methods are not needed in the latest
|
|
26
|
-
# code
|
|
27
|
-
#
|
|
28
|
-
# === TODO:
|
|
29
|
-
#
|
|
30
|
-
# - add xxx! versions
|
|
31
|
-
#
|
|
32
|
-
module HtmlUtils
|
|
33
|
-
|
|
34
|
-
# escape html tags.
|
|
35
|
-
# usefull to make text entered by end users html safe.
|
|
36
|
-
#
|
|
37
|
-
# Input:
|
|
38
|
-
# the string to be escaped
|
|
39
|
-
#
|
|
40
|
-
# Output:
|
|
41
|
-
# the escaped string
|
|
42
|
-
#
|
|
43
|
-
def self.escape(string)
|
|
44
|
-
# gmosx: no need to return "" on nil, will be interpolated to ""
|
|
45
|
-
return nil unless string
|
|
46
|
-
return CGI::escapeHTML(string)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# TODO: move to markup!
|
|
50
|
-
#
|
|
51
|
-
# Expands the urls found in the given string. Use the target parameter
|
|
52
|
-
# to apply presentation semantics (ie open in new window)
|
|
53
|
-
#
|
|
54
|
-
# Example:
|
|
55
|
-
# text = "visit this site: www.navel.gr"
|
|
56
|
-
# text = Web::Utils::Html::expand_urls(text)
|
|
57
|
-
# p text # =>
|
|
58
|
-
# "visit this site: <a href='http://www.navel.gr'>http://www.navel.gr</a>"
|
|
59
|
-
#
|
|
60
|
-
def self.expand_urls(string, target = nil)
|
|
61
|
-
return nil unless string
|
|
62
|
-
|
|
63
|
-
xstring = string.gsub(/\s(www\.[^\s]*)/, " http://\\1")
|
|
64
|
-
xstring.gsub!(/\s(ftp\.[^\s]*)/, " ftp://\\1")
|
|
65
|
-
|
|
66
|
-
xstring.gsub!(URI::REGEXP::ABS_URI_REF) { |uriref|
|
|
67
|
-
if /(http|ftp):/.match(uriref)
|
|
68
|
-
"<a" + (target.nil?? "" : " target='#{target}'") +
|
|
69
|
-
" href='#{uriref}'>#{uriref}</a>"
|
|
70
|
-
else
|
|
71
|
-
uriref
|
|
72
|
-
end
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return xstring
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# Strips potentially dangerous html tags, leaving only safe
|
|
79
|
-
# tags. Usefull for simple Html formatting.
|
|
80
|
-
#
|
|
81
|
-
# === Design:
|
|
82
|
-
#
|
|
83
|
-
# Escapes ALL quotes for security, use html without quotes:
|
|
84
|
-
#
|
|
85
|
-
# <font size=+1>kok</font>
|
|
86
|
-
# <a href=http://www.navel.gr
|
|
87
|
-
# ...
|
|
88
|
-
#
|
|
89
|
-
# Should handle the following case:
|
|
90
|
-
#
|
|
91
|
-
# <tr><td><a href='koko</td></tr>...
|
|
92
|
-
# passes with obvious results :(
|
|
93
|
-
# even the following fucks up browsers:
|
|
94
|
-
# <tr><td><p href='koko</td></tr>
|
|
95
|
-
#
|
|
96
|
-
# We HAVE TO CHECK VALID XHTML/XML before using this method.
|
|
97
|
-
#
|
|
98
|
-
# <img> is NOT a safe tag, because it can fuckup the
|
|
99
|
-
# layout, so it is not included in the default safe tags
|
|
100
|
-
#
|
|
101
|
-
# on open
|
|
102
|
-
#
|
|
103
|
-
# === Input:
|
|
104
|
-
# the string to be filtered
|
|
105
|
-
# extra exclude_tags
|
|
106
|
-
# extra include_tags
|
|
107
|
-
#
|
|
108
|
-
# === Output:
|
|
109
|
-
# the filtered string, only contains safe html tags
|
|
110
|
-
|
|
111
|
-
OPEN_TAGS = /<([^<>]*)(?=<)/
|
|
112
|
-
VALID_TAGS = /<([^<>]*)>(?=<)/
|
|
113
|
-
OPEN_QUOTES = /['"]([^'"]*)(?!['"])/
|
|
114
|
-
|
|
115
|
-
def self.only_safe_tags(string, exclude_tags = nil, include_tags = nil)
|
|
116
|
-
return nil unless string
|
|
117
|
-
|
|
118
|
-
# default safe tags
|
|
119
|
-
# FIXME: move the array outside of the method to avoid
|
|
120
|
-
# excessive array creation
|
|
121
|
-
|
|
122
|
-
safe_tags = ["A", "B", "I", "U", "BR", "STRONG", "LI"]
|
|
123
|
-
|
|
124
|
-
# customize if necessary
|
|
125
|
-
safe_tags += exclude_tags if exclude_tags
|
|
126
|
-
safe_tags -= include_tags if include_tags
|
|
127
|
-
|
|
128
|
-
# try to fix up invalid XHTML tags: close brackets, and
|
|
129
|
-
# escape quotes of open tags.
|
|
130
|
-
# SOS: keep the order of the escapes!
|
|
131
|
-
|
|
132
|
-
escaped = string.gsub(OPEN_TAGS, '<\1>')
|
|
133
|
-
escaped = CGI::escapeHTML(escaped)
|
|
134
|
-
escaped = CGI::unescapeElement(escaped, safe_tags)
|
|
135
|
-
escaped.gsub!(/"/, '"')
|
|
136
|
-
escaped.gsub!(/'/, ''')
|
|
137
|
-
|
|
138
|
-
return escaped
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# convert plain newlines into line breaks <br/>
|
|
142
|
-
|
|
143
|
-
def self.convert_newlines(string)
|
|
144
|
-
return nil unless N::StringUtils.valid?(string)
|
|
145
|
-
xstring = string.gsub(/\n/, "<br/>")
|
|
146
|
-
return xstring;
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
end # module
|
data/lib/nitro/http.rb
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
# * Elias Karakoulakis <ekarak@ktismata.com>
|
|
4
|
-
#
|
|
5
|
-
# (c) 2004 Navel, all rights reserved.
|
|
6
|
-
# $Id: http.rb 164 2004-11-18 11:47:50Z gmosx $
|
|
7
|
-
|
|
8
|
-
require "uri"
|
|
9
|
-
require "cgi"
|
|
10
|
-
require "net/http"
|
|
11
|
-
|
|
12
|
-
module N
|
|
13
|
-
|
|
14
|
-
# = HTTP
|
|
15
|
-
#
|
|
16
|
-
# HTTP protocol constants.
|
|
17
|
-
#
|
|
18
|
-
module HTTP
|
|
19
|
-
# HTTP protocol EOL constants
|
|
20
|
-
|
|
21
|
-
CR = "\x0d"
|
|
22
|
-
LF = "\x0a"
|
|
23
|
-
CRLF = "\x0d\x0a"
|
|
24
|
-
EOL = CRLF
|
|
25
|
-
|
|
26
|
-
# Http protocol status codes maps.
|
|
27
|
-
|
|
28
|
-
# constants for readable code
|
|
29
|
-
|
|
30
|
-
STATUS_OK = 200
|
|
31
|
-
STATUS_PARTIAL_CONTENT = 206
|
|
32
|
-
STATUS_MOVED = 301
|
|
33
|
-
STATUS_REDIRECT = 302
|
|
34
|
-
STATUS_SEE_OTHER = 303 # gmosx: VERIFY THIS
|
|
35
|
-
STATUS_SEE_OTHER_307 = 307 # gmosx: VERIFY THIS
|
|
36
|
-
STATUS_NOT_MODIFIED = 304
|
|
37
|
-
STATUS_BAD_REQUEST = 400
|
|
38
|
-
STATUS_AUTH_REQUIRED = 401
|
|
39
|
-
STATUS_FORBIDDEN = 403
|
|
40
|
-
STATUS_NOT_FOUND = 404
|
|
41
|
-
STATUS_METHOD_NOT_ALLOWED = 405
|
|
42
|
-
STATUS_NOT_ACCEPTABLE = 406
|
|
43
|
-
STATUS_LENGTH_REQUIRED = 411
|
|
44
|
-
STATUS_PRECONDITION_FAILED = 412
|
|
45
|
-
STATUS_SERVER_ERROR = 500
|
|
46
|
-
STATUS_NOT_IMPLEMENTED = 501
|
|
47
|
-
STATUS_BAD_GATEWAY = 502
|
|
48
|
-
STATUS_VARIANT_ALSO_VARIES = 506
|
|
49
|
-
|
|
50
|
-
# hash to allow id to description maping.
|
|
51
|
-
|
|
52
|
-
STATUS_STRINGS = {
|
|
53
|
-
200 => "OK",
|
|
54
|
-
206 => "Partial Content",
|
|
55
|
-
300 => "Multiple Choices",
|
|
56
|
-
301 => "Moved Permanently",
|
|
57
|
-
302 => "Found",
|
|
58
|
-
303 => "See other", # gmosx: VERIFY THIS
|
|
59
|
-
304 => "Not Modified",
|
|
60
|
-
307 => "See other 07", # gmosx: VERIFY THIS
|
|
61
|
-
400 => "Bad Request",
|
|
62
|
-
401 => "Authorization Required",
|
|
63
|
-
403 => "Forbidden",
|
|
64
|
-
404 => "Not Found",
|
|
65
|
-
405 => "Method Not Allowed",
|
|
66
|
-
406 => "Not Acceptable",
|
|
67
|
-
411 => "Length Required",
|
|
68
|
-
412 => "Rrecondition Failed",
|
|
69
|
-
500 => "Internal Server Error",
|
|
70
|
-
501 => "Method Not Implemented",
|
|
71
|
-
502 => "Bad Gateway",
|
|
72
|
-
506 => "Variant Also Negotiates"
|
|
73
|
-
}
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# = HttpUtils
|
|
77
|
-
#
|
|
78
|
-
# HTTP utilities collection
|
|
79
|
-
#
|
|
80
|
-
module HttpUtils
|
|
81
|
-
|
|
82
|
-
# Converts the given time object to an http time string.
|
|
83
|
-
# Example:
|
|
84
|
-
# Sat, 01 Jan 2000 00:00:00 GMT
|
|
85
|
-
#
|
|
86
|
-
def self.time_to_string(time)
|
|
87
|
-
return CGI::rfc1123_date(time)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# NOT IMPLEMENTED
|
|
91
|
-
#
|
|
92
|
-
# Converts an http time string to a time object.
|
|
93
|
-
# Example:
|
|
94
|
-
# Sat, 01 Jan 2000 00:00:00 GMT
|
|
95
|
-
#
|
|
96
|
-
def self.string_to_time(string)
|
|
97
|
-
raise "Not implemented"
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
end # module
|