ramaze 0.3.5 → 0.3.9
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 +5 -20
- data/bin/ramaze +0 -4
- data/doc/AUTHORS +5 -0
- data/doc/meta/announcement.txt +2 -1
- data/doc/tutorial/todolist.html +20 -21
- data/doc/tutorial/todolist.mkd +10 -9
- data/examples/blog/{src/controller.rb → controller/main.rb} +2 -0
- data/examples/blog/{src/model.rb → model/entry.rb} +0 -0
- data/examples/blog/spec/blog.rb +3 -3
- data/examples/blog/start.rb +2 -3
- data/examples/blog/view/edit.xhtml +17 -0
- data/examples/blog/view/index.xhtml +17 -0
- data/examples/blog/view/layout.xhtml +11 -0
- data/examples/blog/view/new.xhtml +16 -0
- data/examples/facebook.rb +15 -8
- data/examples/identity.rb +1 -1
- data/examples/memleak_detector.rb +1 -1
- data/examples/rammit/src/model.rb +1 -1
- data/examples/rapaste/controller/paste.rb +7 -7
- data/examples/rapaste/model/paste.rb +1 -3
- data/examples/rapaste/public/css/display.css +2 -1
- data/examples/rapaste/start.rb +2 -3
- data/examples/sourceview/sourceview.rb +1 -1
- data/examples/templates/template/external.tenjin +28 -0
- data/examples/templates/template_amrita2.rb +0 -3
- data/examples/templates/template_tenjin.rb +57 -0
- data/examples/todolist/spec/todolist.rb +13 -2
- data/examples/todolist/src/controller/main.rb +1 -1
- data/examples/todolist/template/index.xhtml +1 -1
- data/examples/wiktacular/spec/wiktacular.rb +18 -0
- data/examples/wiktacular/src/controller.rb +2 -2
- data/examples/wiktacular/src/model.rb +8 -2
- data/lib/proto/public/css/ramaze_error.css +4 -0
- data/lib/proto/public/dispatch.fcgi +11 -0
- data/lib/proto/spec/main.rb +1 -1
- data/lib/proto/start.ru +8 -0
- data/lib/proto/view/error.xhtml +2 -0
- data/lib/ramaze.rb +28 -5
- data/lib/ramaze/action.rb +9 -2
- data/lib/ramaze/action/render.rb +40 -24
- data/lib/ramaze/adapter.rb +10 -17
- data/lib/ramaze/adapter/base.rb +8 -12
- data/lib/ramaze/adapter/cgi.rb +14 -13
- data/lib/ramaze/adapter/ebb.rb +34 -0
- data/lib/ramaze/adapter/evented_mongrel.rb +1 -1
- data/lib/ramaze/adapter/fcgi.rb +14 -14
- data/lib/ramaze/adapter/lsws.rb +15 -11
- data/lib/ramaze/adapter/mongrel.rb +2 -1
- data/lib/ramaze/adapter/scgi.rb +24 -0
- data/lib/ramaze/adapter/swiftiplied_mongrel.rb +1 -1
- data/lib/ramaze/adapter/thin.rb +4 -5
- data/lib/ramaze/adapter/webrick.rb +5 -5
- data/lib/ramaze/cache.rb +1 -1
- data/lib/ramaze/cache/memcached.rb +1 -1
- data/lib/ramaze/contrib.rb +70 -10
- data/lib/ramaze/contrib/auto_params.rb +1 -1
- data/lib/ramaze/contrib/email.rb +15 -15
- data/lib/ramaze/contrib/facebook.rb +2 -2
- data/lib/ramaze/contrib/facebook/facebook.rb +7 -4
- data/lib/ramaze/contrib/file_cache.rb +65 -0
- data/lib/ramaze/contrib/gettext.rb +56 -55
- data/lib/ramaze/contrib/profiling.rb +36 -0
- data/lib/ramaze/contrib/sequel_cache.rb +92 -0
- data/lib/ramaze/controller.rb +80 -47
- data/lib/ramaze/controller/error.rb +10 -5
- data/lib/ramaze/controller/resolve.rb +36 -48
- data/lib/ramaze/current.rb +70 -0
- data/lib/ramaze/{trinity → current}/request.rb +62 -15
- data/lib/ramaze/current/response.rb +19 -0
- data/lib/ramaze/{trinity → current}/session.rb +32 -110
- data/lib/ramaze/current/session/flash.rb +67 -0
- data/lib/ramaze/current/session/hash.rb +65 -0
- data/lib/ramaze/dispatcher.rb +1 -28
- data/lib/ramaze/dispatcher/action.rb +6 -3
- data/lib/ramaze/dispatcher/directory.rb +1 -1
- data/lib/ramaze/dispatcher/error.rb +26 -5
- data/lib/ramaze/dispatcher/file.rb +13 -2
- data/lib/ramaze/gestalt.rb +3 -1
- data/lib/ramaze/global.rb +6 -3
- data/lib/ramaze/global/globalstruct.rb +3 -1
- data/lib/ramaze/helper.rb +66 -20
- data/lib/ramaze/helper/aspect.rb +25 -17
- data/lib/ramaze/helper/auth.rb +4 -3
- data/lib/ramaze/helper/cache.rb +5 -4
- data/lib/ramaze/helper/cgi.rb +11 -9
- data/lib/ramaze/helper/flash.rb +28 -3
- data/lib/ramaze/helper/formatting.rb +1 -3
- data/lib/ramaze/helper/identity.rb +2 -3
- data/lib/ramaze/helper/inform.rb +7 -6
- data/lib/ramaze/helper/link.rb +15 -17
- data/lib/ramaze/helper/markaby.rb +2 -4
- data/lib/ramaze/helper/maruku.rb +1 -1
- data/lib/ramaze/helper/nitroform.rb +4 -4
- data/lib/ramaze/helper/pager.rb +4 -6
- data/lib/ramaze/helper/partial.rb +24 -21
- data/lib/ramaze/helper/redirect.rb +8 -5
- data/lib/ramaze/helper/{file.rb → sendfile.rb} +1 -3
- data/lib/ramaze/helper/sequel.rb +1 -3
- data/lib/ramaze/helper/stack.rb +1 -3
- data/lib/ramaze/helper/tagz.rb +19 -0
- data/lib/ramaze/helper/user.rb +63 -0
- data/lib/ramaze/inform.rb +2 -24
- data/lib/ramaze/log.rb +28 -0
- data/lib/ramaze/{inform → log}/analogger.rb +3 -3
- data/lib/ramaze/{inform → log}/growl.rb +2 -2
- data/lib/ramaze/{inform → log}/hub.rb +4 -6
- data/lib/ramaze/{inform → log}/informer.rb +4 -4
- data/lib/ramaze/{inform → log}/knotify.rb +2 -2
- data/lib/ramaze/log/logger.rb +22 -0
- data/lib/ramaze/{inform/informing.rb → log/logging.rb} +16 -16
- data/lib/ramaze/{inform → log}/syslog.rb +0 -0
- data/lib/ramaze/{inform → log}/xosd.rb +2 -2
- data/lib/ramaze/route.rb +64 -36
- data/lib/ramaze/snippets/array/put_within.rb +13 -0
- data/lib/ramaze/snippets/binding/locals.rb +13 -0
- data/lib/ramaze/snippets/kernel/__dir__.rb +10 -8
- data/lib/ramaze/snippets/kernel/aquire.rb +1 -1
- data/lib/ramaze/snippets/kernel/constant.rb +1 -1
- data/lib/ramaze/snippets/object/pretty.rb +6 -0
- data/lib/ramaze/snippets/object/scope.rb +11 -0
- data/lib/ramaze/snippets/object/thread_accessor.rb +5 -0
- data/lib/ramaze/snippets/ordered_set.rb +1 -1
- data/lib/ramaze/snippets/proc/locals.rb +11 -0
- data/lib/ramaze/snippets/ramaze/thread_accessor.rb +44 -0
- data/lib/ramaze/snippets/string/esc.rb +29 -0
- data/lib/ramaze/snippets/string/start_with.rb +7 -0
- data/lib/ramaze/snippets/string/unindent.rb +6 -1
- data/lib/ramaze/snippets/struct/values_at.rb +1 -5
- data/lib/ramaze/sourcereload.rb +16 -14
- data/lib/ramaze/spec.rb +1 -0
- data/lib/ramaze/spec/helper.rb +11 -3
- data/lib/ramaze/spec/helper/browser.rb +25 -1
- data/lib/ramaze/spec/helper/pretty_output.rb +11 -11
- data/lib/ramaze/template.rb +5 -4
- data/lib/ramaze/template/amrita2.rb +2 -3
- data/lib/ramaze/template/ezamar/element.rb +2 -3
- data/lib/ramaze/template/ezamar/morpher.rb +1 -2
- data/lib/ramaze/template/ezamar/render_partial.rb +1 -1
- data/lib/ramaze/template/haml.rb +5 -2
- data/lib/ramaze/template/markaby.rb +2 -0
- data/lib/ramaze/template/tagz.rb +79 -0
- data/lib/ramaze/template/tenjin.rb +34 -0
- data/lib/ramaze/tool/create.rb +0 -3
- data/lib/ramaze/tool/localize.rb +107 -105
- data/lib/ramaze/tool/mime.rb +0 -2
- data/lib/ramaze/trinity.rb +1 -26
- data/lib/ramaze/version.rb +1 -1
- data/lib/vendor/bacon.rb +47 -41
- data/rake_tasks/conf.rake +18 -0
- data/rake_tasks/darcs.rake +5 -0
- data/rake_tasks/maintenance.rake +37 -24
- data/rake_tasks/spec.rake +1 -1
- data/spec/contrib/auto_params.rb +3 -1
- data/spec/contrib/profiling.rb +26 -0
- data/spec/examples/templates/template_redcloth.rb +1 -1
- data/spec/examples/templates/template_tenjin.rb +28 -0
- data/spec/helper.rb +0 -1
- data/spec/ramaze/action/layout.rb +28 -0
- data/spec/ramaze/controller/actionless_templates.rb +32 -0
- data/spec/ramaze/controller/template/other_wrapper.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +37 -0
- data/spec/ramaze/{trinity → current}/request.rb +12 -2
- data/spec/ramaze/current/session.rb +97 -0
- data/spec/ramaze/dispatcher/directory.rb +2 -1
- data/spec/ramaze/dispatcher/file.rb +8 -3
- data/spec/ramaze/dispatcher/public/file name.txt +1 -0
- data/spec/ramaze/gestalt.rb +11 -0
- data/spec/ramaze/helper/aspect.rb +28 -22
- data/spec/ramaze/helper/cgi.rb +2 -2
- data/spec/ramaze/helper/flash.rb +33 -15
- data/spec/ramaze/helper/formatting.rb +2 -2
- data/spec/ramaze/helper/link.rb +46 -18
- data/spec/ramaze/helper/pager.rb +8 -5
- data/spec/ramaze/helper/partial.rb +8 -1
- data/spec/ramaze/helper/template/recursive_local_ivars.xhtml +7 -0
- data/spec/ramaze/helper/user.rb +46 -0
- data/spec/ramaze/{inform → log}/informer.rb +0 -0
- data/spec/ramaze/{inform → log}/syslog.rb +1 -1
- data/spec/ramaze/request.rb +14 -10
- data/spec/ramaze/route.rb +23 -0
- data/spec/ramaze/template.rb +48 -1
- data/spec/ramaze/template/haml.rb +6 -16
- data/spec/ramaze/template/haml/locals.haml +2 -1
- data/spec/ramaze/template/tagz.rb +62 -0
- data/spec/ramaze/template/tagz/external.tagz +8 -0
- data/spec/ramaze/template/tagz/sum.tagz +1 -0
- data/spec/ramaze/template/tenjin.rb +49 -0
- data/spec/ramaze/template/tenjin/external.tenjin +1 -0
- data/spec/snippets/string/unindent.rb +15 -0
- metadata +509 -475
- data/doc/README.html +0 -729
- data/doc/changes.txt +0 -5757
- data/doc/changes.xml +0 -5759
- data/examples/blog/src/view.rb +0 -16
- data/examples/blog/template/edit.xhtml +0 -19
- data/examples/blog/template/index.xhtml +0 -19
- data/examples/blog/template/new.xhtml +0 -18
- data/examples/wiktacular/mkd/newpagename/current.mkd +0 -1
- data/examples/wiktacular/mkd/newpagename/current.mkd.bak +0 -1
- data/lib/ramaze/contrib/email.rb-darcs-backup0 +0 -81
- data/lib/ramaze/template/bijou.rb +0 -39
- data/lib/ramaze/trinity/response.rb +0 -32
- data/spec/ramaze/template/bijou.rb +0 -25
- data/spec/ramaze/trinity/session.rb +0 -29
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
|
-
Ramaze::
|
|
4
|
+
Ramaze::Log.debug "Using Swiftiplied Mongrel"
|
|
5
5
|
|
|
6
6
|
require 'swiftcore/swiftiplied_mongrel'
|
|
7
7
|
require 'ramaze/adapter/mongrel'
|
data/lib/ramaze/adapter/thin.rb
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
require 'thin'
|
|
2
|
-
require 'ramaze/adapter'
|
|
3
2
|
require 'rack/handler/thin'
|
|
4
3
|
|
|
5
4
|
module Ramaze
|
|
6
|
-
|
|
5
|
+
Global.test_connections = true
|
|
7
6
|
|
|
7
|
+
module Adapter
|
|
8
8
|
class Thin < Base
|
|
9
9
|
class << self
|
|
10
10
|
|
|
11
11
|
# start server on given host and port.
|
|
12
12
|
def run_server host, port
|
|
13
13
|
server = ::Thin::Server.new(host, port, self)
|
|
14
|
-
|
|
14
|
+
::Thin::Logging.silent = true
|
|
15
15
|
server.timeout = 3
|
|
16
|
-
server.start
|
|
17
16
|
|
|
18
|
-
thread = Thread.new{ server.
|
|
17
|
+
thread = Thread.new{ server.start }
|
|
19
18
|
thread[:adapter] = server
|
|
20
19
|
thread
|
|
21
20
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
|
-
require 'ramaze/adapter'
|
|
5
4
|
require 'webrick'
|
|
6
5
|
require 'rack/handler/webrick'
|
|
7
6
|
|
|
8
7
|
module Ramaze
|
|
9
|
-
|
|
8
|
+
Global.test_connections = true
|
|
10
9
|
|
|
10
|
+
module Adapter
|
|
11
11
|
# Our WEBrick adapter acts as wrapper for the Rack::Handler::WEBrick.
|
|
12
12
|
class WEBrick < Base
|
|
13
13
|
class << self
|
|
@@ -17,10 +17,10 @@ module Ramaze
|
|
|
17
17
|
options = {
|
|
18
18
|
:Port => port,
|
|
19
19
|
:BindAddress => host,
|
|
20
|
-
:Logger =>
|
|
20
|
+
:Logger => Log,
|
|
21
21
|
:AccessLog => [
|
|
22
|
-
[
|
|
23
|
-
[
|
|
22
|
+
[Log, ::WEBrick::AccessLog::COMMON_LOG_FORMAT],
|
|
23
|
+
[Log, ::WEBrick::AccessLog::REFERER_LOG_FORMAT]
|
|
24
24
|
]
|
|
25
25
|
}.merge(options)
|
|
26
26
|
|
data/lib/ramaze/cache.rb
CHANGED
data/lib/ramaze/contrib.rb
CHANGED
|
@@ -2,21 +2,81 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
module Ramaze
|
|
5
|
+
|
|
6
|
+
# Loads and sets up contrib modules.
|
|
7
|
+
#
|
|
8
|
+
# For more information @see Ramaze::Contrib.load
|
|
9
|
+
#
|
|
10
|
+
# Usage:
|
|
11
|
+
#
|
|
12
|
+
# Ramaze.contrib :gzip_filter
|
|
13
|
+
|
|
5
14
|
def self.contrib(*args)
|
|
6
|
-
|
|
15
|
+
Contrib.load *args
|
|
7
16
|
end
|
|
8
17
|
|
|
18
|
+
# A module used for loading contrib modules.
|
|
19
|
+
|
|
9
20
|
module Contrib
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
|
|
22
|
+
# Loads and sets up contrib modules from /ramaze/contrib.
|
|
23
|
+
#
|
|
24
|
+
# === Usage:
|
|
25
|
+
#
|
|
26
|
+
# Ramaze::Contrib.load :gzip_filter
|
|
27
|
+
#
|
|
28
|
+
# === Creating a contrib module:
|
|
29
|
+
#
|
|
30
|
+
# module Ramaze::Contrib::Test
|
|
31
|
+
# def self.setup
|
|
32
|
+
# Log.info "Test module set up"
|
|
33
|
+
# end
|
|
34
|
+
# end
|
|
35
|
+
# class TestController < Ramaze::Controller
|
|
36
|
+
# map '/test'
|
|
37
|
+
# def index; "Chunky Bacon!"; end
|
|
38
|
+
# end
|
|
39
|
+
#
|
|
40
|
+
# # Save that to your <app dir>/contrib and use like:
|
|
41
|
+
# Ramaze.contrib :test
|
|
42
|
+
|
|
43
|
+
def self.load(*contribs)
|
|
44
|
+
contribs.each do |name|
|
|
45
|
+
mod_name = name.to_s.camel_case
|
|
46
|
+
begin
|
|
47
|
+
const = Contrib.const_get(mod_name)
|
|
48
|
+
Global.contribs << const
|
|
16
49
|
const.startup if const.respond_to?(:startup)
|
|
17
|
-
|
|
50
|
+
Log.dev "Loaded contrib: #{const}"
|
|
51
|
+
rescue NameError
|
|
52
|
+
files = Dir["{contrib,#{BASEDIR/:ramaze/:contrib}}/#{name}.{so,bundle,rb}"]
|
|
53
|
+
raise LoadError, "#{mod_name} not found" unless files.any?
|
|
54
|
+
require(files.first) ? retry : raise
|
|
18
55
|
end
|
|
19
56
|
end
|
|
20
57
|
end
|
|
21
|
-
|
|
22
|
-
|
|
58
|
+
|
|
59
|
+
# Will call .shutdown on all contrib modules which support it.
|
|
60
|
+
#---
|
|
61
|
+
# .shudown gets called by Ramaze :essentials.
|
|
62
|
+
#+++
|
|
63
|
+
|
|
64
|
+
def self.shutdown
|
|
65
|
+
Global.contribs.each do |contrib|
|
|
66
|
+
contrib.shutdown if contrib.respond_to?(:shutdown)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Will load all contrib modules from options[:contrib]
|
|
71
|
+
#---
|
|
72
|
+
# .startup gets called by Ramaze :essentials.
|
|
73
|
+
#+++
|
|
74
|
+
|
|
75
|
+
def self.startup(options = {})
|
|
76
|
+
return unless options[:contrib]
|
|
77
|
+
[options[:contrib]].flatten.each do |contrib|
|
|
78
|
+
load(contrib)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end # class Contrib
|
|
82
|
+
end # class Ramaze
|
data/lib/ramaze/contrib/email.rb
CHANGED
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
# require 'ramaze/contrib/email'
|
|
6
6
|
#
|
|
7
7
|
# # Set the required traits:
|
|
8
|
-
# Ramaze::EmailHelper.trait
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
8
|
+
# Ramaze::EmailHelper.trait :smtp_server => 'smtp.your-isp.com',
|
|
9
|
+
# :smtp_helo_domain => "originating-server.com",
|
|
10
|
+
# :smtp_username => 'username',
|
|
11
|
+
# :smtp_password => 'password',
|
|
12
|
+
# :sender_address => 'no-reply@your-domain.com'
|
|
13
13
|
#
|
|
14
14
|
# # Optionally, set some other traits:
|
|
15
|
-
# Ramaze::EmailHelper.trait
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
15
|
+
# Ramaze::EmailHelper.trait :smtp_auth_type => :login,
|
|
16
|
+
# :bcc_addresses => [ 'admin@your-domain.com' ],
|
|
17
|
+
# :sender_full => 'MailBot <no-reply@your-domain.com>',
|
|
18
|
+
# :id_generator => lambda { "<#{Time.now.to_i}@your-domain.com>" },
|
|
19
|
+
# :subject_prefix => "[SiteName]"
|
|
20
20
|
#
|
|
21
21
|
# To send an e-mail:
|
|
22
22
|
#
|
|
@@ -70,15 +70,15 @@ Message-Id: #{id}
|
|
|
70
70
|
def send_smtp( email, recipient, subject )
|
|
71
71
|
options = trait.values_at(:smtp_server, :smtp_port, :smtp_helo_domain,
|
|
72
72
|
:smtp_username, :smtp_password, :smtp_auth_type)
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
Net::SMTP.start( *options ) do |smtp|
|
|
75
75
|
smtp.send_message( email, trait[ :sender_address ], Array[ recipient, *trait[ :bcc_addresses ] ] )
|
|
76
|
-
|
|
76
|
+
Log.info "E-mail sent to #{recipient} - '#{subject}'"
|
|
77
77
|
end
|
|
78
78
|
rescue => e
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
Log.error "Failed to send e-mail to #{recipient}"
|
|
80
|
+
Log.error e
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
|
-
end
|
|
84
|
+
end
|
|
@@ -47,7 +47,7 @@ module Facebook
|
|
|
47
47
|
else
|
|
48
48
|
v.to_s
|
|
49
49
|
end
|
|
50
|
-
|
|
50
|
+
}.sort
|
|
51
51
|
|
|
52
52
|
data = Array["sig=#{Digest::MD5.hexdigest(args.join+SECRET)}", *args].join('&')
|
|
53
53
|
|
|
@@ -71,7 +71,10 @@ module Facebook
|
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
unless method == 'fql.query'
|
|
75
|
+
ret = ret.first if ret.is_a? Array and ret.size == 1 and ret.first.is_a? Hash
|
|
76
|
+
end
|
|
77
|
+
|
|
75
78
|
raise Facebook::Error, ret['error_msg'] if ret.is_a? Hash and ret['error_code']
|
|
76
79
|
|
|
77
80
|
ret
|
|
@@ -83,7 +86,7 @@ module Facebook
|
|
|
83
86
|
end
|
|
84
87
|
|
|
85
88
|
def valid?
|
|
86
|
-
return false unless
|
|
89
|
+
return false unless respond_to?(:request) and not request['fb_sig'].nil?
|
|
87
90
|
request['facebook.valid?'] ||= \
|
|
88
91
|
request['fb_sig'] == Digest::MD5.hexdigest(request.params.map{|k,v| "#{$1}=#{v}" if k =~ /^fb_sig_(.+)$/ }.compact.sort.join+SECRET)
|
|
89
92
|
end
|
|
@@ -94,7 +97,7 @@ module Facebook
|
|
|
94
97
|
|
|
95
98
|
def redirect url
|
|
96
99
|
url[0,0] = URL unless url =~ /^http/
|
|
97
|
-
if
|
|
100
|
+
if respond_to?(:response)
|
|
98
101
|
response.build "<fb:redirect url='#{url}'/>"
|
|
99
102
|
throw :respond
|
|
100
103
|
else
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#
|
|
2
|
+
# drop-in replacement for Ramaze's built-in MemoryCache built on the
|
|
3
|
+
# filesystem. # to use with sessions do
|
|
4
|
+
#
|
|
5
|
+
# Ramaze::Global::cache_alternative[:sessions] = Ramaze::FileCache
|
|
6
|
+
#
|
|
7
|
+
# to use with everything do
|
|
8
|
+
#
|
|
9
|
+
# Ramaze::Global::cache = Ramaze::FileCache
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
module Ramaze::FileCache
|
|
13
|
+
require "fileutils"
|
|
14
|
+
require "socket"
|
|
15
|
+
|
|
16
|
+
Host = Socket.gethostname
|
|
17
|
+
Pid = Process.pid
|
|
18
|
+
Fu = FileUtils
|
|
19
|
+
Root = File.join Ramaze::APPDIR, "cache"
|
|
20
|
+
|
|
21
|
+
Fu.mkdir_p(Root) rescue nil
|
|
22
|
+
|
|
23
|
+
def self.[] key
|
|
24
|
+
path = File.join Root, key, "data"
|
|
25
|
+
Marshal.load(IO.read(path))
|
|
26
|
+
rescue
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.[]= key, value
|
|
31
|
+
tmp = File.join Root, key, "data.#{ Host }.#{ Pid }"
|
|
32
|
+
dirname = File.join Root, key
|
|
33
|
+
path = File.join Root, key, "data"
|
|
34
|
+
data = Marshal.dump value
|
|
35
|
+
Fu.rm_rf dirname rescue nil
|
|
36
|
+
Fu.mkdir_p dirname rescue nil
|
|
37
|
+
open(tmp, 'w'){|fd| fd.write data}
|
|
38
|
+
Fu.mv tmp, path
|
|
39
|
+
rescue
|
|
40
|
+
nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.values_at *keys
|
|
44
|
+
keys.map{|key| self[key]}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.delete *keys
|
|
48
|
+
keys.map do |key|
|
|
49
|
+
dirname = File.join Root, key
|
|
50
|
+
Fu.rm_rf dirname rescue next
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.clear
|
|
55
|
+
Dir["#{ Root }/*"].each{|entry| Fu.rm_rf entry}
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.new
|
|
59
|
+
self
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.to_sym
|
|
63
|
+
name.split(%r/::/).last.to_sym
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -22,84 +22,85 @@ require 'ramaze/contrib/gettext/po'
|
|
|
22
22
|
#
|
|
23
23
|
# Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Gettext
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
module Ramaze
|
|
26
|
+
class Tool::Gettext < Tool::Localize
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
# Enable Localization
|
|
29
|
+
trait :enable => true
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
# Default language that is used if the browser don't suggests otherwise or
|
|
32
|
+
# the language requested is not available.
|
|
33
|
+
trait :default_language => 'en'
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
# languages supported
|
|
36
|
+
trait :languages => %w[ en ]
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
# YAML files the localizations are saved to and loaded from, %s is
|
|
39
|
+
# substituted by the values from trait[:languages]
|
|
40
|
+
trait :file => 'conf/locale_%s.mo'.freeze
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
# The pattern that is substituted with the translation of the current locale.
|
|
43
|
+
trait :regex => /\[\[(.*?)\]\]/
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
# Browsers may send different keys for the same language, this allows you to
|
|
46
|
+
# do some coercion between what you use as keys and what the browser sends.
|
|
47
|
+
trait :mapping => { 'en-us' => 'en', 'ja' => 'jp'}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
# When this is set to false, it will not save newly collected translatable
|
|
50
|
+
# strings to disk. Disable this for production use, as it slows the
|
|
51
|
+
# application down.
|
|
52
|
+
trait :collect => true
|
|
52
53
|
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
# Load given locales from disk and save it into the dictionary.
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
def self.load(*locales)
|
|
58
|
+
Log.debug "loading locales: #{locales.inspect}"
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
dict = trait[:dictionary] || {}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
locales.each do |locale|
|
|
63
|
+
begin
|
|
64
|
+
dict[locale] = ::MOFile.open(trait[:file] % locale)
|
|
65
|
+
rescue Errno::ENOENT
|
|
66
|
+
Log.error "couldn't load #{trait[:file] % locale}"
|
|
67
|
+
dict[locale] = {}
|
|
68
|
+
end
|
|
67
69
|
end
|
|
68
|
-
end
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
trait[:dictionary] = dict
|
|
72
|
+
end
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
# Reloads given locales from the disk to refresh the dictionary.
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
def self.update
|
|
77
|
+
trait[:dictionary] = nil
|
|
78
|
+
dictionary.each do |locale, dict|
|
|
79
|
+
if dict.kind_of?(MOFile)
|
|
80
|
+
Log.debug("Reloading #{dict.filename}")
|
|
81
|
+
dict.update!
|
|
82
|
+
end
|
|
81
83
|
end
|
|
82
84
|
end
|
|
83
|
-
end
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
# Stores given locales from the dictionary to disk.
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
def self.store(*locales)
|
|
89
|
+
keys = []
|
|
90
|
+
dictionary.each do |locale, dict|
|
|
91
|
+
keys.concat dict.keys
|
|
92
|
+
end
|
|
93
|
+
keys.delete ""
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
data = ::GetText::RGetText.generate(keys.compact.uniq.sort.map {|x| [x] })
|
|
96
|
+
file = (trait[:file] % trait[:default_language]) + '.pot'
|
|
97
|
+
File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
|
|
98
|
+
fd.write data
|
|
99
|
+
end
|
|
100
|
+
rescue Errno::ENOENT => e
|
|
101
|
+
Log.error e
|
|
98
102
|
end
|
|
99
|
-
rescue Errno::ENOENT => e
|
|
100
|
-
Ramaze::Inform.error e
|
|
101
103
|
end
|
|
102
|
-
|
|
103
104
|
end
|
|
104
105
|
|
|
105
106
|
class Ramaze::Contrib::Gettext
|