ramaze 0.1.1 → 0.1.2
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/Rakefile +14 -29
- data/bin/ramaze +2 -3
- data/doc/AUTHORS +5 -2
- data/doc/CHANGELOG +262 -9
- data/doc/FAQ +6 -6
- data/doc/meta/announcement.txt +5 -19
- data/doc/tutorial/todolist.html +47 -57
- data/doc/tutorial/todolist.mkd +47 -55
- data/examples/memleak_detector.rb +31 -0
- data/examples/todolist/src/controller/main.rb +14 -13
- data/examples/todolist/src/element/page.rb +2 -2
- data/examples/todolist/src/model.rb +2 -2
- data/examples/todolist/todolist.db +0 -4
- data/examples/whywiki/main.rb +2 -2
- data/examples/whywiki/template/edit.xhtml +1 -1
- data/examples/whywiki/template/show.xhtml +3 -3
- data/lib/proto/src/controller/main.rb +18 -1
- data/lib/proto/template/index.xhtml +11 -2
- data/lib/ramaze.rb +1 -1
- data/lib/ramaze/action.rb +104 -5
- data/lib/ramaze/action/render.rb +54 -0
- data/lib/ramaze/adapter.rb +2 -1
- data/lib/ramaze/adapter/mongrel.rb +13 -4
- data/lib/ramaze/cache.rb +17 -8
- data/lib/ramaze/cache/memcached.rb +1 -5
- data/lib/ramaze/controller.rb +51 -18
- data/lib/ramaze/controller/resolve.rb +19 -14
- data/lib/ramaze/dispatcher.rb +13 -16
- data/lib/ramaze/dispatcher/action.rb +2 -3
- data/lib/ramaze/dispatcher/error.rb +8 -3
- data/lib/ramaze/dispatcher/file.rb +1 -4
- data/lib/ramaze/error.rb +5 -5
- data/lib/ramaze/global.rb +7 -1
- data/lib/ramaze/global/globalstruct.rb +1 -3
- data/lib/ramaze/helper/aspect.rb +8 -10
- data/lib/ramaze/helper/cgi.rb +21 -3
- data/lib/ramaze/helper/identity.rb +4 -6
- data/lib/ramaze/helper/link.rb +4 -4
- data/lib/ramaze/helper/pager.rb +316 -0
- data/lib/ramaze/helper/partial.rb +37 -0
- data/lib/ramaze/helper/stack.rb +1 -1
- data/lib/ramaze/inform.rb +9 -0
- data/lib/ramaze/inform/hub.rb +5 -0
- data/lib/ramaze/inform/informer.rb +12 -6
- data/lib/ramaze/inform/informing.rb +32 -7
- data/lib/ramaze/inform/knotify.rb +21 -0
- data/lib/ramaze/inform/xosd.rb +58 -24
- data/lib/ramaze/sourcereload.rb +30 -1
- data/lib/ramaze/template.rb +33 -12
- data/lib/ramaze/template/amrita2.rb +21 -20
- data/lib/ramaze/template/erubis.rb +18 -14
- data/lib/ramaze/template/ezamar.rb +15 -26
- data/lib/ramaze/template/ezamar/element.rb +1 -1
- data/lib/ramaze/template/ezamar/engine.rb +45 -36
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/ezamar/render_partial.rb +26 -0
- data/lib/ramaze/template/haml.rb +23 -18
- data/lib/ramaze/template/liquid.rb +5 -3
- data/lib/ramaze/template/markaby.rb +14 -11
- data/lib/ramaze/template/remarkably.rb +11 -5
- data/lib/ramaze/tool/localize.rb +12 -4
- data/lib/ramaze/tool/tidy.rb +26 -23
- data/lib/ramaze/trinity/request.rb +11 -7
- data/lib/ramaze/trinity/session.rb +24 -8
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/maintaince.rake +136 -11
- data/spec/examples/templates/template_liquid.rb +6 -3
- data/spec/examples/todolist.rb +1 -2
- data/spec/helper/minimal.rb +7 -7
- data/spec/ramaze/action/basics.rb +19 -0
- data/spec/ramaze/action/render.rb +18 -0
- data/spec/ramaze/controller.rb +1 -1
- data/spec/ramaze/controller/template_resolving.rb +1 -1
- data/spec/ramaze/dispatcher/file.rb +24 -0
- data/spec/ramaze/error.rb +28 -29
- data/spec/ramaze/helper/cgi.rb +43 -0
- data/spec/ramaze/helper/pager.rb +27 -0
- data/spec/ramaze/helper/partial.rb +38 -0
- data/spec/ramaze/helper/template/partial.xhtml +1 -0
- data/spec/ramaze/inform/informer.rb +1 -1
- data/spec/ramaze/localize.rb +1 -1
- data/spec/ramaze/morpher.rb +3 -3
- data/spec/ramaze/request.rb +1 -3
- data/spec/ramaze/template.rb +9 -7
- data/spec/ramaze/template/haml.rb +2 -1
- metadata +21 -7
- data/examples/todolist/public/404.jpg +0 -0
- data/examples/todolist/public/error.xhtml +0 -74
- data/lib/ramaze/controller/render.rb +0 -90
data/lib/ramaze/tool/tidy.rb
CHANGED
@@ -29,29 +29,30 @@ module Ramaze
|
|
29
29
|
:wrap => 500
|
30
30
|
}
|
31
31
|
|
32
|
-
# dirty html in, tidy html out
|
33
|
-
# To activate Tidy for everything outgoing (given that it is of
|
34
|
-
# Content-Type text/html) set
|
35
|
-
# Global.tidy = true
|
36
|
-
# there is almost no speed-tradeoff but makes debugging a much
|
37
|
-
# nicer experience ;)
|
38
|
-
#
|
39
|
-
# Example:
|
40
|
-
#
|
41
|
-
# include Ramaze::Tool::Tidy
|
42
|
-
# puts tidy('<html></html>')
|
43
|
-
#
|
44
|
-
# # results in something like:
|
45
|
-
#
|
46
|
-
# <html>
|
47
|
-
# <head>
|
48
|
-
# <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" />
|
49
|
-
# <title></title>
|
50
|
-
# </head>
|
51
|
-
# <body></body>
|
52
|
-
# </html>
|
53
|
-
|
54
32
|
class << self
|
33
|
+
|
34
|
+
# dirty html in, tidy html out
|
35
|
+
# To activate Tidy for everything outgoing (given that it is of
|
36
|
+
# Content-Type text/html) set
|
37
|
+
# Global.tidy = true
|
38
|
+
# there is almost no speed-tradeoff but makes debugging a much
|
39
|
+
# nicer experience ;)
|
40
|
+
#
|
41
|
+
# Example:
|
42
|
+
#
|
43
|
+
# include Ramaze::Tool::Tidy
|
44
|
+
# puts tidy('<html></html>')
|
45
|
+
#
|
46
|
+
# # results in something like:
|
47
|
+
#
|
48
|
+
# <html>
|
49
|
+
# <head>
|
50
|
+
# <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" />
|
51
|
+
# <title></title>
|
52
|
+
# </head>
|
53
|
+
# <body></body>
|
54
|
+
# </html>
|
55
|
+
|
55
56
|
def tidy html, options = {}
|
56
57
|
require 'tidy'
|
57
58
|
|
@@ -84,6 +85,8 @@ module Ramaze
|
|
84
85
|
puts "you can find it at http://tidy.rubyforge.org/"
|
85
86
|
end
|
86
87
|
|
88
|
+
# Enables being plugged into Dispatcher::Action::FILTER
|
89
|
+
|
87
90
|
def call(response, options = {})
|
88
91
|
return response unless trait[:enable]
|
89
92
|
response.body = tidy(response.body, options)
|
@@ -91,7 +94,7 @@ module Ramaze
|
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
94
|
-
# calls
|
97
|
+
# calls Tidy::tidy
|
95
98
|
|
96
99
|
def tidy html, options = {}
|
97
100
|
Ramaze::Tool::Tidy.tidy(html, options)
|
@@ -40,6 +40,9 @@ module Ramaze
|
|
40
40
|
# Wrapping Request#params to support a one-level hash notation.
|
41
41
|
# It doesn't support anything really fancy, so be conservative in its use.
|
42
42
|
#
|
43
|
+
# See if following provides something useful for us:
|
44
|
+
# http://redhanded.hobix.com/2006/01/25.html
|
45
|
+
#
|
43
46
|
# Example Usage:
|
44
47
|
#
|
45
48
|
# # Template:
|
@@ -66,20 +69,21 @@ module Ramaze
|
|
66
69
|
# end
|
67
70
|
|
68
71
|
def params
|
69
|
-
|
70
|
-
|
72
|
+
return @ramaze_params if @ramaze_params
|
73
|
+
@rack_params ||= rack_params
|
74
|
+
@ramaze_params = {}
|
71
75
|
|
72
|
-
|
76
|
+
@rack_params.each do |key, value|
|
73
77
|
outer_key, inner_key = key.scan(/^(.+)\[(.*?)\]$/).first
|
74
78
|
if outer_key and inner_key
|
75
|
-
|
76
|
-
|
79
|
+
@ramaze_params[outer_key] ||= {}
|
80
|
+
@ramaze_params[outer_key][inner_key] = value
|
77
81
|
else
|
78
|
-
|
82
|
+
@ramaze_params[key] = value
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
82
|
-
|
86
|
+
@ramaze_params
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
@@ -27,6 +27,8 @@ module Ramaze
|
|
27
27
|
result
|
28
28
|
end
|
29
29
|
|
30
|
+
# Calls #inspect on the wrapped @hash
|
31
|
+
|
30
32
|
def inspect
|
31
33
|
@hash.inspect
|
32
34
|
end
|
@@ -53,9 +55,13 @@ module Ramaze
|
|
53
55
|
|
54
56
|
SESSION_KEY = '_ramaze_session_id'
|
55
57
|
|
56
|
-
|
58
|
+
# Holds counter for IPs
|
59
|
+
|
60
|
+
IP_COUNT = Hash.new{|h,k| h[k] = []}
|
61
|
+
|
62
|
+
# Limit the number of sessions one IP is allowed to hold.
|
57
63
|
|
58
|
-
|
64
|
+
IP_COUNT_LIMIT = 1000
|
59
65
|
|
60
66
|
class << self
|
61
67
|
|
@@ -81,12 +87,12 @@ module Ramaze
|
|
81
87
|
|
82
88
|
def initialize request
|
83
89
|
@session_id = (request.cookies[SESSION_KEY] || random_key)
|
84
|
-
|
90
|
+
|
85
91
|
ip = request.remote_addr
|
86
|
-
|
92
|
+
IP_COUNT[ip] << @session_id
|
87
93
|
|
88
|
-
if
|
89
|
-
sessions.delete(
|
94
|
+
if IP_COUNT[ip].size > IP_COUNT_LIMIT
|
95
|
+
sessions.delete(IP_COUNT[ip].shift)
|
90
96
|
end
|
91
97
|
|
92
98
|
@flash = Ramaze::SessionFlash.new
|
@@ -129,6 +135,8 @@ module Ramaze
|
|
129
135
|
Digest::SHA256.hexdigest(h)
|
130
136
|
end
|
131
137
|
|
138
|
+
# Inspect on Session.current
|
139
|
+
|
132
140
|
def inspect
|
133
141
|
current.inspect
|
134
142
|
end
|
@@ -140,7 +148,7 @@ module Ramaze
|
|
140
148
|
# and always just keep the current and previous key/value pairs.
|
141
149
|
|
142
150
|
def finalize
|
143
|
-
old = delete(:FLASH)
|
151
|
+
old = current.delete(:FLASH)
|
144
152
|
current[:FLASH_PREVIOUS] = old if old
|
145
153
|
end
|
146
154
|
end
|
@@ -176,24 +184,32 @@ module Ramaze
|
|
176
184
|
previous.merge(current)
|
177
185
|
end
|
178
186
|
|
187
|
+
# flash[key] in your Controller
|
188
|
+
|
179
189
|
def [](key)
|
180
190
|
combined[key]
|
181
191
|
end
|
182
192
|
|
193
|
+
# flash[key] = value in your Controller
|
194
|
+
|
183
195
|
def []=(key, value)
|
184
196
|
prev = session[:FLASH] || {}
|
185
197
|
prev[key] = value
|
186
198
|
session[:FLASH] = prev
|
187
199
|
end
|
188
200
|
|
201
|
+
# Inspects the combined SessionFlash
|
202
|
+
|
189
203
|
def inspect
|
190
204
|
combined.inspect
|
191
205
|
end
|
192
206
|
|
193
207
|
private
|
194
208
|
|
209
|
+
# Session.current or {}
|
210
|
+
|
195
211
|
def session
|
196
|
-
|
212
|
+
Session.current || {}
|
197
213
|
end
|
198
214
|
end
|
199
215
|
end
|
data/lib/ramaze/version.rb
CHANGED
data/rake_tasks/maintaince.rake
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
desc "add copyright to all .rb files in the distribution"
|
2
2
|
task 'add-copyright' do
|
3
3
|
puts "adding copyright to files that don't have it currently"
|
4
|
+
puts COPYRIGHT
|
5
|
+
puts
|
4
6
|
Dir['{lib,test}/**/*{.rb}'].each do |file|
|
5
7
|
next if file =~ /_darcs/
|
6
8
|
lines = File.readlines(file).map{|l| l.chomp}
|
7
9
|
unless lines.first(COPYRIGHT.size) == COPYRIGHT
|
8
|
-
puts "
|
9
|
-
|
10
|
-
|
11
|
-
f.puts(line)
|
12
|
-
end
|
13
|
-
end
|
10
|
+
puts "#{file} seems to need attention, first 4 lines:"
|
11
|
+
puts lines[0..3]
|
12
|
+
puts
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -202,9 +201,12 @@ task 'authors' do
|
|
202
201
|
authors = []
|
203
202
|
mapping = {}
|
204
203
|
author_map = {
|
205
|
-
'm.fellinger@gmail.com'
|
206
|
-
'manveru@weez-int.com'
|
207
|
-
'clive@crous.co.za'
|
204
|
+
'm.fellinger@gmail.com' => 'Michael Fellinger',
|
205
|
+
'manveru@weez-int.com' => 'Michael Fellinger',
|
206
|
+
'clive@crous.co.za' => 'Clive Crous',
|
207
|
+
'blueonyx@dev-area.net' => 'Martin Hilbig',
|
208
|
+
'rff.rff@gmail.com' => 'Gabriele Renzi',
|
209
|
+
'comp.lang.zenix+ramaze@gmail.com' => 'zenix',
|
208
210
|
}
|
209
211
|
changes.split("\n").grep(/^\w/).each do |line|
|
210
212
|
splat = line.split
|
@@ -215,14 +217,137 @@ task 'authors' do
|
|
215
217
|
name = author_map[email] if name.empty?
|
216
218
|
mapping[name] = email
|
217
219
|
end
|
220
|
+
pp mapping
|
218
221
|
|
219
222
|
max = mapping.map{|k,v| k.size}.max
|
220
223
|
|
221
224
|
File.open('doc/AUTHORS', 'w+') do |fp|
|
222
|
-
fp.puts("Following persons have contributed to Ramaze:")
|
225
|
+
fp.puts("Following persons (in alphabetical order) have contributed to Ramaze:")
|
223
226
|
fp.puts
|
224
|
-
mapping.sort_by{|k,v|
|
227
|
+
mapping.sort_by{|k,v| k}.each do |name, email|
|
225
228
|
fp.puts("#{name.ljust(max)} - #{email}")
|
226
229
|
end
|
227
230
|
end
|
228
231
|
end
|
232
|
+
|
233
|
+
task 'release' => ['distribute'] do
|
234
|
+
sh 'rubyforge login'
|
235
|
+
sh 'rubyforge add_release ramaze ramaze #{VERS} pkg/ramaze-#{VERS}.gem'
|
236
|
+
|
237
|
+
require 'open-uri'
|
238
|
+
require 'hpricot'
|
239
|
+
|
240
|
+
url = "http://rubyforge.org/frs/?group_id=3034"
|
241
|
+
doc = Hpricot(open(url))
|
242
|
+
a = (doc/:a).find{|a| a[:href] =~ /release_id/}
|
243
|
+
|
244
|
+
version = a.inner_html
|
245
|
+
release_id = Hash[*a[:href].split('?').last.split('=').flatten]['release_id']
|
246
|
+
|
247
|
+
sh "rubyforge add_file ramaze ramaze #{release_id} pkg/ramaze-#{VERS}.tar.gz"
|
248
|
+
sh "rubyforge add_file ramaze ramaze #{release_id} pkg/ramaze-#{VERS}.tar.bz2"
|
249
|
+
end
|
250
|
+
|
251
|
+
desc "list all undocumented methods"
|
252
|
+
task 'undocumented-module' do
|
253
|
+
require 'strscan'
|
254
|
+
require 'term/ansicolor'
|
255
|
+
|
256
|
+
class String
|
257
|
+
include Term::ANSIColor
|
258
|
+
end
|
259
|
+
|
260
|
+
class SimpleDoc
|
261
|
+
def initialize(string)
|
262
|
+
@s = StringScanner.new(string)
|
263
|
+
end
|
264
|
+
|
265
|
+
def scan
|
266
|
+
comment = false
|
267
|
+
total, missing = [], []
|
268
|
+
until @s.eos?
|
269
|
+
unless @s.scan(/^\s*#.*/)
|
270
|
+
comment = true if @s.scan(/^=begin$/)
|
271
|
+
comment = false if comment and @s.scan(/^=end$/)
|
272
|
+
|
273
|
+
unless comment
|
274
|
+
if @s.scan(/(?:class ).*/)
|
275
|
+
#p @s.matched
|
276
|
+
elsif @s.scan(/(?:module ).*/)
|
277
|
+
#p @s.matched
|
278
|
+
elsif @s.scan(/(?:def )[\w?!*+\/-]+(?=[\(\s])/)
|
279
|
+
total << @s.matched.split.last
|
280
|
+
prev = @s.pre_match.split("\n")
|
281
|
+
prev.delete_if{|s| s.strip.empty?}
|
282
|
+
unless prev.last =~ /^\s*#.*/
|
283
|
+
missing << @s.matched.split.last
|
284
|
+
end
|
285
|
+
else
|
286
|
+
@s.scan(/./m)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
return total, missing
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
all = {}
|
297
|
+
files = Dir['lib/**/*.rb']
|
298
|
+
|
299
|
+
files.each do |file|
|
300
|
+
t, m = SimpleDoc.new(File.read(file)).scan
|
301
|
+
all[file] = [t, m]
|
302
|
+
end
|
303
|
+
|
304
|
+
failed = all.reject{|k,(t,m)| m.size == 0}
|
305
|
+
|
306
|
+
max = failed.keys.sort_by{|f| f.size}.last.size
|
307
|
+
|
308
|
+
colors = {
|
309
|
+
(0..25 ) => :blue,
|
310
|
+
(25..50 ) => :green,
|
311
|
+
(50..75 ) => :yellow,
|
312
|
+
(75..100) => :red,
|
313
|
+
}
|
314
|
+
|
315
|
+
puts "\nAll undocumented methods\n\n"
|
316
|
+
|
317
|
+
failed.sort.each do |file, (t, m)|
|
318
|
+
ts, ms = t.size, m.size
|
319
|
+
tss, mss = ts.to_s, ms.to_s
|
320
|
+
ratio = ((ms.to_f/ts)*100).to_i
|
321
|
+
color = colors.find{|k,v| k.include?(ratio)}.last
|
322
|
+
complete = ms.to_f/ts.to_f
|
323
|
+
mthc = "method"
|
324
|
+
if ratio != 100
|
325
|
+
puts "#{file.ljust(max)}\t[#{[mss, tss].join('/').center(8)}]".send(color)
|
326
|
+
mthc = "methods" if ts > 1
|
327
|
+
if $VERBOSE
|
328
|
+
puts "Of #{tss} #{mthc}, #{mss} still needs documenting (#{100 - ratio}% documented, #{ratio}% undocumented)".send(color)
|
329
|
+
mthc = "method"
|
330
|
+
mthc = "methods" if ms > 1
|
331
|
+
print "#{mthc.capitalize}: "
|
332
|
+
end
|
333
|
+
puts m.join(', ')
|
334
|
+
puts
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
puts "The colors mean percentages of documentation left (ratio of undocumented methods to total):"
|
339
|
+
colors.sort_by{|k,v| k.begin}.each do |r, color|
|
340
|
+
print "[#{r.inspect}] ".send(color)
|
341
|
+
end
|
342
|
+
puts
|
343
|
+
end
|
344
|
+
|
345
|
+
task 'undocumented' do
|
346
|
+
$VERBOSE = false
|
347
|
+
Rake::Task['undocumented-module'].execute
|
348
|
+
end
|
349
|
+
|
350
|
+
task 'undocumented-verbose' do
|
351
|
+
$VERBOSE = true
|
352
|
+
Rake::Task['undocumented-module'].execute
|
353
|
+
end
|
@@ -13,10 +13,13 @@ describe 'Template Liquid' do
|
|
13
13
|
|
14
14
|
%w[/internal /external].each do |url|
|
15
15
|
it url do
|
16
|
-
|
16
|
+
name = url.gsub(/^\//, '')
|
17
|
+
response = get(url)
|
18
|
+
response.status.should == 200
|
19
|
+
html = response.body
|
17
20
|
html.should_not == nil
|
18
|
-
html.should =~ %r
|
19
|
-
html.should =~ %r
|
21
|
+
html.should =~ %r(<title>Template::Liquid #{name}</title>)
|
22
|
+
html.should =~ %r(<h1>The #{name} Template for Liquid</h1>)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
data/spec/examples/todolist.rb
CHANGED
@@ -8,7 +8,6 @@ require 'main'
|
|
8
8
|
# fix the paths to template and public for the spec
|
9
9
|
class MainController
|
10
10
|
template_root 'examples/todolist/template'
|
11
|
-
public_root 'examples/todolist/public'
|
12
11
|
end
|
13
12
|
|
14
13
|
describe 'todolist' do
|
@@ -47,7 +46,7 @@ describe 'todolist' do
|
|
47
46
|
end
|
48
47
|
|
49
48
|
it 'should start' do
|
50
|
-
ramaze :port => 7080
|
49
|
+
ramaze :public_root => 'examples/todolist/public', :port => 7080
|
51
50
|
get('/').status.should == 200
|
52
51
|
end
|
53
52
|
|
data/spec/helper/minimal.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'timeout'
|
2
2
|
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError => ex
|
6
|
+
end
|
7
|
+
|
3
8
|
base = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
4
9
|
$:.unshift base.gsub(/^#{Dir.pwd}/, '.')
|
5
10
|
|
@@ -8,13 +13,8 @@ $context_runner = false
|
|
8
13
|
|
9
14
|
require 'ramaze'
|
10
15
|
|
11
|
-
begin
|
12
|
-
require 'rubygems'
|
13
|
-
rescue LoadError => ex
|
14
|
-
end
|
15
|
-
|
16
16
|
require 'spec'
|
17
|
-
if Spec::VERSION::FULL_VERSION < "0.
|
18
|
-
puts "please update rspec >= 0.
|
17
|
+
if Spec::VERSION::FULL_VERSION < "1.0.3 (r2035)"
|
18
|
+
puts "please update rspec >= 1.0.3"
|
19
19
|
exit 1
|
20
20
|
end
|