nitro 0.21.2 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
2
 
3
3
  require 'test/unit'
4
- require 'nitro/dispatcher'
4
+
5
+ require 'nitro'
5
6
  require 'nitro/dispatcher/general'
6
7
 
7
8
  class TC_Dispatcher < Test::Unit::TestCase # :nodoc: all
@@ -28,6 +28,12 @@ $source = %{
28
28
  </html>
29
29
  }
30
30
 
31
+ $source2 = %{
32
+ <x:box color="#ff0">
33
+ xhtml mode
34
+ </x:box>
35
+ }
36
+
31
37
  class Box < Nitro::Element
32
38
  def open
33
39
  %|<div style="color: #@color">|
@@ -41,5 +47,8 @@ end
41
47
  class TC_Element < Test::Unit::TestCase # :nodoc: all
42
48
  def test_all
43
49
  res = ElementProcessor.transform($source)
50
+ assert_match /div style/, res
51
+ res = ElementProcessor.transform($source2)
52
+ assert_match /div style/, res
44
53
  end
45
54
  end
@@ -0,0 +1,38 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+
5
+ require 'nitro/request'
6
+
7
+ class TC_Request < Test::Unit::TestCase # :nodoc: all
8
+ class DummyRequest
9
+ include Nitro::Request
10
+
11
+ def initialize
12
+ @headers = {}
13
+ end
14
+ end
15
+
16
+ def test_all
17
+ req = DummyRequest.new
18
+
19
+ req.headers['HTTP_HOST'] = 'www.nitrohq.com'
20
+ assert_equal 'nitrohq.com', req.domain
21
+ assert_equal 'www', req.subdomains.first
22
+
23
+ req.headers['HTTP_HOST'] = 'www.nitrohq.co.uk'
24
+ assert_equal 'nitrohq.co.uk', req.domain(2)
25
+
26
+ req.headers['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
27
+ assert req.xhr?
28
+
29
+ req.headers['REQUEST_METHOD'] = 'POST'
30
+
31
+ req.headers['CONTENT_TYPE'] = 'application/x-yaml'
32
+ assert req.yaml_post?
33
+
34
+ req.instance_variable_set '@post_format', nil
35
+ req.headers['CONTENT_TYPE'] = 'text/xml'
36
+ assert req.xml_post?
37
+ end
38
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: nitro
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.21.2
7
- date: 2005-07-28 00:00:00 +03:00
6
+ version: 0.22.0
7
+ date: 2005-08-07 00:00:00 +03:00
8
8
  summary: Nitro Web Engine
9
9
  require_paths:
10
10
  - lib
@@ -64,6 +64,7 @@ files:
64
64
  - proto/src
65
65
  - proto/run.rb
66
66
  - proto/README
67
+ - proto/script
67
68
  - proto/conf/lhttpd.conf
68
69
  - proto/conf/apache.conf
69
70
  - proto/doc/README
@@ -82,31 +83,30 @@ files:
82
83
  - proto/public/js/behaviour.js
83
84
  - proto/public/js/controls.js
84
85
  - proto/public/js/effects.js
86
+ - proto/script/runner
85
87
  - lib/nitro
86
88
  - lib/nitro.rb
87
89
  - lib/nitro/server
88
- - lib/nitro/testing
89
90
  - lib/nitro/session
90
91
  - lib/nitro/adapter
91
92
  - lib/nitro/caching
92
93
  - lib/nitro/element
94
+ - lib/nitro/test
93
95
  - lib/nitro/controller.rb
94
96
  - lib/nitro/scaffold.rb
95
- - lib/nitro/mail.rb
96
97
  - lib/nitro/dispatcher.rb
97
98
  - lib/nitro/context.rb
98
99
  - lib/nitro/dispatcher
99
100
  - lib/nitro/request.rb
100
101
  - lib/nitro/mixin
101
102
  - lib/nitro/caching.rb
103
+ - lib/nitro/test.rb
102
104
  - lib/nitro/compiler
103
105
  - lib/nitro/cookie.rb
104
- - lib/nitro/testing.rb
105
106
  - lib/nitro/render.rb
106
107
  - lib/nitro/session.rb
107
108
  - lib/nitro/routing.rb
108
109
  - lib/nitro/response.rb
109
- - lib/nitro/template.rb
110
110
  - lib/nitro/element.rb
111
111
  - lib/nitro/service.rb
112
112
  - lib/nitro/service
@@ -114,9 +114,6 @@ files:
114
114
  - lib/nitro/server.rb
115
115
  - lib/nitro/compiler.rb
116
116
  - lib/nitro/server/runner.rb
117
- - lib/nitro/testing/assertions.rb
118
- - lib/nitro/testing/context.rb
119
- - lib/nitro/testing/testcase.rb
120
117
  - lib/nitro/session/drbserver.rb
121
118
  - lib/nitro/session/drb.rb
122
119
  - lib/nitro/session/memory.rb
@@ -131,6 +128,9 @@ files:
131
128
  - lib/nitro/caching/output.rb
132
129
  - lib/nitro/caching/fragments.rb
133
130
  - lib/nitro/element/java_script.rb
131
+ - lib/nitro/test/assertions.rb
132
+ - lib/nitro/test/context.rb
133
+ - lib/nitro/test/testcase.rb
134
134
  - lib/nitro/dispatcher/nice.rb
135
135
  - lib/nitro/dispatcher/general.rb
136
136
  - lib/nitro/mixin/debug.rb
@@ -157,8 +157,6 @@ files:
157
157
  - test/nitro/mixin
158
158
  - test/nitro/ui
159
159
  - test/nitro/adapter
160
- - test/nitro/tc_template.rb
161
- - test/nitro/tc_mail.rb
162
160
  - test/nitro/tc_controller.rb
163
161
  - test/nitro/tc_session.rb
164
162
  - test/nitro/tc_context.rb
@@ -167,7 +165,9 @@ files:
167
165
  - test/nitro/tc_caching.rb
168
166
  - test/nitro/tc_flash.rb
169
167
  - test/nitro/tc_server.rb
168
+ - test/nitro/tc_request.rb
170
169
  - test/nitro/tc_cookie.rb
170
+ - test/nitro/tc_controller_aspect.rb
171
171
  - test/nitro/mixin/tc_pager.rb
172
172
  - test/nitro/mixin/tc_rss.rb
173
173
  - test/nitro/mixin/tc_table.rb
@@ -208,7 +208,7 @@ dependencies:
208
208
  -
209
209
  - "="
210
210
  - !ruby/object:Gem::Version
211
- version: 0.21.2
211
+ version: 0.22.0
212
212
  version:
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: og
@@ -218,7 +218,7 @@ dependencies:
218
218
  -
219
219
  - "="
220
220
  - !ruby/object:Gem::Version
221
- version: 0.21.2
221
+ version: 0.22.0
222
222
  version:
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: ruby-breakpoint
@@ -1,270 +0,0 @@
1
- # Based on original code from the RubyOnRails project.
2
- # http://www.rubyonrails.com
3
- # Copyright (c) 2004 David Heinemeier Hansson
4
-
5
- require 'net/smtp'
6
-
7
- require 'glue/attribute'
8
- require 'nitro/template'
9
-
10
- module Nitro
11
-
12
- # Encapsulates an email message.
13
-
14
- class Mail
15
-
16
- # Sender, can be an array.
17
-
18
- attr_accessor :from
19
-
20
- # The list of the recipients, can be arrays.
21
-
22
- attr_accessor :to, :cc, :bcc
23
-
24
- # The subject
25
-
26
- attr_accessor :subject
27
-
28
- # The body of the message.
29
-
30
- attr_accessor :body
31
-
32
- # Reply to.
33
-
34
- attr_accessor :reply_to
35
-
36
- # Sent on
37
-
38
- attr_accessor :sent_on
39
-
40
- # Encode the subject?
41
-
42
- attr_accessor :encode_subject
43
-
44
- # The charset used to encode the message.
45
-
46
- attr_accessor :charset
47
-
48
- # Additional headers
49
-
50
- attr_accessor :headers
51
-
52
- def initialize(from = nil, to = nil, subject = nil, body = nil)
53
- @from, @to, @subject, @body = from, to, subject, body
54
- @headers = {}
55
- end
56
-
57
- def [](key)
58
- @headers[key]
59
- end
60
-
61
- def []=(key, value)
62
- @headers[key] = value
63
- end
64
-
65
- # Returns the Mail message in encoded format.
66
-
67
- def encoded
68
- raise 'No body defined' unless @body
69
- raise 'No sender defined' unless @from
70
- raise 'No recipients defined' unless @to
71
-
72
- # gmosx: From is typically NOT an array.
73
-
74
- from = @from.is_a?(Array) ? @from.join(', ') : @from
75
- buf = "From: #{from}\n"
76
-
77
- to = @to.is_a?(Array) ? @to.join(', ') : @to
78
- buf << "To: #{to}\n"
79
-
80
- if @cc
81
- cc = @cc.is_a?(Array) ? @cc.join(', ') : @cc
82
- buf << "Cc: #{cc}\n"
83
- end
84
-
85
- if @bcc
86
- bcc = @bcc.is_a?(Array) ? @bcc.join(', ') : @bcc
87
- buf << "Bcc: #{bcc}\n"
88
- end
89
-
90
- buf << "Subject: #@subject\n" if @subject
91
-
92
- buf << "\n"
93
- buf << @body
94
-
95
- return buf
96
- end
97
- end
98
-
99
- module MailerMixin
100
-
101
- def self.append_features(base) # :nodoc:
102
- super
103
- base.extend(SingletonMethods)
104
- end
105
-
106
- module SingletonMethods
107
-
108
- def mailer(klass)
109
- end
110
-
111
- end
112
-
113
- end
114
-
115
- # A flexible mailing service.
116
- #--
117
- # TODO: add callback/observers support.
118
- #++
119
-
120
- class Mailer < Mail
121
-
122
- # The mail server configuration.
123
-
124
- cattr_accessor :server; @@server = {
125
- :address => 'localhost',
126
- :port => 25,
127
- :domain => 'localhost.localdomain',
128
- :username => nil,
129
- :password => nil,
130
- :authentication => nil
131
- }
132
-
133
- # The delivery method. The following options are
134
- # supported:
135
- #
136
- # * :smtp
137
- # * :sendmail
138
- # * :test
139
-
140
- cattr_accessor :delivery_method; @@delivery_method = :smtp
141
-
142
- # The encode subject.
143
-
144
- cattr_accessor :encode_subject; @@encode_subject = false # true
145
-
146
- # The default charset.
147
-
148
- cattr_accessor :default_charset, 'utf-8'
149
-
150
- # An array to store the delivered mails, useful
151
- # for testing.
152
-
153
- cattr_accessor :deliveries; @@deliveries = []
154
-
155
- # Disable deliveries, useful for testing.
156
-
157
- cattr_accessor :disable_deliveries, false
158
-
159
- # The root directory where the templates reside
160
-
161
- attr_accessor :template_root
162
-
163
- def initialize(from = nil, to = nil, subject = nil, body = FileTemplate.new)
164
- super
165
- @charset = @@default_charset.dup
166
- @encode_subject = @@encode_subject
167
- @template_root = 'public'
168
- end
169
-
170
- class << self
171
-
172
- def method_missing(method_symbol, *params) #:nodoc:
173
- case method_symbol.id2name
174
- when /^create_([_a-z]*)/
175
- create_from_method($1, *params)
176
- when /^deliver_([_a-z]*)/
177
- begin
178
- deliver(send("create_" + $1, *params))
179
- rescue Object => e
180
- raise e # FIXME
181
- end
182
- end
183
- end
184
-
185
- def mail(from, to, subject, body, timestamp = nil, headers = {}, encode = @@encode_subject, charset = @@default_charset) #:nodoc:
186
- deliver(create(from, to, subject, body, timestamp, headers, charset))
187
- end
188
-
189
- def create(from, to, subject, body, timestamp = nil, headers = {}, encode = @@encode_subject, charset = @@default_charset) #:nodoc:
190
- m = Mail.new
191
- m.to, m.subject, m.body, m.from = to, ( encode ? quoted_printable(subject, charset) : subject ), body, from
192
- # m.date = timestamp.respond_to?("to_time") ? timestamp.to_time : (timestamp || Time.now)
193
- # m.set_content_type "text", "plain", { "charset" => charset }
194
- headers.each do |k, v|
195
- m[k] = v
196
- end
197
- return m
198
- end
199
-
200
- def deliver(mail) #:nodoc:
201
- send("perform_delivery_#{delivery_method}", mail) unless disable_deliveries
202
- end
203
-
204
- def quoted_printable(text, charset) #:nodoc:
205
- text = text.gsub( /[^a-z ]/i ) { "=%02x" % $&[0] }.gsub( / /, "_" )
206
- "=?#{charset}?Q?#{text}?="
207
- end
208
-
209
- private
210
-
211
- def create_from_method(method_name, *params)
212
- mailer = new
213
-
214
- mailer.send(method_name, *params)
215
-
216
- unless mailer.body.is_a?(String)
217
- mailer.body = render_body(method_name, mailer)
218
- end
219
-
220
- mail = create(
221
- mailer.from, mailer.to, mailer.subject,
222
- mailer.body, mailer.sent_on,
223
- mailer.headers, mailer.charset
224
- )
225
-
226
- mail.cc = mailer.cc if mailer.cc
227
- mail.bcc = mailer.bcc if mailer.bcc
228
-
229
- return mail
230
- end
231
-
232
- # Render the body by expanfing the template
233
-
234
- def render_body(method_name, mailer)
235
- mailer.body.template_filename = "#{mailer.template_root}/#{method_name.to_s}.xhtml"
236
- return mailer.body.process
237
- end
238
-
239
- # Deliver emails using SMTP.
240
-
241
- def perform_delivery_smtp(mail) # :nodoc:
242
- c = @@server
243
- Net::SMTP.start(c[:address], c[:port], c[:domain], c[:username], c[:password], c[:authentication]) do |smtp|
244
- smtp.send_message(mail.encoded, mail.from, mail.to)
245
- end
246
- end
247
-
248
- # Deliver emails using sendmail.
249
-
250
- def perform_delivery_sendmail(mail) # :nodoc:
251
- IO.popen('/usr/sbin/sendmail -i -t', 'w+') do |sm|
252
- sm.print(mail.encoded)
253
- sm.flush
254
- end
255
- end
256
-
257
- # Used for testing, does not actually send the
258
- # mail.
259
-
260
- def perform_delivery_test(mail) # :nodoc:
261
- deliveries << mail
262
- end
263
-
264
- end
265
-
266
- end
267
-
268
- end
269
-
270
- # * George Moschovitis <gm@navel.gr>
@@ -1,202 +0,0 @@
1
- require 'glue/flexob'
2
- require 'glue/configuration'
3
-
4
- module Nitro
5
-
6
- # A template is a text file with embeded Ruby code. The template
7
- # processor converts the original text file to ruby code and
8
- # then evaluates this code to produce the result of the
9
- # template transformation.
10
-
11
- module TemplateMixin
12
-
13
- # Convert a template to actual Ruby code, ready to be
14
- # evaluated.
15
- #
16
- # [+template+]
17
- # The template as a String.
18
- #
19
- # [+buffer+]
20
- # The variable to act as a buffer where the ruby code
21
- # for this template will be generated. Passed as a|
22
- # String.
23
- #
24
- # [+base_dir+]
25
- # The base directory where the templates reside.
26
-
27
- def compile_template(template, buffer = '@out', base_dir = Dir.pwd)
28
- text = template.dup
29
-
30
- # Strip the xml header! (interracts with the following gsub!)
31
- text.gsub!(/<\?xml.*\?>/, "")
32
-
33
- # Statically include sub-template files.
34
- # The target file is included at compile time.
35
- #
36
- # gmosx: must be xformed before the <?r pi.
37
- #
38
- # Example:
39
- # <?include href="root/myfile.sx" ?>
40
-
41
- text.gsub!(/<\?include href=["|'](.*?)["|'](.*)\?>/) do |match|
42
- text = File.read("#{base_dir}/#$1")
43
- text.gsub!(/<\?xml.*\?>/, '')
44
- text.gsub!(/<\/?root(.*?)>/m, ' ');
45
- text
46
- end
47
-
48
- # Transform include instructions <include href="xxx" />
49
- # must be transformed before the processinc instructions.
50
- # Useful to include fragments cached on disk
51
- #
52
- # gmosx, FIXME: NOT TESTED! test and add caching.
53
- # add load_statically_included fixes.
54
-
55
- text.gsub!(/<include href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
56
- "<?r File.read( '\#\{@dispatcher.root\}/#$1' ?>"
57
- end
58
-
59
- # xform render/inject instructions <render href="xxx" />
60
- # must be transformed before the processinc instructions.
61
-
62
- text.gsub!(/<inject href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
63
- "<?r render '/#$1' ?>"
64
- end
65
-
66
- text.gsub!(/<render href=["|'](.*?)["|'](.*)(.?)\/>/) do |match|
67
- "<?r render '/#$1' ?>"
68
- end
69
-
70
- # Remove <root> elements. typically removed by xslt but lets
71
- # play it safe. The <root> element is typically added to
72
- # template files to make them XHTML valid.
73
-
74
- text.gsub!(/<(\/)?root>/, '')
75
-
76
- # Transform the processing instructions, use <?r as
77
- # a marker.
78
-
79
- text.gsub!(/\?>/, "; #{buffer} << %^")
80
- text.gsub!(/<\?r(\s?)/, "^; ")
81
-
82
- # Transform alternative code tags.
83
- # (very useful in xsl stylesheets)
84
-
85
- text.gsub!(/<\/ruby>/, "; #{buffer} << %^")
86
- text.gsub!(/<ruby>/, "^; ")
87
-
88
- # Also handle erb/asp/jsp style tags. Those tags
89
- # *cannot* be used with an xslt stylesheet.
90
-
91
- text.gsub!(/%>/, "; #{buffer} << %^")
92
- text.gsub!(/<%/, "^; ")
93
-
94
- # Alterative versions of interpolation.
95
- # (very useful in xsl stylesheets)
96
- # Example: #\my_val\
97
-
98
- text.gsub!(/\#\\(.*?)\\/, '#{\1}')
99
-
100
- # Alternative for entities.
101
- # (useful in xsl stylesheets)
102
- # Examples: %nbsp;, %rquo;
103
-
104
- text.gsub!(/%(\S*?);/, '&\1;')
105
-
106
- # Compile time ruby code. This code is evaluated when
107
- # compiling the template and the result injected directly
108
- # into the result. Usefull for example to prevaluate
109
- # localization. Just use the #[] marker instead of #{}.
110
-
111
- text.gsub!(/\#\[(.*?)\]/) do |match|
112
- eval($1)
113
- end
114
-
115
- text = "#{buffer} << %^" + text + "^"
116
-
117
- return text
118
- end
119
-
120
- # Render the template.
121
- #
122
- # [+ruby+]
123
- # A String containing the compiled template
124
- # code.
125
- #
126
- # [+binding+]
127
- # The evaluation binding for the rendering.
128
-
129
- def render_template(ruby, the_binding = nil)
130
- eval(ruby, the_binding)
131
- end
132
-
133
- # Compile and render the template.
134
-
135
- def process_template(template, buffer = '@out', the_binding = nil)
136
- render_template(compile_template(template, buffer), the_binding)
137
- end
138
-
139
- end
140
-
141
- # A helper class that provides access to the Template methods
142
- # as singleton methods.
143
-
144
- class Template
145
-
146
- # The default root directory where template files reside.
147
-
148
- setting :root, :default => 'public', :doc => 'The default root directory where template files reside'
149
-
150
- # The default template name.
151
-
152
- setting :default, :default => 'index', :doc => 'The default template name'
153
-
154
- # The default template file extension.
155
-
156
- setting :extension, :default => 'xhtml', :doc => 'The default template file extension'
157
-
158
- class << self
159
- include TemplateMixin
160
- alias_method :compile, :compile_template
161
- alias_method :transform, :compile_template
162
- alias_method :render, :render_template
163
- alias_method :process, :process_template
164
- end
165
-
166
- end
167
-
168
- # A Template that reads from files and also
169
- # provides a simple but effective caching scheme.
170
- # An intuitive binding mechanism provides the
171
- # expansion environment.
172
-
173
- class FileTemplate < Flexob
174
- include TemplateMixin
175
-
176
- @@compiled_template_cache = {}
177
-
178
- attr_accessor :template_filename
179
-
180
- def initialize(filename = nil)
181
- super
182
- @template_filename = filename
183
- end
184
-
185
- def process
186
- __out__ = ''
187
-
188
- unless compiled = @@compiled_template_cache[@template_filename]
189
- template = File.read(@template_filename)
190
- compiled = compile_template(template, '__out__')
191
- @@compiled_template_cache[@template_filename] = compiled
192
- end
193
-
194
- render_template(compiled, binding)
195
-
196
- return __out__
197
- end
198
- end
199
-
200
- end
201
-
202
- # * George Moschovitis <gm@navel.gr>