nitro 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +752 -543
- data/INSTALL +38 -38
- data/README +264 -225
- data/Rakefile +48 -49
- data/bin/nitro +3 -3
- data/bin/nitrogen +6 -6
- data/doc/AUTHORS +10 -10
- data/doc/CHANGELOG.1 +1939 -1939
- data/doc/CHANGELOG.2 +954 -954
- data/doc/LICENSE +3 -3
- data/doc/MIGRATION +28 -0
- data/doc/RELEASES +814 -643
- data/doc/config.txt +5 -5
- data/install.rb +7 -17
- data/lib/nitro.rb +38 -9
- data/lib/nitro/adapter/cgi.rb +311 -312
- data/lib/nitro/adapter/fastcgi.rb +18 -25
- data/lib/nitro/adapter/webrick.rb +128 -137
- data/lib/nitro/adapter/wee.rb +51 -0
- data/lib/nitro/caching.rb +20 -20
- data/lib/nitro/caching/actions.rb +43 -43
- data/lib/nitro/caching/fragments.rb +46 -46
- data/lib/nitro/caching/invalidation.rb +11 -11
- data/lib/nitro/caching/output.rb +65 -65
- data/lib/nitro/caching/stores.rb +67 -67
- data/lib/nitro/compiler.rb +262 -0
- data/lib/nitro/compiler/elements.rb +0 -0
- data/lib/nitro/compiler/errors.rb +65 -0
- data/lib/nitro/compiler/localization.rb +25 -0
- data/lib/nitro/compiler/markup.rb +19 -0
- data/lib/nitro/compiler/shaders.rb +206 -0
- data/lib/nitro/compiler/squeeze.rb +20 -0
- data/lib/nitro/compiler/xslt.rb +61 -0
- data/lib/nitro/context.rb +87 -88
- data/lib/nitro/controller.rb +151 -158
- data/lib/nitro/cookie.rb +34 -34
- data/lib/nitro/dispatcher.rb +195 -186
- data/lib/nitro/element.rb +132 -126
- data/lib/nitro/element/java_script.rb +6 -6
- data/lib/nitro/flash.rb +66 -66
- data/lib/nitro/mail.rb +192 -192
- data/lib/nitro/mixin/buffer.rb +66 -0
- data/lib/nitro/mixin/debug.rb +16 -16
- data/lib/nitro/mixin/form.rb +88 -0
- data/lib/nitro/mixin/helper.rb +2 -2
- data/lib/nitro/mixin/javascript.rb +108 -108
- data/lib/nitro/mixin/markup.rb +144 -0
- data/lib/nitro/mixin/pager.rb +202 -202
- data/lib/nitro/mixin/rss.rb +67 -0
- data/lib/nitro/mixin/table.rb +63 -0
- data/lib/nitro/mixin/xhtml.rb +75 -0
- data/lib/nitro/mixin/xml.rb +124 -0
- data/lib/nitro/render.rb +183 -359
- data/lib/nitro/request.rb +140 -140
- data/lib/nitro/response.rb +27 -27
- data/lib/nitro/routing.rb +21 -21
- data/lib/nitro/scaffold.rb +124 -118
- data/lib/nitro/server.rb +117 -80
- data/lib/nitro/server/runner.rb +341 -0
- data/lib/nitro/service.rb +12 -12
- data/lib/nitro/service/xmlrpc.rb +22 -22
- data/lib/nitro/session.rb +122 -120
- data/lib/nitro/session/drb.rb +9 -9
- data/lib/nitro/session/drbserver.rb +34 -34
- data/lib/nitro/template.rb +171 -155
- data/lib/nitro/testing/assertions.rb +90 -90
- data/lib/nitro/testing/context.rb +16 -16
- data/lib/nitro/testing/testcase.rb +34 -34
- data/proto/conf/lhttpd.conf +9 -9
- data/proto/public/error.xhtml +75 -75
- data/proto/public/index.xhtml +18 -18
- data/proto/public/js/behaviour.js +65 -65
- data/proto/public/js/controls.js +1 -1
- data/proto/public/js/prototype.js +3 -3
- data/proto/public/settings.xhtml +61 -61
- data/proto/run.rb +1 -5
- data/test/nitro/adapter/raw_post1.bin +0 -0
- data/test/nitro/adapter/tc_cgi.rb +57 -57
- data/test/nitro/adapter/tc_webrick.rb +4 -4
- data/test/nitro/mixin/tc_pager.rb +25 -25
- data/test/nitro/mixin/tc_rss.rb +24 -0
- data/test/nitro/mixin/tc_table.rb +31 -0
- data/test/nitro/mixin/tc_xhtml.rb +13 -0
- data/test/nitro/tc_caching.rb +10 -10
- data/test/nitro/tc_context.rb +8 -8
- data/test/nitro/tc_controller.rb +48 -48
- data/test/nitro/tc_cookie.rb +6 -6
- data/test/nitro/tc_dispatcher.rb +64 -64
- data/test/nitro/tc_element.rb +27 -27
- data/test/nitro/tc_flash.rb +31 -31
- data/test/nitro/tc_mail.rb +63 -63
- data/test/nitro/tc_server.rb +26 -26
- data/test/nitro/tc_session.rb +9 -9
- data/test/nitro/tc_template.rb +19 -19
- data/test/public/blog/list.xhtml +1 -1
- metadata +31 -37
- data/lib/nitro/buffering.rb +0 -45
- data/lib/nitro/builder/form.rb +0 -104
- data/lib/nitro/builder/rss.rb +0 -104
- data/lib/nitro/builder/table.rb +0 -80
- data/lib/nitro/builder/xhtml.rb +0 -132
- data/lib/nitro/builder/xml.rb +0 -131
- data/lib/nitro/conf.rb +0 -36
- data/lib/nitro/environment.rb +0 -21
- data/lib/nitro/errors.rb +0 -69
- data/lib/nitro/localization.rb +0 -153
- data/lib/nitro/markup.rb +0 -147
- data/lib/nitro/output.rb +0 -24
- data/lib/nitro/runner.rb +0 -348
- data/lib/nitro/shaders.rb +0 -206
- data/test/nitro/builder/tc_rss.rb +0 -23
- data/test/nitro/builder/tc_table.rb +0 -30
- data/test/nitro/builder/tc_xhtml.rb +0 -39
- data/test/nitro/builder/tc_xml.rb +0 -56
- data/test/nitro/tc_localization.rb +0 -49
data/lib/nitro/runner.rb
DELETED
@@ -1,348 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
|
5
|
-
require 'glue/misc'
|
6
|
-
require 'glue/configuration'
|
7
|
-
|
8
|
-
require 'nitro/conf'
|
9
|
-
|
10
|
-
module Nitro
|
11
|
-
|
12
|
-
# The Runner is a helper class that encapsulates a web
|
13
|
-
# application and is responsible for launching the
|
14
|
-
# application in differnt modes.
|
15
|
-
#
|
16
|
-
# The runner provides default parsing of command line
|
17
|
-
# and environment parameters.
|
18
|
-
#
|
19
|
-
# The default execution modes are:
|
20
|
-
#
|
21
|
-
# :debug, :stage, :live
|
22
|
-
#
|
23
|
-
# You can implement your own, custom version of the Runner
|
24
|
-
# to run your custom web applications.
|
25
|
-
|
26
|
-
class Runner
|
27
|
-
|
28
|
-
# Execution mode = (:debug, :stage, :live)
|
29
|
-
#
|
30
|
-
# [:debug]
|
31
|
-
# useful when debugging, extra debug information
|
32
|
-
# is emmited, actions, templates and shaders are
|
33
|
-
# reloaded, etc. The execution speed of the application
|
34
|
-
# is impaired.
|
35
|
-
#
|
36
|
-
# [:stage]
|
37
|
-
# test the application with live parameters
|
38
|
-
# (typically on a staging server).
|
39
|
-
#
|
40
|
-
# [:live]
|
41
|
-
# use the parameters for the live (production)
|
42
|
-
# server. Optimized for speed.
|
43
|
-
#
|
44
|
-
# The default mode is :debug
|
45
|
-
|
46
|
-
attr :mode
|
47
|
-
|
48
|
-
# :start, :stop, :restart
|
49
|
-
|
50
|
-
attr :action
|
51
|
-
|
52
|
-
# The server used to run this web application.
|
53
|
-
# :webrick, :nitro, :lhttp, :apache, :mod_apache
|
54
|
-
#
|
55
|
-
# At the moment only :webrick and :lhttp are available.
|
56
|
-
|
57
|
-
attr :server
|
58
|
-
|
59
|
-
# Run as daemon.
|
60
|
-
|
61
|
-
attr :daemon
|
62
|
-
|
63
|
-
# Spidering mode. Acceptable values are :crawl, :render
|
64
|
-
# and false.
|
65
|
-
|
66
|
-
attr :spider
|
67
|
-
|
68
|
-
# Parse the command line arguments and the environment
|
69
|
-
# parameters to setup the application.
|
70
|
-
|
71
|
-
def setup
|
72
|
-
|
73
|
-
@mode = :debug
|
74
|
-
@action = :start
|
75
|
-
@server = :webrick
|
76
|
-
@daemon = false
|
77
|
-
@spider = false
|
78
|
-
|
79
|
-
parser = OptionParser.new do |opts|
|
80
|
-
|
81
|
-
opts.banner = 'Usage: run.rb [options]'
|
82
|
-
opts.separator ''
|
83
|
-
opts.separator 'Specific options:'
|
84
|
-
|
85
|
-
opts.on('-s', '--start', 'Start application.') do
|
86
|
-
@action = :start
|
87
|
-
end
|
88
|
-
|
89
|
-
opts.on('-S', '--stop', 'Stop application.') do
|
90
|
-
@action = :stop
|
91
|
-
end
|
92
|
-
|
93
|
-
opts.on('-r', '--restart', 'Restart application.') do
|
94
|
-
@action = :restart
|
95
|
-
end
|
96
|
-
|
97
|
-
opts.on('-d', '--daemon', 'Run application as a daemon.') do
|
98
|
-
@daemon = true
|
99
|
-
end
|
100
|
-
|
101
|
-
opts.on('-D', '--debug', 'Run application in debug mode.') do
|
102
|
-
@mode = :debug
|
103
|
-
end
|
104
|
-
|
105
|
-
opts.on('-T', '--stage', 'Run application in stage mode.') do
|
106
|
-
@mode = :stage
|
107
|
-
end
|
108
|
-
|
109
|
-
opts.on('-L', '--live', 'Run application in live mode.') do
|
110
|
-
@mode = :live
|
111
|
-
end
|
112
|
-
|
113
|
-
opts.on('-w', '--webrick', 'Use a webrick server [default].') do
|
114
|
-
@server = :webrick
|
115
|
-
end
|
116
|
-
|
117
|
-
opts.on('-l', '--lhttpd', 'Use a lighttpd server.') do
|
118
|
-
@server = :lhttpd
|
119
|
-
Logger.set(Logger.new('log/app.log'))
|
120
|
-
end
|
121
|
-
|
122
|
-
opts.on('-a', '--apache', 'Use an apache server.') do
|
123
|
-
@server = :apache
|
124
|
-
Logger.set(Logger.new('log/app.log'))
|
125
|
-
end
|
126
|
-
|
127
|
-
opts.on('--apache-cgi', 'Run as CGI (Apache)') do
|
128
|
-
@server = :cgi
|
129
|
-
Logger.set(Logger.new('log/app.log'))
|
130
|
-
end
|
131
|
-
|
132
|
-
opts.on('-C', '--console', 'Start a console attached to an instance of the application.') do
|
133
|
-
if RUBY_PLATFORM =~ /mswin32/
|
134
|
-
irb_name = 'irb.bat'
|
135
|
-
else
|
136
|
-
irb_name = 'irb'
|
137
|
-
end
|
138
|
-
ENV['NITRO_INVOKE'] = 'irb'
|
139
|
-
conf_file = File.basename(caller.last.split(':').first)
|
140
|
-
# exec "#{irb_name} -r #{conf_file} -r irb/completion --noinspect"
|
141
|
-
exec "#{irb_name} -r #{conf_file} --noinspect"
|
142
|
-
exit
|
143
|
-
end
|
144
|
-
|
145
|
-
opts.on('--crawl', 'Crawl the application.') do
|
146
|
-
@server = :webrick
|
147
|
-
@spider = :crawl
|
148
|
-
end
|
149
|
-
|
150
|
-
opts.on('--render', 'Crawl the application and render all pages as static html files.') do
|
151
|
-
@server = :webrick
|
152
|
-
@spider = :render
|
153
|
-
end
|
154
|
-
|
155
|
-
opts.on_tail('-v', '--version', 'Show version.') do
|
156
|
-
puts "Nitro #{Nitro::Version}"
|
157
|
-
exit
|
158
|
-
end
|
159
|
-
|
160
|
-
opts.on_tail('-h', '--help', 'Show this message.') do
|
161
|
-
puts opts
|
162
|
-
exit
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
parser.parse!(ARGV)
|
168
|
-
|
169
|
-
return self
|
170
|
-
end
|
171
|
-
|
172
|
-
# Run the application in the declared execution mode,
|
173
|
-
# using the passed configuration parameters.
|
174
|
-
|
175
|
-
def run(conf)
|
176
|
-
if conf.is_a?(Hash)
|
177
|
-
conf = Conf.new(conf)
|
178
|
-
end
|
179
|
-
|
180
|
-
case @mode
|
181
|
-
when :debug
|
182
|
-
setup_debug(conf)
|
183
|
-
|
184
|
-
when :stage
|
185
|
-
setup_stage(conf)
|
186
|
-
|
187
|
-
when :live
|
188
|
-
setup_live(conf)
|
189
|
-
end
|
190
|
-
|
191
|
-
if 'fcgi_proc' == ENV['NITRO_INVOKE']
|
192
|
-
invoke_fcgi_proc(conf)
|
193
|
-
elsif 'cgi_proc' == ENV['NITRO_INVOKE']
|
194
|
-
invoke_cgi_proc(conf)
|
195
|
-
elsif 'irb' == ENV['NITRO_INVOKE']
|
196
|
-
invoke_irb(conf)
|
197
|
-
else
|
198
|
-
invoke_server(conf)
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
def setup_debug(conf)
|
204
|
-
$DBG = true
|
205
|
-
Rendering.reload = :full
|
206
|
-
require 'glue/autoreload'
|
207
|
-
autoreload(3)
|
208
|
-
Caching.caching_enabled = false
|
209
|
-
end
|
210
|
-
|
211
|
-
def setup_stage(conf)
|
212
|
-
$DBG = false
|
213
|
-
Rendering.reload = false
|
214
|
-
Logger.set(Logger.new('log/app.log'))
|
215
|
-
end
|
216
|
-
|
217
|
-
def setup_live(conf)
|
218
|
-
$DBG = false
|
219
|
-
Rendering.reload = false
|
220
|
-
Logger.set(Logger.new('log/app.log'))
|
221
|
-
end
|
222
|
-
alias_method :setup_production, :setup_live
|
223
|
-
|
224
|
-
def invoke_fcgi_proc(conf)
|
225
|
-
require 'nitro/adapter/fastcgi'
|
226
|
-
FastCGI.start(conf)
|
227
|
-
end
|
228
|
-
|
229
|
-
def invoke_cgi_proc(conf)
|
230
|
-
require 'nitro/adapter/cgi'
|
231
|
-
Cgi.start(conf)
|
232
|
-
end
|
233
|
-
|
234
|
-
def invoke_irb(conf)
|
235
|
-
$conf = conf
|
236
|
-
end
|
237
|
-
|
238
|
-
def invoke_server(conf)
|
239
|
-
spider_thread = nil
|
240
|
-
|
241
|
-
case @action
|
242
|
-
when :start
|
243
|
-
|
244
|
-
case @spider
|
245
|
-
when :render
|
246
|
-
spider_thread = Thread.new do
|
247
|
-
sleep(6)
|
248
|
-
`wget -k -m -p #{conf.host}:#{conf.port} -directory-prefix=rendered`
|
249
|
-
end
|
250
|
-
when :crawl
|
251
|
-
spider_thread = Thread.new do
|
252
|
-
sleep(6)
|
253
|
-
`wget -m --spider #{conf.host}:#{conf.port}`
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
puts "\n==> Listening at #{conf.host}:#{conf.port}.\n\n"
|
258
|
-
|
259
|
-
case @server
|
260
|
-
when :webrick
|
261
|
-
require 'nitro/adapter/webrick'
|
262
|
-
Webrick.start(conf)
|
263
|
-
|
264
|
-
when :lhttpd
|
265
|
-
require 'nitro/adapter/fastcgi'
|
266
|
-
`lighttpd -f conf/lhttpd.conf`
|
267
|
-
|
268
|
-
when :apache
|
269
|
-
require 'nitro/adapter/fastcgi'
|
270
|
-
`apachectl -d #{Dir.pwd} -f conf/apache.conf -k start`
|
271
|
-
|
272
|
-
when :cgi
|
273
|
-
require 'nitro/adapter/cgi'
|
274
|
-
end
|
275
|
-
|
276
|
-
when :stop
|
277
|
-
|
278
|
-
case @server
|
279
|
-
when :webrick
|
280
|
-
|
281
|
-
when :lhttpd
|
282
|
-
|
283
|
-
when :apache
|
284
|
-
`apachectl -d #{Dir.pwd} -f conf/apache.conf -k stop`
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
def daemonize
|
291
|
-
require 'daemons/daemonize'
|
292
|
-
pwd = Dir.pwd
|
293
|
-
Daemonize.daemonize(File.join(pwd, 'log/app.log'))
|
294
|
-
# Restore the original pwd (daemonize sets the
|
295
|
-
# pwd to '/').
|
296
|
-
Dir.chdir(pwd)
|
297
|
-
# Set the logger to a file (daemonize closes the
|
298
|
-
# std streams).
|
299
|
-
Logger.set(Logger.new('log/app.log'))
|
300
|
-
end
|
301
|
-
|
302
|
-
# Helper method.
|
303
|
-
|
304
|
-
def self.run(conf)
|
305
|
-
runner = Runner.new.setup.run(conf)
|
306
|
-
end
|
307
|
-
|
308
|
-
end
|
309
|
-
|
310
|
-
# Helper method to start applications.
|
311
|
-
#
|
312
|
-
# === Example
|
313
|
-
#
|
314
|
-
# Nitro.run do |conf|
|
315
|
-
# conf.port = 8080
|
316
|
-
# conf.template_root = 'root'
|
317
|
-
# end
|
318
|
-
#
|
319
|
-
# Nitro.run do |conf|
|
320
|
-
# conf.update(
|
321
|
-
# :template_root => root,
|
322
|
-
# :port => 8080
|
323
|
-
# )
|
324
|
-
# end
|
325
|
-
|
326
|
-
def self.run(conf = nil)
|
327
|
-
runner = Runner.new.setup
|
328
|
-
runner.daemonize if runner.daemon
|
329
|
-
conf ||= Conf.new({})
|
330
|
-
$nitro_environment = conf
|
331
|
-
yield(conf) if block_given?
|
332
|
-
runner.run(conf)
|
333
|
-
end
|
334
|
-
|
335
|
-
#--
|
336
|
-
# Experimental.
|
337
|
-
#++
|
338
|
-
|
339
|
-
def self.start(controller)
|
340
|
-
# require 'glue/autoreload'
|
341
|
-
# autoreload(3)
|
342
|
-
Server.run(controller)
|
343
|
-
end
|
344
|
-
|
345
|
-
end
|
346
|
-
|
347
|
-
# * George Moschovitis <gm@navel.gr>
|
348
|
-
# * James Britt <james_b@neurogami.com>
|
data/lib/nitro/shaders.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
require 'nitro/template'
|
2
|
-
require 'nitro/element'
|
3
|
-
|
4
|
-
module Nitro
|
5
|
-
|
6
|
-
# A shader defines a transformation-pipeline that tansforms
|
7
|
-
# the .xhtml files to actual ruby code ready for evaluation
|
8
|
-
# (compilation) by the engine.
|
9
|
-
#
|
10
|
-
# Shaders employ a folded-filter design.
|
11
|
-
#--
|
12
|
-
# TODO: pipeline stage mixin to be reused in filters too.
|
13
|
-
#++
|
14
|
-
|
15
|
-
class Shader
|
16
|
-
|
17
|
-
# the next stage in the Shader pipeline.
|
18
|
-
|
19
|
-
attr :next_stage
|
20
|
-
|
21
|
-
def initialize(next_stage = nil)
|
22
|
-
@next_stage = next_stage
|
23
|
-
end
|
24
|
-
|
25
|
-
# Process the text and optionally update the hash.
|
26
|
-
# The hash is a short, unique representation of the
|
27
|
-
# input text, typically used as a caching key.
|
28
|
-
|
29
|
-
def process(hash, text)
|
30
|
-
process_next(hash, text)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Set the next stage of the pipeline.
|
34
|
-
|
35
|
-
def << (next_stage = nil)
|
36
|
-
@next_stage = next_stage
|
37
|
-
return self
|
38
|
-
end
|
39
|
-
|
40
|
-
# Process the next stage of the pipeline.
|
41
|
-
|
42
|
-
def process_next(hash, text)
|
43
|
-
if @next_stage
|
44
|
-
return @next_stage.process(hash, text)
|
45
|
-
else
|
46
|
-
return hash, text
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Convert the xhtml script to actual Ruby code, ready
|
52
|
-
# to be evaluated.
|
53
|
-
|
54
|
-
class RubyShader < Shader
|
55
|
-
include TemplateMixin
|
56
|
-
|
57
|
-
# Convert the xhtml script to actual Ruby code, ready
|
58
|
-
# to be evaluated.
|
59
|
-
#--
|
60
|
-
# Investigate:
|
61
|
-
# perhaps xl:href should be used to be XLink compatible?
|
62
|
-
#++
|
63
|
-
|
64
|
-
def process(hash, text)
|
65
|
-
text = compile_template(text)
|
66
|
-
process_next(hash, text)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Loads and statically includes a file.
|
70
|
-
|
71
|
-
def load_statically_included(filename)
|
72
|
-
Logger.debug "Statically including '#{filename}'" if $DBG
|
73
|
-
|
74
|
-
text = File.read(filename)
|
75
|
-
text.gsub!(/<\?xml.*\?>/, '')
|
76
|
-
text.gsub!(/<\/?root(.*?)>/m, ' ');
|
77
|
-
|
78
|
-
return text
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
# Apply an XSL transformation to the script code.
|
84
|
-
# There is no need to keep post xsl. I can reuse the
|
85
|
-
# same xsl by calling transform again.
|
86
|
-
|
87
|
-
class XSLTShader < Shader
|
88
|
-
|
89
|
-
# The name
|
90
|
-
|
91
|
-
attr :name
|
92
|
-
|
93
|
-
# The xslt filename.
|
94
|
-
|
95
|
-
attr :xsl_filename
|
96
|
-
|
97
|
-
# The xslt transformer.
|
98
|
-
|
99
|
-
attr :xslt
|
100
|
-
|
101
|
-
# Last modified time of the xslt.
|
102
|
-
|
103
|
-
attr :mtime
|
104
|
-
|
105
|
-
def initialize(xsl_filename, next_stage = nil)
|
106
|
-
|
107
|
-
# leave this require here. only inlcude the xslt
|
108
|
-
# library if the project needs it.
|
109
|
-
|
110
|
-
require "xml/xslt"
|
111
|
-
|
112
|
-
@name = File.basename(xsl_filename, '.*')
|
113
|
-
@xsl_filename = xsl_filename
|
114
|
-
@xslt = XML::XSLT.new
|
115
|
-
@next_stage = next_stage
|
116
|
-
end
|
117
|
-
|
118
|
-
# Transform the given text.
|
119
|
-
|
120
|
-
def process(hash, text)
|
121
|
-
parse_xsl()
|
122
|
-
@xslt.xml = text
|
123
|
-
hash += @name
|
124
|
-
Logger.debug "Applying xsl '#{@xsl_filename}' to template" if $DBG
|
125
|
-
process_next(hash, xslt.serve)
|
126
|
-
end
|
127
|
-
|
128
|
-
private
|
129
|
-
|
130
|
-
# Parse the xsl.
|
131
|
-
|
132
|
-
def parse_xsl
|
133
|
-
Logger.debug "Parsing xsl '#{@xsl_filename}'" if $DBG
|
134
|
-
@mtime = File.mtime(@xsl_filename)
|
135
|
-
@xslt.xsl = File.read(@xsl_filename)
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
# Compress the inline xhtml. Does not touch the ruby code.
|
141
|
-
|
142
|
-
class CompressShader < Shader
|
143
|
-
|
144
|
-
# Compress the inline xhtml. Does not touch the ruby code.
|
145
|
-
|
146
|
-
def process(hash, text)
|
147
|
-
text.gsub!(/\@out \<\< \%\^(.*?)\^/m) do |match|
|
148
|
-
c = $1.gsub(/^(\s*)/m, '').squeeze(" \t").tr("\n", '').tr("\t", ' ')
|
149
|
-
"@out << %{#{c}}"
|
150
|
-
end
|
151
|
-
|
152
|
-
process_next(hash, text)
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
# MorphingShader
|
158
|
-
|
159
|
-
class MorphingShader < Shader
|
160
|
-
|
161
|
-
def process(hash, text)
|
162
|
-
|
163
|
-
# <tag if="x">..</tag>
|
164
|
-
# <tag unless="x">..</tag>
|
165
|
-
|
166
|
-
text.gsub!(/<(\w*?)([^>]*?)(if|unless)=["|'](.*?)["|'](.*?)>(.*?)<\/\1>/m) do |match|
|
167
|
-
%{<?r #$3 #$4 ?>
|
168
|
-
<#$1#$2#$5>#$6</#$1>
|
169
|
-
<?r end ?>}
|
170
|
-
end
|
171
|
-
|
172
|
-
# <tag times="x">..</tag>
|
173
|
-
|
174
|
-
text.gsub!(/<(\w*?)([^>]*?)times=["|'](.*?)["|'](.*?)>(.*?)<\/\1>/m) do |match|
|
175
|
-
%{<?r #$3.times do ?>
|
176
|
-
<#$1#$2#$4>#$5</#$1>
|
177
|
-
<?r end ?>}
|
178
|
-
end
|
179
|
-
|
180
|
-
# <tag each="x">..</tag>
|
181
|
-
|
182
|
-
text.gsub!(/<(\w*?)([^>]*?)each=["|'](.*?)["|'](.*?)>(.*?)<\/\1>/m) do |match|
|
183
|
-
%{<?r for #$3 ?>
|
184
|
-
<#$1#$2#$4>#$5</#$1>
|
185
|
-
<?r end ?>}
|
186
|
-
end
|
187
|
-
|
188
|
-
process_next(hash, text)
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
# ElementsShader
|
194
|
-
|
195
|
-
class ElementsShader < Shader
|
196
|
-
|
197
|
-
def process(hash, text)
|
198
|
-
text = ElementProcessor.render(text)
|
199
|
-
process_next(hash, text)
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
# * George Moschovitis <gm@navel.gr>
|