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
data/lib/ramaze/spec.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'ramaze/spec/helper'
|
data/lib/ramaze/spec/helper.rb
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
begin
|
|
5
5
|
require 'rubygems'
|
|
6
|
-
rescue LoadError
|
|
6
|
+
rescue LoadError
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
require 'timeout'
|
|
10
|
-
|
|
11
9
|
require 'ramaze'
|
|
12
10
|
require 'ramaze/spec/helper/bacon'
|
|
13
11
|
|
|
@@ -112,3 +110,13 @@ shared 'xpath' do
|
|
|
112
110
|
end
|
|
113
111
|
end
|
|
114
112
|
end
|
|
113
|
+
|
|
114
|
+
shared 'resolve' do
|
|
115
|
+
def resolve(url)
|
|
116
|
+
Ramaze::Controller::resolve(url)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def stack(url, &block)
|
|
120
|
+
resolve(url).stack(&block)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
class Browser
|
|
5
|
-
attr_reader :cookie
|
|
5
|
+
attr_reader :cookie, :http
|
|
6
6
|
|
|
7
7
|
def initialize(url = '/', base = '/', &block)
|
|
8
8
|
@base = base
|
|
@@ -42,6 +42,30 @@ class Browser
|
|
|
42
42
|
erequest(:get, url, hash)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def hget(*args)
|
|
46
|
+
@page = Hpricot(get(*args))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def hpost(*args)
|
|
50
|
+
@page = Hpricot(post(*args))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def find_link(text)
|
|
54
|
+
link = @page.at("a[text()='#{text}']")
|
|
55
|
+
link.should.not.be.nil if link.respond_to?(:should)
|
|
56
|
+
link[:href]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def follow_link(text)
|
|
60
|
+
hget find_link(text)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def follow_links(*texts)
|
|
64
|
+
texts.each do |text|
|
|
65
|
+
follow_link text
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
45
69
|
def request method, url, hash = {}
|
|
46
70
|
@http.uri = url2uri(url)
|
|
47
71
|
@http.request_headers['referer'] = @history.last.path rescue '/'
|
|
@@ -14,12 +14,12 @@ module Bacon
|
|
|
14
14
|
error = yield
|
|
15
15
|
|
|
16
16
|
unless error.empty?
|
|
17
|
-
if defined?(Ramaze::
|
|
17
|
+
if defined?(Ramaze::Logging)
|
|
18
18
|
puts '', " #{NAME} -- #{description} [FAILED]".center(70, '-'), ''
|
|
19
19
|
colors = Ramaze::Informer::COLORS
|
|
20
20
|
|
|
21
|
-
until RamazeLogger.
|
|
22
|
-
tag, line = RamazeLogger.
|
|
21
|
+
until RamazeLogger.history.empty?
|
|
22
|
+
tag, line = RamazeLogger.history.shift
|
|
23
23
|
out = "%6s | %s" % [tag.to_s, line]
|
|
24
24
|
puts out.send(colors[tag])
|
|
25
25
|
end
|
|
@@ -45,30 +45,30 @@ module Bacon
|
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
if defined?(Ramaze::
|
|
48
|
+
if defined?(Ramaze::Logging)
|
|
49
49
|
module Ramaze
|
|
50
50
|
class SpecLogger
|
|
51
|
-
include Ramaze::
|
|
51
|
+
include Ramaze::Logging
|
|
52
52
|
include Enumerable
|
|
53
53
|
|
|
54
|
-
attr_accessor :
|
|
54
|
+
attr_accessor :history
|
|
55
55
|
|
|
56
56
|
def initialize
|
|
57
|
-
@
|
|
57
|
+
@history = []
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def each
|
|
61
|
-
@
|
|
61
|
+
@history.each{|e| yield(e) }
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def
|
|
65
|
-
@
|
|
64
|
+
def log(tag, str)
|
|
65
|
+
@history << [tag, str]
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
module Bacon::PrettyOutput
|
|
71
71
|
RamazeLogger = Ramaze::SpecLogger.new
|
|
72
|
-
Ramaze::
|
|
72
|
+
Ramaze::Log.loggers = [RamazeLogger]
|
|
73
73
|
end
|
|
74
74
|
end
|
data/lib/ramaze/template.rb
CHANGED
|
@@ -16,16 +16,17 @@ module Ramaze
|
|
|
16
16
|
|
|
17
17
|
ENGINES = {} unless defined?(ENGINES)
|
|
18
18
|
|
|
19
|
-
%w[ Amrita2 Builder Erubis Haml Liquid Markaby Nagoro None RedCloth Remarkably Sass XSLT ]
|
|
20
|
-
|
|
19
|
+
AVAILABLE_ENGINES = %w[ Amrita2 Builder Erubis Haml Liquid Markaby Nagoro None RedCloth Remarkably Sass XSLT Tenjin Tagz ]
|
|
20
|
+
|
|
21
|
+
AVAILABLE_ENGINES.each do |const|
|
|
21
22
|
autoload(const, "ramaze/template/#{const.downcase}")
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
# The superclass for all templates, contains the shared behaviour of
|
|
25
|
-
# the templates and includes Ramaze::Helper
|
|
26
|
+
# the templates and includes Ramaze::Helper::Methods
|
|
26
27
|
|
|
27
28
|
class Template
|
|
28
|
-
include Ramaze::Helper
|
|
29
|
+
include Ramaze::Helper::Methods
|
|
29
30
|
|
|
30
31
|
class << self
|
|
31
32
|
|
|
@@ -7,9 +7,8 @@ class Amrita2::Template
|
|
|
7
7
|
|
|
8
8
|
# Ramaze helpers are available in template contexts.
|
|
9
9
|
|
|
10
|
-
include Ramaze::Helper
|
|
11
|
-
|
|
12
|
-
helper :link, :file, :flash, :cgi
|
|
10
|
+
include Ramaze::Helper::Methods
|
|
11
|
+
helper :link, :sendfile, :flash, :cgi
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
module Ramaze
|
|
@@ -56,8 +56,7 @@
|
|
|
56
56
|
class Ezamar::Element
|
|
57
57
|
attr_accessor :content
|
|
58
58
|
|
|
59
|
-
include Ramaze::Helper
|
|
60
|
-
extend Ramaze::Helper
|
|
59
|
+
include Ramaze::Helper::Methods
|
|
61
60
|
|
|
62
61
|
helper :redirect, :link
|
|
63
62
|
|
|
@@ -137,7 +136,7 @@ class Ezamar::Element
|
|
|
137
136
|
|
|
138
137
|
instance.render
|
|
139
138
|
rescue => ex
|
|
140
|
-
Ramaze::
|
|
139
|
+
Ramaze::Log.debug(ex.message)
|
|
141
140
|
''
|
|
142
141
|
end
|
|
143
142
|
|
|
@@ -1,11 +1,10 @@
|
|
|
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/template/ezamar/engine'
|
|
5
4
|
begin
|
|
6
5
|
require 'hpricot'
|
|
7
6
|
rescue LoadError => ex
|
|
8
|
-
Ramaze::
|
|
7
|
+
Ramaze::Log.error "Please install hpricot (for example via `gem install hpricot`) to get morphing"
|
|
9
8
|
puts ex
|
|
10
9
|
end
|
|
11
10
|
|
data/lib/ramaze/template/haml.rb
CHANGED
|
@@ -19,14 +19,17 @@ module Ramaze
|
|
|
19
19
|
|
|
20
20
|
def transform action
|
|
21
21
|
haml = wrap_compile(action)
|
|
22
|
-
haml.to_html(action.instance)
|
|
22
|
+
haml.to_html(action.instance, action.binding.locals)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
# Instantiates Haml::Engine with the template and haml_options trait from
|
|
26
26
|
# the controller.
|
|
27
27
|
|
|
28
28
|
def compile(action, template)
|
|
29
|
-
|
|
29
|
+
opts = action.controller.trait[:haml_options] || {}
|
|
30
|
+
opts.merge! :filename => action.template if action.template
|
|
31
|
+
|
|
32
|
+
::Haml::Engine.new(template, opts)
|
|
30
33
|
end
|
|
31
34
|
end
|
|
32
35
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
|
+
|
|
4
|
+
require "tagz"
|
|
5
|
+
|
|
6
|
+
module Ramaze
|
|
7
|
+
module Template
|
|
8
|
+
|
|
9
|
+
# Is responsible for compiling a template using the Tagz templating engine.
|
|
10
|
+
# Can be found at: http://rubyforge.org/projects/codeforpeople/
|
|
11
|
+
# gem install tagz
|
|
12
|
+
# be sure you get version 1.0 or higher
|
|
13
|
+
|
|
14
|
+
class Tagz < Template
|
|
15
|
+
ENGINES[self] = %w[ rb tagz ]
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
|
|
19
|
+
# Entry point for Action#render
|
|
20
|
+
|
|
21
|
+
def transform action
|
|
22
|
+
result, file = result_and_file(action)
|
|
23
|
+
if file
|
|
24
|
+
markup = "tagz{#{ file }}"
|
|
25
|
+
action.instance.extend Methods
|
|
26
|
+
result = eval markup, action.binding, file
|
|
27
|
+
end
|
|
28
|
+
result
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Methods defines a host of methods useful inside the context of a view
|
|
34
|
+
# including print style methods that output content rather that printing to
|
|
35
|
+
# STDOUT
|
|
36
|
+
|
|
37
|
+
module Methods
|
|
38
|
+
include ::Tagz
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
def << s
|
|
42
|
+
tagz << s; self
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def concat *a
|
|
46
|
+
a.each{|s| tagz << s}; self
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def puts *a
|
|
50
|
+
a.each{|elem| tagz << "#{ elem.to_s.chomp }#{ eol }"}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def print *a
|
|
54
|
+
a.each{|elem| tagz << elem}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def p *a
|
|
58
|
+
a.each{|elem| tagz << "#{ CGI.escapeHTML elem.inspect }#{ eol }"}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def pp *a
|
|
62
|
+
a.each{|elem| tagz << "#{ CGI.escapeHTML PP.pp(elem, '') }#{ eol }"}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def eol
|
|
66
|
+
if response.content_type =~ %r|text/plain|io
|
|
67
|
+
"\n"
|
|
68
|
+
else
|
|
69
|
+
"<br />"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def __ *a
|
|
74
|
+
concat eol
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "tenjin"
|
|
2
|
+
require "tempfile"
|
|
3
|
+
|
|
4
|
+
class Tenjin::Context
|
|
5
|
+
include Ramaze::Helper::Methods
|
|
6
|
+
helper :link, :sendfile, :flash, :cgi
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Ramaze
|
|
10
|
+
module Template
|
|
11
|
+
|
|
12
|
+
# Is responsible for compiling a template using the Tenjin templating engine.
|
|
13
|
+
# Can be found at: http://www.kuwata-lab.com/tenjin/
|
|
14
|
+
|
|
15
|
+
class Tenjin < Template
|
|
16
|
+
|
|
17
|
+
ENGINES[self] = %w[ rbhtml tenjin ]
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
def transform(action)
|
|
21
|
+
tenjin = wrap_compile(action)
|
|
22
|
+
context = action.instance.instance_variable_get("@context") || {}
|
|
23
|
+
tenjin.render(context)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def compile(action, template)
|
|
27
|
+
tenjin = ::Tenjin::Template.new
|
|
28
|
+
tenjin.convert(template)
|
|
29
|
+
return tenjin
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/ramaze/tool/create.rb
CHANGED
data/lib/ramaze/tool/localize.rb
CHANGED
|
@@ -12,149 +12,151 @@ require 'ya2yaml'
|
|
|
12
12
|
#
|
|
13
13
|
# Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Localize
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
module Ramaze
|
|
16
|
+
class Tool::Localize
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
# Enable Localization
|
|
19
|
+
trait :enable => true
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
# Default language that is used if the browser don't suggests otherwise or
|
|
22
|
+
# the language requested is not available.
|
|
23
|
+
trait :default_language => 'en'
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
# languages supported
|
|
26
|
+
trait :languages => %w[ en ]
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
# YAML files the localizations are saved to and loaded from, %s is
|
|
29
|
+
# substituted by the values from trait[:languages]
|
|
30
|
+
trait :file => 'conf/locale_%s.yaml'.freeze
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
# The pattern that is substituted with the translation of the current locale.
|
|
33
|
+
trait :regex => /\[\[(.*?)\]\]/
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# Browsers may send different keys for the same language, this allows you to
|
|
36
|
+
# do some coercion between what you use as keys and what the browser sends.
|
|
37
|
+
trait :mapping => { 'en-us' => 'en', 'ja' => 'jp'}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
# When this is set to false, it will not save newly collected translatable
|
|
40
|
+
# strings to disk. Disable this for production use, as it slows the
|
|
41
|
+
# application down.
|
|
42
|
+
trait :collect => true
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
class << self
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
include Trinity
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
# Enables being plugged into Dispatcher::Action::FILTER
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
def call(response, options = {})
|
|
51
|
+
return response unless trait[:enable]
|
|
52
|
+
return response if response.body.nil?
|
|
53
|
+
return response if response.body.respond_to?(:read)
|
|
54
|
+
response.body = localize_body(response.body, options)
|
|
55
|
+
response
|
|
56
|
+
end
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
# Localizes a response body. It reacts to a regular expression as given
|
|
59
|
+
# in trait[:regex]. Every 'entity' in it will be translated, see
|
|
60
|
+
# `localize` for more information.
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
def localize_body(body, options)
|
|
63
|
+
locale =
|
|
64
|
+
if trait[:languages].include?(response["Content-Language"])
|
|
65
|
+
response["Content-Language"]
|
|
66
|
+
else
|
|
67
|
+
(session[:LOCALE] || set_session_locale).to_s
|
|
68
|
+
end
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
body.gsub!(trait[:regex]) do
|
|
71
|
+
localize($1, locale) unless $1.to_s.empty?
|
|
72
|
+
end
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
store(locale, trait[:default_language]) if trait[:collect]
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
body
|
|
77
|
+
end
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
# Localizes a single 'entity'. If a translation in the chosen language is
|
|
80
|
+
# not available, it falls back to the default language.
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
def localize(str, locale)
|
|
83
|
+
default_language = trait[:default_language]
|
|
84
|
+
dict = dictionary
|
|
85
|
+
dict[locale] ||= {}
|
|
86
|
+
dict[default_language] ||= {}
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
trans = dict[locale].fetch(str, dict[default_language][str])
|
|
89
|
+
dict[locale][str] ||= trans
|
|
90
|
+
dict[default_language][str] ||= trans
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
trans
|
|
93
|
+
rescue Object => ex
|
|
94
|
+
Log.error(ex)
|
|
95
|
+
str
|
|
96
|
+
end
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
# Sets session[:LOCALE] to one of the languages defined in the dictionary.
|
|
99
|
+
# It first tries to honor the browsers accepted languages and then falls
|
|
100
|
+
# back to the default language.
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
def set_session_locale
|
|
103
|
+
session[:LOCALE] = trait[:default_language]
|
|
104
|
+
accepted_langs = request.http_accept_language rescue 'en'
|
|
104
105
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
mapping = trait[:mapping]
|
|
107
|
+
dict = dictionary
|
|
108
|
+
accepted_langs = accepted_langs.scan(/([^,;]+)(?:;q=[^,]+)?/m)[0]
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
accepted_langs.each do |language|
|
|
111
|
+
language = mapping[language] || language
|
|
112
|
+
if dict.key?(language)
|
|
113
|
+
session[:LOCALE] = language
|
|
114
|
+
break
|
|
115
|
+
end
|
|
114
116
|
end
|
|
115
|
-
end
|
|
116
117
|
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
session[:LOCALE]
|
|
119
|
+
end
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
# Returns the dictionary used for translation.
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
def dictionary
|
|
124
|
+
trait[:languages].map! {|x| x.to_s }.uniq!
|
|
125
|
+
trait[:dictionary] || load(*trait[:languages])
|
|
126
|
+
end
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
# Load given locales from disk and save it into the dictionary.
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
def load(*locales)
|
|
131
|
+
Log.debug "loading locales: #{locales.inspect}"
|
|
131
132
|
|
|
132
|
-
|
|
133
|
+
dict = trait[:dictionary] || {}
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
locales.each do |locale|
|
|
136
|
+
begin
|
|
137
|
+
dict[locale] = YAML.load_file(trait[:file] % locale)
|
|
138
|
+
rescue Errno::ENOENT
|
|
139
|
+
dict[locale] = {}
|
|
140
|
+
end
|
|
139
141
|
end
|
|
140
|
-
end
|
|
141
142
|
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
trait[:dictionary] = dict
|
|
144
|
+
end
|
|
144
145
|
|
|
145
|
-
|
|
146
|
+
# Stores given locales from the dictionary to disk.
|
|
146
147
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
def store(*locales)
|
|
149
|
+
locales.uniq.compact.each do |locale|
|
|
150
|
+
Log.dev "saving localized to: #{trait[:file] % locale}"
|
|
151
|
+
data = dictionary[locale].ya2yaml
|
|
152
|
+
file = trait[:file] % locale
|
|
153
|
+
File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
|
|
154
|
+
fd.write data
|
|
155
|
+
end
|
|
154
156
|
end
|
|
157
|
+
rescue Errno::ENOENT => e
|
|
158
|
+
Log.error e
|
|
155
159
|
end
|
|
156
|
-
rescue Errno::ENOENT => e
|
|
157
|
-
Ramaze::Inform.error e
|
|
158
160
|
end
|
|
159
161
|
end
|
|
160
162
|
end
|