Pistos-ramaze 2008.12 → 2009.01
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/examples/app/blog/model/entry.rb +8 -1
- data/examples/app/wikore/src/model.rb +7 -1
- data/lib/proto/public/.htaccess +24 -0
- data/lib/ramaze/contrib/gettext/po.rb +23 -23
- data/lib/ramaze/controller/resolve.rb +2 -2
- data/lib/ramaze/current/request.rb +13 -4
- data/lib/ramaze/helper/bench.rb +43 -0
- data/lib/ramaze/helper/markaby.rb +1 -1
- data/lib/ramaze/helper/paginate.rb +1 -1
- data/lib/ramaze/helper/redirect.rb +1 -1
- data/lib/ramaze/log/syslog.rb +36 -36
- data/lib/ramaze/version.rb +1 -1
- data/ramaze.gemspec +3 -167
- data/spec/ramaze/log/syslog.rb +62 -59
- metadata +4 -168
@@ -23,7 +23,14 @@ class Entry < Sequel::Model(:entry)
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
begin
|
27
|
+
Entry.create_table!
|
28
|
+
rescue Sequel::DatabaseError => e
|
29
|
+
if e.message !~ /table.*already exists/
|
30
|
+
raise e
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
27
34
|
|
28
35
|
if Entry.empty?
|
29
36
|
Entry.add 'Blog created', 'Exciting news today, this blog was created'
|
@@ -48,6 +48,12 @@ module Model
|
|
48
48
|
end
|
49
49
|
|
50
50
|
[Page, OldPage].each do |klass|
|
51
|
-
|
51
|
+
begin
|
52
|
+
klass.create_table
|
53
|
+
rescue Sequel::DatabaseError => e
|
54
|
+
if e.message !~ /table.*already exists/
|
55
|
+
raise e
|
56
|
+
end
|
57
|
+
end
|
52
58
|
end
|
53
59
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# General Apache options
|
2
|
+
Options +FollowSymLinks +ExecCGI
|
3
|
+
AddHandler cgi-script cgi rb
|
4
|
+
<IfModule mod_fastcgi.c>
|
5
|
+
AddHandler fastcgi-script fcgi
|
6
|
+
</IfModule>
|
7
|
+
<IfModule mod_fcgid.c>
|
8
|
+
AddHandler fcgid-script fcgi
|
9
|
+
</IfModule>
|
10
|
+
|
11
|
+
# Redirect all requests not available on the filesystem to Ramaze.
|
12
|
+
|
13
|
+
RewriteEngine On
|
14
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
15
|
+
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
16
|
+
|
17
|
+
# In case Ramaze experiences terminal errors.
|
18
|
+
# Instead of displaying this message you can supply a
|
19
|
+
# file here which will be rendered instead.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
# ErrorDocument 500 /500.html
|
23
|
+
|
24
|
+
ErrorDocument 500 "<h2>Application error</h2>Ramaze failed to start properly"
|
@@ -52,22 +52,22 @@ EOS
|
|
52
52
|
str = ""
|
53
53
|
result = Array.new
|
54
54
|
ary.each do |key|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
55
|
+
msgid = key.shift.dup
|
56
|
+
curr_pos = MAX_LINE_LEN
|
57
|
+
key.each do |e|
|
58
|
+
if curr_pos + e.size > MAX_LINE_LEN
|
59
|
+
str << "\n#:"
|
60
|
+
curr_pos = 3
|
61
|
+
else
|
62
|
+
curr_pos += (e.size + 1)
|
63
|
+
end
|
64
|
+
str << " " << e
|
65
|
+
end
|
66
|
+
msgid.gsub!(/"/, '\"')
|
67
|
+
msgid.gsub!(/\r/, '')
|
68
|
+
|
69
|
+
str << "\nmsgid \"" << msgid << "\"\n"
|
70
|
+
str << "msgstr \"\"\n"
|
71
71
|
end
|
72
72
|
str
|
73
73
|
end
|
@@ -81,15 +81,15 @@ EOS
|
|
81
81
|
msgstr = hash[msgid]
|
82
82
|
|
83
83
|
msgid.gsub!(/"/, '\"')
|
84
|
-
|
84
|
+
msgid.gsub!(/\r/, '')
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
if msgstr
|
87
|
+
msgstr.gsub!(/"/, '\"')
|
88
|
+
msgstr.gsub!(/\r/, '')
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
str << "\nmsgid \"" << msgid << "\"\n"
|
92
|
+
str << "msgstr \"" << msgstr << "\"\n"
|
93
93
|
end
|
94
94
|
|
95
95
|
str
|
@@ -16,7 +16,7 @@ module Ramaze
|
|
16
16
|
# instead, in either case with path as argument.
|
17
17
|
|
18
18
|
def resolve(path, routed = false)
|
19
|
-
|
19
|
+
Thread.current[:routed] = routed
|
20
20
|
|
21
21
|
FILTER.each do |filter|
|
22
22
|
answer = if filter.respond_to?(:call)
|
@@ -90,7 +90,7 @@ module Ramaze
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
if
|
93
|
+
if !Thread.current[:routed] and new_path = Route.resolve(path)
|
94
94
|
Log.dev("Routing from `#{path}' to `#{new_path}'")
|
95
95
|
return resolve(new_path, true)
|
96
96
|
end
|
@@ -196,9 +196,9 @@ module Ramaze
|
|
196
196
|
# Example:
|
197
197
|
# request.params
|
198
198
|
# # => {'name' => 'jason', 'age' => '45', 'job' => 'lumberjack'}
|
199
|
-
# request.
|
199
|
+
# request.subset('name')
|
200
200
|
# # => {'name' => 'jason'}
|
201
|
-
# request.
|
201
|
+
# request.subset(:name, :job)
|
202
202
|
# # => {'name' => 'jason', 'job' => 'lumberjack'}
|
203
203
|
|
204
204
|
def subset(*keys)
|
@@ -206,10 +206,19 @@ module Ramaze
|
|
206
206
|
params.reject{|k,v| not keys.include?(k) }
|
207
207
|
end
|
208
208
|
|
209
|
+
# Is this an SSL request?
|
210
|
+
def ssl?
|
211
|
+
env['HTTPS'] == 'on' || env['HTTP_X_FORWARDED_PROTO'] == 'https'
|
212
|
+
end
|
213
|
+
|
214
|
+
# Returns 'https' if this is an SSL request and 'http' otherwise.
|
215
|
+
def protocol
|
216
|
+
ssl? ? 'https' : 'http'
|
217
|
+
end
|
218
|
+
|
209
219
|
def domain(path = '/')
|
210
|
-
scheme = env['rack.url_scheme'] || 'http'
|
211
220
|
host = env['HTTP_HOST']
|
212
|
-
URI("#{
|
221
|
+
URI("#{protocol}://#{host}#{path}")
|
213
222
|
end
|
214
223
|
|
215
224
|
# Returns and array of locales from env['HTTP_ACCEPT_LANGUAGE].
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
module Ramaze
|
4
|
+
module Helper
|
5
|
+
|
6
|
+
# Little helper to give you a hand when benching parts of actions
|
7
|
+
|
8
|
+
module Bench
|
9
|
+
|
10
|
+
# Will first run an empty loop to determine the overhead it imposes, then
|
11
|
+
# goes on to yield your block +iterations+ times.
|
12
|
+
#
|
13
|
+
# The last yielded return value will be returned upon completion of the
|
14
|
+
# benchmark and the result of the benchmark itself will be sent to
|
15
|
+
# Log.info
|
16
|
+
#
|
17
|
+
# Example:
|
18
|
+
#
|
19
|
+
# class MainController < Ramaze::Controller
|
20
|
+
# def index
|
21
|
+
# @users = bench{ User.all }
|
22
|
+
# @tags = bench{ Article.tags }
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# This will show something like following in your log:
|
27
|
+
# [..] INFO Bench ./start.rb:3:in `index': 0.121163845062256
|
28
|
+
# [..] INFO Bench ./start.rb:4:in `index': 2.234987235098341
|
29
|
+
#
|
30
|
+
# So now we know that the Article.tags call takes the most time and
|
31
|
+
# should be improved.
|
32
|
+
|
33
|
+
def bench(iterations = 1)
|
34
|
+
result = nil
|
35
|
+
from = caller[0]
|
36
|
+
delta = Benchmark.realtime{ iterations.times{ nil }}
|
37
|
+
taken = Benchmark.realtime{ iterations.times{ result = yield }}
|
38
|
+
Log.info "Bench #{from}: #{taken - delta}"
|
39
|
+
return result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -15,7 +15,7 @@ module Ramaze
|
|
15
15
|
def markaby(ivs = {}, helpers = nil, &block)
|
16
16
|
builder = ::Markaby::Builder
|
17
17
|
builder.extend(Ramaze::Helper::Methods)
|
18
|
-
builder.send(:helper, :link)
|
18
|
+
builder.send(:helper, :redirect, :link, :sendfile, :flash, :cgi, :partial)
|
19
19
|
|
20
20
|
iv_hash = {}
|
21
21
|
instance_variables.each do |iv|
|
@@ -165,7 +165,7 @@ module Ramaze
|
|
165
165
|
text = h(text.to_s)
|
166
166
|
|
167
167
|
params = Ramaze::Request.current.params.merge(@var.to_s => n)
|
168
|
-
name = Ramaze::Request.current.
|
168
|
+
name = Ramaze::Request.current.path_info
|
169
169
|
hash[:href] = R(name, params)
|
170
170
|
|
171
171
|
g.a(hash){ text }
|
data/lib/ramaze/log/syslog.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
|
2
2
|
# Copyright (c) 2008 rob@rebeltechnologies.nl
|
3
3
|
# All files in this distribution are subject to the terms of the Ruby license.
|
4
4
|
|
@@ -6,46 +6,46 @@ require 'syslog'
|
|
6
6
|
|
7
7
|
# Add aliases for the levelnames used by Ramaze logging
|
8
8
|
module Syslog
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
alias dev debug
|
10
|
+
alias warn warning
|
11
|
+
alias error err
|
12
|
+
module_function :dev, :warn, :error
|
13
13
|
end
|
14
14
|
|
15
15
|
module Ramaze
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
module Logger
|
17
|
+
# Logger class for writing to syslog. It is a *very* thin wrapper
|
18
|
+
# around the Syslog library.
|
19
|
+
class Syslog
|
20
|
+
include Logging
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
# Open the syslog library, if it is allready open, we reopen it using the
|
23
|
+
# new argument list. The argument list is passed on to the Syslog library
|
24
|
+
# so please check that, and man syslog for detailed information.
|
25
|
+
# There are 3 parameters:
|
26
|
+
#
|
27
|
+
# ident: The identification used in the log file, defaults to $0
|
28
|
+
# options: defaults to Syslog::LOG_PID | Syslog::LOG_CONS
|
29
|
+
# facility: defaults to Syslog::LOG_USER
|
30
|
+
#
|
31
|
+
def initialize( *args )
|
32
|
+
::Syslog.close if ::Syslog.opened?
|
33
|
+
::Syslog.open( *args )
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
# just sends all messages received to ::Syslog
|
37
|
+
# We simply return if the log was closed for some reason, this behavior
|
38
|
+
# was copied from Informer. We do not handle levels here. This will
|
39
|
+
# be done by te syslog daemon based on it's configuration.
|
40
|
+
def log(tag, *messages)
|
41
|
+
return if !::Syslog.opened?
|
42
|
+
::Syslog.send(tag, *messages)
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
45
|
+
# Has to call the modules singleton-method.
|
46
|
+
def inspect
|
47
|
+
::Syslog.inspect
|
48
|
+
end
|
50
49
|
end
|
50
|
+
end
|
51
51
|
end
|
data/lib/ramaze/version.rb
CHANGED