nitro 0.9.3 → 0.9.5

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.
Files changed (43) hide show
  1. data/ChangeLog +64 -0
  2. data/RELEASES +13 -0
  3. data/examples/blog/README +1 -1
  4. data/examples/blog/conf/app.conf.rb +2 -6
  5. data/examples/blog/conf/lhttpd.conf +1 -1
  6. data/examples/blog/lib/blog/controller.rb +2 -2
  7. data/examples/blog/root/style.css +0 -2
  8. data/examples/flash/conf/app.conf.rb +2 -4
  9. data/examples/no_xsl_blog/README +9 -0
  10. data/examples/no_xsl_blog/conf/app.conf.rb +5 -8
  11. data/examples/no_xsl_blog/conf/lhttpd.conf +1 -1
  12. data/examples/no_xsl_blog/lib/blog/controller.rb +2 -3
  13. data/examples/no_xsl_blog/lib/blog/template.rb +3 -3
  14. data/examples/no_xsl_blog/root/style.css +0 -2
  15. data/examples/og/mock_example.rb +1 -4
  16. data/examples/og/mysql_to_psql.rb +2 -4
  17. data/examples/tiny/README +1 -1
  18. data/examples/tiny/conf/app.conf.rb +2 -6
  19. data/examples/tiny/conf/lhttpd.conf +1 -1
  20. data/examples/wee_style/README +10 -0
  21. data/examples/wee_style/wee.rb +50 -0
  22. data/lib/glue/cache.rb +32 -34
  23. data/lib/glue/number.rb +3 -9
  24. data/lib/glue/time.rb +14 -22
  25. data/lib/glue/validation.rb +2 -4
  26. data/lib/nitro.rb +1 -3
  27. data/lib/nitro/adaptors/fastcgi.rb +10 -0
  28. data/lib/nitro/adaptors/webrick.rb +27 -11
  29. data/lib/nitro/builders/rss.rb +31 -11
  30. data/lib/nitro/builders/xhtml.rb +2 -8
  31. data/lib/nitro/context.rb +3 -1
  32. data/lib/nitro/dispatcher.rb +21 -4
  33. data/lib/nitro/filters.rb +12 -12
  34. data/lib/nitro/version.rb +1 -1
  35. data/lib/og/backend.rb +36 -40
  36. data/lib/og/backends/psql.rb +7 -7
  37. data/lib/og/backends/sqlite.rb +383 -0
  38. data/lib/og/connection.rb +34 -34
  39. data/lib/og/meta.rb +8 -0
  40. data/lib/og/version.rb +2 -4
  41. data/test/nitro/builders/tc_rss.rb +22 -0
  42. data/test/nitro/tc_dispatcher.rb +6 -1
  43. metadata +7 -2
@@ -1,20 +1,14 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
2
+ # (c) 2004-2005 Navel, all rights reserved.
5
3
  # $Id: number.rb 202 2005-01-17 10:44:13Z gmosx $
6
4
 
7
5
  module N;
8
6
 
9
- # = NumberUtils
10
- #
11
- # === Design:
12
- #
13
7
  # Implement as a module to avoid class polution. You can
14
8
  # still use Ruby's advanced features to include the module in your
15
9
  # class. Passing the object to act upon allows to check for nil,
16
10
  # which isn't possible if you use self.
17
- #
11
+
18
12
  module NumberUtils
19
13
 
20
14
  # Returns the multiple ceil of a number
@@ -27,4 +21,4 @@ module NumberUtils
27
21
 
28
22
  end
29
23
 
30
- end # module
24
+ end
@@ -1,29 +1,23 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
2
+ # (c) 2004-2005 Navel, all rights reserved.
5
3
  # $Id: time.rb 202 2005-01-17 10:44:13Z gmosx $
6
4
 
7
5
  require "time.rb"
8
6
 
9
7
  module N;
10
8
 
11
- # = Time
12
- #
13
9
  # General time utilities collection
14
10
  #
15
- # === Design:
16
- #
17
11
  # Implement as a module to avoid class polution. You can
18
12
  # still Ruby's advanced features to include the module in your
19
13
  # class. Passing the object to act upon allows to check for nil,
20
14
  # which isn't possible if you use self.
21
15
  #
22
- # === TODO:
16
+ # == TODO
23
17
  #
24
18
  # - SOS: add test units.
25
19
  # - add aliases for those methods in Kernel ?
26
- #
20
+
27
21
  module TimeUtils
28
22
 
29
23
  NOW = Time.now
@@ -31,13 +25,13 @@ module TimeUtils
31
25
  ZERO = Time.mktime(1972)
32
26
 
33
27
  # Convert the time to a nice String representation.
34
- #
28
+
35
29
  def self.date_time(time)
36
30
  return nil unless time
37
31
  return time.strftime("%d-%m-%Y %H:%M")
38
32
  end
39
33
 
40
- # this method calculates the days extrema given two time objects.
34
+ # This method calculates the days extrema given two time objects.
41
35
  # start time is the given time1 at 00:00:00
42
36
  # end time is the given time2 at 23:59:59:999
43
37
  #
@@ -48,7 +42,7 @@ module TimeUtils
48
42
  # Output
49
43
  # - the time range. you can get the start/end times using
50
44
  # range methods.
51
- #
45
+
52
46
  def self.days_extrema(time1, time2=nil)
53
47
  time2 = time1 if (not time2.valid? Time)
54
48
  time2 = NEVER if (time2 <= time1)
@@ -57,24 +51,23 @@ module TimeUtils
57
51
  return (start_time..end_time)
58
52
  end
59
53
 
60
- #
61
- # set time to start of day
62
- #
54
+ # Set time to start of day
55
+
63
56
  def self.start_of_day(time)
64
57
  return Time.mktime(time.year, time.month, time.day, 0, 0, 0, 0)
65
58
  end
66
59
 
67
- #
68
- # set time to end of day
69
- #
60
+
61
+ # Set time to end of day
62
+
70
63
  def self.end_of_day(time)
71
64
  return Time.mktime(time.year, time.month, time.day, 23, 59, 59, 999)
72
65
  end
73
66
 
74
67
 
75
- # returns true only if day of time is included in the
68
+ # Returns true only if day of time is included in the
76
69
  # range (stime..etime). Only year days are checked.
77
- #
70
+
78
71
  def self.time_in_day_range(time, stime=ZERO, etime=NEVER)
79
72
  if (etime <= stime)
80
73
  Logger.debug "Invalid end time (#{etime} < #{stime})" if $DBG
@@ -89,5 +82,4 @@ module TimeUtils
89
82
 
90
83
  end
91
84
 
92
- end # module
93
-
85
+ end
@@ -1,11 +1,9 @@
1
- # George Moschovitis <gm@navel.gr>
2
- # (c) 2005 Navel, all rights reserved.
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
3
  # $Id$
4
4
 
5
5
  module N
6
6
 
7
- # = Validation
8
- #
9
7
  # Implements a meta-language for validating managed
10
8
  # objects. Typically used in Validator objects but can be
11
9
  # included in managed objects too.
@@ -10,11 +10,9 @@
10
10
  # Nitro integrates the powerful Og Object-Relational mapping
11
11
  # library.
12
12
  #
13
- #--
14
- # George Moschovitis <gm@navel.gr>
13
+ # * George Moschovitis <gm@navel.gr>
15
14
  # (c) 2004-2005 Navel, all rights reserved.
16
15
  # $Id: nitro.rb 215 2005-01-24 10:44:05Z gmosx $
17
- #++
18
16
 
19
17
  require 'glue'
20
18
  require 'glue/logger'
@@ -9,6 +9,8 @@ require 'nitro/context'
9
9
  require 'nitro/dispatcher'
10
10
  require 'nitro/adaptors/cgi'
11
11
 
12
+ require 'glue/flexob'
13
+
12
14
  module N
13
15
 
14
16
  # FastCGI Adaptor. FastCGI is a language independent,
@@ -19,7 +21,10 @@ module N
19
21
  class FastCGI
20
22
 
21
23
  def self.start(conf)
24
+ conf = Flexob.new(conf) unless conf.is_a?(Flexob)
25
+
22
26
  FCGI.each do |cgi|
27
+
23
28
  context = Context.new(conf)
24
29
 
25
30
  context.in = cgi.in
@@ -28,8 +33,13 @@ class FastCGI
28
33
  CgiUtils.parse_params(context)
29
34
  CgiUtils.parse_cookies(context)
30
35
 
36
+ # gmosx, TODO: move this into a filter.
37
+ Og.db.get_connection if defined?(Og)
38
+
31
39
  context.render(context.path)
32
40
 
41
+ Og.db.put_connection if defined?(Og)
42
+
33
43
  cgi.out.print(CgiUtils.response_headers(context))
34
44
  cgi.out.print(context.out)
35
45
 
@@ -1,11 +1,11 @@
1
- #--
2
- # George Moschovitis <gm@navel.gr>
1
+ # * George Moschovitis <gm@navel.gr>
3
2
  # (c) 2004-2005 Navel, all rights reserved.
4
3
  # $Id$
5
- #++
6
4
 
7
5
  require 'webrick'
8
6
 
7
+ require 'glue/flexob'
8
+
9
9
  require 'nitro/context'
10
10
  require 'nitro/dispatcher'
11
11
 
@@ -33,24 +33,30 @@ class Webrick
33
33
  attr_accessor :server
34
34
 
35
35
  def start(conf)
36
+ conf = Flexob.new(conf) unless conf.is_a?(Flexob)
37
+
36
38
  # patch for OSX
37
39
 
38
40
  Socket.do_not_reverse_lookup = true
39
41
 
40
- # if RUBY_PLATFORM =~ /mswin32/
41
- # accesslog = WEBrick::BasicLog::new('/dev/null')
42
- # referer = WEBrick::BasicLog::new('/dev/null')
43
-
44
- accesslog = WEBrick::BasicLog::new('log/access.log')
45
- referer = WEBrick::BasicLog::new('log/referer.log')
46
-
42
+ if :none == conf.log and RUBY_PLATFORM !~ /mswin32/
43
+ accesslog = WEBrick::BasicLog::new('/dev/null')
44
+ refererlog = WEBrick::BasicLog::new('/dev/null')
45
+ elsif (conf.accesslog || conf.refererlog)
46
+ accesslog = WEBrick::BasicLog::new(conf.accesslog || 'log/access.log')
47
+ refererlog = WEBrick::BasicLog::new(conf.refererlog || 'log/referer.log')
48
+ else
49
+ accesslog = STDERR
50
+ refererlog = STDERR
51
+ end
52
+
47
53
  @server = WEBrick::HTTPServer.new(
48
54
  :BindAddress => conf.host,
49
55
  :Port => conf.port,
50
56
  :DocumentRoot => conf.dispatcher.root,
51
57
  :AccessLog => [
52
58
  [accesslog, WEBrick::AccessLog::COMMON_LOG_FORMAT],
53
- [referer, WEBrick::AccessLog::REFERER_LOG_FORMAT]
59
+ [refererlog, WEBrick::AccessLog::REFERER_LOG_FORMAT]
54
60
  ]
55
61
  )
56
62
 
@@ -66,6 +72,8 @@ end
66
72
  # A Webrick Adaptor for Nitro.
67
73
 
68
74
  class WebrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
75
+
76
+ # REQUEST_MUTEX = Mutex.new
69
77
 
70
78
  def initialize(server, conf)
71
79
  @conf = conf
@@ -84,6 +92,11 @@ class WebrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
84
92
  if path =~ /\./
85
93
  @file_handler.do_GET(req, res)
86
94
  else
95
+ # gmosx, TODO: move this into a filter.
96
+ Og.db.get_connection if defined?(Og)
97
+
98
+ # REQUEST_MUTEX.lock
99
+
87
100
  context = Context.new(@conf)
88
101
 
89
102
  context.params = req.query
@@ -100,6 +113,9 @@ class WebrickAdaptor < WEBrick::HTTPServlet::AbstractServlet
100
113
  res.cookies = context.response_cookies || {}
101
114
  res.body = context.out
102
115
  end
116
+ ensure
117
+ # REQUEST_MUTEX.unlock if REQUEST_MUTEX.locked?
118
+ Og.db.put_connection if defined?(Og)
103
119
  end
104
120
 
105
121
  alias do_GET handle
@@ -1,32 +1,50 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
2
+ # (c) 2004-2005 Navel, all rights reserved.
5
3
  # $Id: rss.rb 202 2005-01-17 10:44:13Z gmosx $
6
4
 
7
5
  require 'rss/0.9'
8
6
 
7
+ require 'glue/string'
8
+
9
9
  module N
10
10
 
11
- # = RssBuilder
12
- #
13
11
  # Build RSS represenations of ruby object collections.
14
12
  # Utilize duck typing to grab the attributes to render.
15
13
  #--
16
14
  # TODO: add more options here, 1.0/2.0 support and more.
17
15
  #++
16
+
18
17
  class RssBuilder
19
18
 
20
- def self.render(objects)
19
+ class << self
20
+
21
+ # Options:
22
+ #
23
+ # [+:description+]
24
+ # Description of the Feed
25
+ # [+:base+]
26
+ # Base url of the Feed.
27
+ # [+:link+]
28
+ # Link of the Feed.
29
+
30
+ def render_0_9(objects, options = {})
31
+ c = {
32
+ :description => 'Syndication'
33
+ }.update(options)
34
+
35
+ c[:base] ||= c[:link]
36
+
37
+ raise "Option ':base' cannot be infered!" unless c[:base]
38
+
21
39
  channel = RSS::Rss::Channel.new
22
- channel.description = 'Syndication'
23
- channel.link = $srv_url
40
+ channel.description = c[:description]
41
+ channel.link = c[:link] if c[:link]
24
42
 
25
43
  for obj in objects
26
44
  item = RSS::Rss::Channel::Item.new
27
45
  item.title = obj.title if obj.respond_to?(:title)
28
46
  item.description = N::StringUtils.head(obj.body, 256) if obj.respond_to?(:body)
29
- item.link = "#$srv_url/#{obj.view_uri}" if obj.respond_to?(:view_uri)
47
+ item.link = "#{c[:base]}/#{obj.view_uri}" if obj.respond_to?(:view_uri)
30
48
  channel.items << item
31
49
  end
32
50
 
@@ -35,8 +53,10 @@ class RssBuilder
35
53
 
36
54
  return rss.to_s
37
55
  end
56
+ alias_method :render, :render_0_9
57
+
58
+ end
38
59
 
39
60
  end
40
61
 
41
- end # module
42
-
62
+ end
@@ -1,13 +1,11 @@
1
- # George Moschovitis <gm@navel.gr>
2
- # (c) 2005 Navel, all rights reserved.
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
3
  # $Id$
4
4
 
5
5
  require 'nitro/builders/xml'
6
6
 
7
7
  module N
8
8
 
9
- # = XhtmlBuilderMixin
10
- #
11
9
  # A helper mixin for programmatically building XHTML
12
10
  # blocks.
13
11
  #--
@@ -78,8 +76,6 @@ module XhtmlBuilderMixin
78
76
  end
79
77
  end
80
78
 
81
- # = XhtmlString
82
- #
83
79
  # A String extension with XHTML generation
84
80
  # functionality.
85
81
 
@@ -88,8 +84,6 @@ class XhtmlString < String
88
84
  include N::XhtmlBuilderMixin
89
85
  end
90
86
 
91
- # = XhtmlBuilder
92
- #
93
87
  # A class that encapsulats the XHTML generation
94
88
  # functionality. Utilizes duck typing to redirect
95
89
  # output to a target buffer.
@@ -7,6 +7,8 @@ require 'nitro/response'
7
7
  require 'nitro/render'
8
8
  require 'nitro/session'
9
9
 
10
+ require 'nitro/builders/xhtml'
11
+
10
12
  module N
11
13
 
12
14
  # Encapsulates an HTTP processing cycle context.
@@ -43,7 +45,7 @@ class Context
43
45
 
44
46
  # gmosx, FIXME: try to avoid creating this hash!
45
47
  @response_headers = {}
46
- @out = ''
48
+ @out = XhtmlString.new
47
49
  end
48
50
 
49
51
  # Lazy lookup of the session to avoid costly cookie
@@ -1,8 +1,6 @@
1
- #--
2
- # George Moschovitis <gm@navel.gr>
1
+ # * George Moschovitis <gm@navel.gr>
3
2
  # (c) 2004-2005 Navel, all rights reserved.
4
3
  # $Id$
5
- #++
6
4
 
7
5
  module N
8
6
 
@@ -24,15 +22,34 @@ class Dispatcher
24
22
 
25
23
  attr_accessor :apis
26
24
 
25
+ # Create a new Dispatcher.
26
+ #
27
+ # Input:
28
+ #
29
+ # [+controllers+]
30
+ # Either a hash of controller mappings or a single
31
+ # controller that gets mapped to :index.
32
+ #
33
+ # [+apis+]
34
+ # A hash of apis supported by the Dispatcher.
35
+
27
36
  def initialize(controllers = nil, apis = nil)
28
37
  @root = 'root'
29
- @controllers = controllers || { :index => Controller }
38
+
39
+ if controllers and controllers.is_a?(Class) and controllers.ancestors.include?(Controller)
40
+ @controllers = { :index => controllers }
41
+ else
42
+ @controllers = controllers || { :index => Controller }
43
+ end
44
+
30
45
  @apis = apis
31
46
  end
32
47
 
33
48
  # Process the given hash and mount the
34
49
  # defined controllers.
35
50
  #
51
+ # Input:
52
+ #
36
53
  # [+controllers+]
37
54
  # A hash representing the mapping of
38
55
  # mount points to controllers.
@@ -1,8 +1,6 @@
1
- #--
2
- # George Moschovitis <gm@navel.gr>
3
- # (c) 2004 Navel, all rights reserved.
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
4
3
  # $Id: filters.rb 215 2005-01-24 10:44:05Z gmosx $
5
- #++
6
4
 
7
5
  module N
8
6
 
@@ -29,7 +27,7 @@ module Filtering
29
27
 
30
28
  # Ruby is sometimes VERY surprising, the following trick is needed
31
29
  # to include singleton methods in other classes.
32
- #
30
+
33
31
  def self.append_features(base)
34
32
  super; base.extend(ClassMethods)
35
33
  end
@@ -54,43 +52,45 @@ module Filtering
54
52
  end
55
53
 
56
54
  #
57
- #
55
+
58
56
  def prepend_before_filter(*filters, &block)
59
57
  filters << block if block_given?
60
58
  @@before_filters = filters + @@before_filters
61
59
  end
62
60
 
63
61
  #
64
- #
62
+
65
63
  def append_before_filter(*filters, &block)
66
64
  filters << block if block_given?
67
65
  @@before_filters = @@before_filters + filters
68
66
  end
69
67
 
70
68
  # Alias for the most common case.
69
+
71
70
  alias :before_filter :prepend_before_filter
72
71
 
73
72
  #
74
- #
73
+
75
74
  def prepend_after_filter(*filters, &block)
76
75
  filters << block if block_given?
77
76
  @@after_filters = filters + @@after_filters
78
77
  end
79
78
 
80
79
  #
81
- #
80
+
82
81
  def append_after_filter(*filters, &block)
83
82
  filters << block if block_given?
84
83
  @@after_filters = @@after_filters + filters
85
84
  end
86
85
 
87
86
  # Alias for the most common case.
87
+
88
88
  alias :after_filter :append_after_filter
89
89
 
90
90
  # Install an arround Filter. A filter is a class that responds
91
91
  # to the before and after methods. Both methods are prepended to
92
92
  # the respective lists.
93
- #
93
+
94
94
  def prepend_arround_filter(*filters)
95
95
  filters = [filters].flatten
96
96
 
@@ -108,7 +108,7 @@ module Filtering
108
108
  # Install an arround Filter. A filter is a class that responds
109
109
  # to the before and after methods. Both methods are appended to
110
110
  # the respective lists.
111
- #
111
+
112
112
  def append_arround_filter(*filters)
113
113
  filters = [filters].flatten
114
114
 
@@ -127,7 +127,7 @@ module Filtering
127
127
  alias :filter :append_arround_filter
128
128
 
129
129
  #
130
- #
130
+
131
131
  def gen_filters_call_code(filters)
132
132
  code = ""
133
133