ramaze 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -259
- data/bin/ramaze +52 -25
- data/doc/AUTHORS +6 -0
- data/doc/CHANGELOG +1363 -42
- data/doc/INSTALL +1 -1
- data/doc/README +48 -35
- data/doc/README.html +637 -0
- data/doc/TODO +7 -16
- data/doc/allison/allison.css +6 -7
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/cache/STYLE +1 -2
- data/doc/changes.txt +3375 -0
- data/doc/changes.xml +3378 -0
- data/doc/meta/announcement.txt +47 -0
- data/doc/meta/configuration.txt +179 -0
- data/doc/meta/internals.txt +111 -0
- data/doc/readme_chunks/features.txt +8 -16
- data/doc/readme_chunks/installing.txt +7 -1
- data/doc/tutorial/todolist.txt +2 -3
- data/examples/blog/main.rb +9 -8
- data/examples/blog/public/styles/blog.css +132 -0
- data/examples/blog/src/controller.rb +14 -41
- data/examples/blog/src/model.rb +12 -13
- data/examples/blog/src/view.rb +16 -0
- data/examples/blog/template/edit.xhtml +19 -8
- data/examples/blog/template/index.xhtml +14 -22
- data/examples/blog/template/new.xhtml +18 -5
- data/examples/caching.rb +5 -8
- data/examples/element.rb +3 -3
- data/examples/hello.rb +3 -5
- data/examples/simple.rb +4 -7
- data/examples/templates/template/external.haml +8 -7
- data/examples/templates/template/external.mab +11 -8
- data/examples/templates/template_amrita2.rb +4 -4
- data/examples/templates/template_erubis.rb +3 -3
- data/examples/templates/template_ezamar.rb +1 -2
- data/examples/templates/template_haml.rb +24 -23
- data/examples/templates/template_liquid.rb +3 -1
- data/examples/templates/template_markaby.rb +15 -9
- data/examples/todolist/src/element/page.rb +1 -1
- data/lib/proto/conf/benchmark.yaml +6 -20
- data/lib/proto/conf/debug.yaml +6 -19
- data/lib/proto/conf/live.yaml +7 -19
- data/lib/proto/conf/silent.yaml +6 -16
- data/lib/proto/conf/stage.yaml +6 -18
- data/lib/proto/public/error.zmr +2 -2
- data/lib/ramaze.rb +34 -72
- data/lib/ramaze/adapter.rb +21 -18
- data/lib/ramaze/adapter/mongrel.rb +0 -3
- data/lib/ramaze/adapter/webrick.rb +6 -6
- data/lib/ramaze/cache/memcached.rb +3 -0
- data/lib/ramaze/controller.rb +227 -183
- data/lib/ramaze/dispatcher.rb +34 -129
- data/lib/ramaze/dispatcher/action.rb +28 -0
- data/lib/ramaze/dispatcher/error.rb +43 -0
- data/lib/ramaze/dispatcher/file.rb +34 -0
- data/lib/ramaze/global.rb +89 -48
- data/lib/ramaze/helper/aspect.rb +8 -6
- data/lib/ramaze/helper/auth.rb +3 -3
- data/lib/ramaze/helper/cache.rb +2 -2
- data/lib/ramaze/helper/file.rb +14 -0
- data/lib/ramaze/helper/inform.rb +36 -0
- data/lib/ramaze/helper/link.rb +7 -3
- data/lib/ramaze/helper/markaby.rb +30 -0
- data/lib/ramaze/helper/redirect.rb +2 -0
- data/lib/ramaze/inform.rb +8 -182
- data/lib/ramaze/inform/analogger.rb +19 -0
- data/lib/ramaze/inform/growl.rb +28 -0
- data/lib/ramaze/inform/hub.rb +26 -0
- data/lib/ramaze/inform/informer.rb +92 -0
- data/lib/ramaze/inform/informing.rb +44 -0
- data/lib/ramaze/inform/syslog.rb +27 -0
- data/lib/ramaze/inform/xosd.rb +42 -0
- data/lib/ramaze/snippets.rb +6 -2
- data/lib/ramaze/snippets/object/traits.rb +13 -1
- data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
- data/lib/ramaze/snippets/string/color.rb +27 -0
- data/lib/ramaze/snippets/string/each.rb +6 -0
- data/lib/ramaze/snippets/struct/fill.rb +15 -0
- data/lib/ramaze/template/ezamar.rb +13 -22
- data/lib/ramaze/template/ezamar/element.rb +12 -12
- data/lib/ramaze/template/liquid.rb +19 -18
- data/lib/ramaze/template/markaby.rb +37 -58
- data/lib/ramaze/tool/localize.rb +128 -0
- data/lib/ramaze/tool/tidy.rb +51 -21
- data/lib/ramaze/trinity.rb +3 -3
- data/lib/ramaze/trinity/request.rb +41 -23
- data/lib/ramaze/trinity/response.rb +10 -5
- data/lib/ramaze/trinity/session.rb +17 -3
- data/lib/ramaze/version.rb +2 -2
- data/rake_tasks/conf.rake +56 -0
- data/rake_tasks/gem.rake +44 -0
- data/rake_tasks/maintaince.rake +187 -0
- data/spec/all.rb +32 -0
- data/spec/examples/caching.rb +19 -0
- data/spec/examples/element.rb +15 -0
- data/spec/examples/hello.rb +11 -0
- data/spec/examples/simple.rb +51 -0
- data/spec/examples/templates/template_amrita2.rb +14 -0
- data/spec/examples/templates/template_erubis.rb +21 -0
- data/spec/examples/templates/template_ezamar.rb +22 -0
- data/spec/examples/templates/template_haml.rb +23 -0
- data/spec/examples/templates/template_liquid.rb +24 -0
- data/spec/examples/templates/template_markaby.rb +21 -0
- data/spec/helper.rb +81 -0
- data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
- data/spec/helper/layout.rb +55 -0
- data/spec/helper/mock_http.rb +66 -0
- data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
- data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
- data/spec/helper/wrap.rb +193 -0
- data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
- data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
- data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
- data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
- data/spec/ramaze/conf/locale_de.yaml +6 -0
- data/spec/ramaze/conf/locale_en.yaml +6 -0
- data/spec/ramaze/controller.rb +184 -0
- data/spec/ramaze/controller/template/greet.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +54 -0
- data/spec/ramaze/dependencies.rb +16 -0
- data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
- data/spec/ramaze/error.rb +64 -0
- data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
- data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
- data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
- data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
- data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
- data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
- data/spec/ramaze/helper/file.rb +17 -0
- data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
- data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
- data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
- data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
- data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
- data/spec/ramaze/inform/informer.rb +40 -0
- data/spec/ramaze/inform/syslog.rb +10 -0
- data/spec/ramaze/localize.rb +40 -0
- data/spec/ramaze/morpher.rb +82 -0
- data/spec/ramaze/params.rb +124 -0
- data/spec/{public → ramaze/public}/error404.xhtml +0 -0
- data/spec/{public → ramaze/public}/favicon.ico +0 -0
- data/spec/{public → ramaze/public}/ramaze.png +0 -0
- data/spec/{public → ramaze/public}/test_download.css +0 -0
- data/spec/ramaze/request.rb +129 -0
- data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
- data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
- data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
- data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
- data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
- data/spec/ramaze/template.rb +86 -0
- data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
- data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
- data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
- data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
- data/spec/ramaze/template/ezamar.rb +62 -0
- data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
- data/spec/ramaze/template/ezamar/nested.zmr +1 -0
- data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
- data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
- data/spec/{template → ramaze/template}/haml/index.haml +0 -0
- data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
- data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
- data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
- data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
- data/spec/ramaze/template/markaby.rb +59 -0
- data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
- data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
- data/spec/ramaze/template/ramaze/external.test +1 -0
- data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
- metadata +145 -81
- data/examples/blog/public/screen.css +0 -106
- data/examples/blog/src/element.rb +0 -58
- data/examples/blog/template/view.xhtml +0 -15
- data/examples/blog/test/tc_entry.rb +0 -18
- data/lib/proto/public/404.jpg +0 -0
- data/spec/request_tc_helper.rb +0 -135
- data/spec/spec_all.rb +0 -118
- data/spec/spec_helper.rb +0 -66
- data/spec/tc_controller.rb +0 -49
- data/spec/tc_dependencies.rb +0 -13
- data/spec/tc_error.rb +0 -43
- data/spec/tc_morpher.rb +0 -88
- data/spec/tc_params.rb +0 -125
- data/spec/tc_template_ezamar.rb +0 -64
- data/spec/tc_template_markaby.rb +0 -72
- data/spec/template/ezamar/nested.zmr +0 -1
@@ -15,7 +15,7 @@
|
|
15
15
|
# %{
|
16
16
|
# <html>
|
17
17
|
# <h1>
|
18
|
-
#
|
18
|
+
# #@title
|
19
19
|
# </h1>
|
20
20
|
# #{content}
|
21
21
|
# </html>
|
@@ -82,10 +82,6 @@ class Ezamar::Element
|
|
82
82
|
# transforms all <Element> tags within the string, takes also
|
83
83
|
# a binding to be compatible to the transform-pipeline, won't have
|
84
84
|
# any use for it though.
|
85
|
-
#
|
86
|
-
# It also sets a instance-variable for you called @hash, which
|
87
|
-
# contains the parameters you gave the <Element> tag.
|
88
|
-
# See above for an example of writing and using them.
|
89
85
|
|
90
86
|
def transform string = '', options = {}
|
91
87
|
binding, path = options.values_at(:binding, :path)
|
@@ -120,8 +116,9 @@ class Ezamar::Element
|
|
120
116
|
end
|
121
117
|
|
122
118
|
# find the element, create an instance, pass it the content
|
123
|
-
# check if it responds to :render and
|
124
|
-
#
|
119
|
+
# check if it responds to :render and sets instance-variables
|
120
|
+
# that are named after the keys and hold the values of the parameters
|
121
|
+
# you passed to the Element
|
125
122
|
#
|
126
123
|
# Parameters look like:
|
127
124
|
# <Page foo="true"> bar </Page>
|
@@ -130,12 +127,13 @@ class Ezamar::Element
|
|
130
127
|
def finish_transform(klass, params, content)
|
131
128
|
instance = constant(klass).new(content)
|
132
129
|
|
133
|
-
|
134
|
-
|
130
|
+
demunge_passed_variables(params).each do |key, value|
|
131
|
+
instance.instance_variable_set("@#{key}", value)
|
132
|
+
end
|
135
133
|
|
136
134
|
instance.render
|
137
135
|
rescue => ex
|
138
|
-
Ramaze::
|
136
|
+
Ramaze::Inform.debug(ex.message)
|
139
137
|
''
|
140
138
|
end
|
141
139
|
|
@@ -154,8 +152,10 @@ class Ezamar::Element
|
|
154
152
|
string.scan(/\s?(.*?)="(.*?)"/).inject({}) do |hash, (key, value)|
|
155
153
|
value =
|
156
154
|
case value
|
157
|
-
when 'true'
|
158
|
-
|
155
|
+
when 'true'
|
156
|
+
true
|
157
|
+
when 'false'
|
158
|
+
false
|
159
159
|
else
|
160
160
|
Integer(value) rescue Float(value) rescue value
|
161
161
|
end
|
@@ -3,31 +3,32 @@
|
|
3
3
|
|
4
4
|
require 'liquid'
|
5
5
|
|
6
|
-
module Ramaze
|
7
|
-
|
6
|
+
module Ramaze
|
7
|
+
module Template
|
8
|
+
class Liquid < Template
|
9
|
+
Controller.register_engine self, %w[ liquid ]
|
8
10
|
|
9
|
-
|
11
|
+
class << self
|
10
12
|
|
11
|
-
|
13
|
+
# initializes the handling of a request on the controller.
|
14
|
+
# Creates a new instances of itself and sends the action and params.
|
15
|
+
# Also tries to render the template.
|
16
|
+
# In Theory you can use this standalone, this has not been tested though.
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
# Also tries to render the template.
|
16
|
-
# In Theory you can use this standalone, this has not been tested though.
|
18
|
+
def transform controller, options = {}
|
19
|
+
action, parameter, file, bound = *super
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
reaction = controller.send(action, *parameter)
|
22
|
+
template = reaction_or_file(reaction, file)
|
20
23
|
|
21
|
-
|
22
|
-
template = reaction_or_file(reaction, file)
|
24
|
+
return '' unless template
|
23
25
|
|
24
|
-
|
26
|
+
hash = controller.instance_variable_get("@hash") || {}
|
27
|
+
template = ::Liquid::Template.parse(template)
|
28
|
+
options = controller.ancestral_trait[:liquid_options]
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
options = controller.ancestral_trait[:liquid_options]
|
29
|
-
|
30
|
-
template.render(hash, options)
|
30
|
+
template.render(hash, options)
|
31
|
+
end
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -3,68 +3,47 @@
|
|
3
3
|
|
4
4
|
require 'markaby'
|
5
5
|
|
6
|
-
module Ramaze
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
6
|
+
module Ramaze
|
7
|
+
module Template
|
8
|
+
class Markaby < Template
|
9
|
+
Controller.register_engine self, %w[ mab ]
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
# initializes the handling of a request on the controller.
|
14
|
+
# Creates a new instances of itself and sends the action and params.
|
15
|
+
# Also tries to render the template.
|
16
|
+
# In Theory you can use this standalone, this has not been tested though.
|
17
|
+
|
18
|
+
def transform controller, options = {}
|
19
|
+
action, parameter, file, bound = *super
|
20
|
+
|
21
|
+
unless controller.private_methods.include?(action)
|
22
|
+
reaction = controller.__send__(action, *parameter)
|
23
|
+
template =
|
24
|
+
if file
|
25
|
+
transform_file(controller, file)
|
26
|
+
elsif reaction.respond_to?(:to_str)
|
27
|
+
reaction
|
28
|
+
end
|
29
|
+
return template if template
|
30
|
+
end
|
31
|
+
|
32
|
+
raise Error::NoAction, "No Action found for `#{action}' on #{controller.class}"
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
instance_eval(File.read(file))
|
35
|
+
def transform_file controller, file
|
36
|
+
ivs = {}
|
37
|
+
controller.instance_variables.each do |iv|
|
38
|
+
ivs[iv.gsub('@', '').to_sym] = controller.instance_variable_get(iv)
|
39
|
+
end
|
40
|
+
controller.send(:mab, ivs) do
|
41
|
+
instance_eval(File.read(file))
|
42
|
+
end
|
43
|
+
rescue Object => ex
|
44
|
+
raise Error::Template, ex.message, ex.backtrace
|
46
45
|
end
|
47
|
-
rescue Object => ex
|
48
|
-
puts ex
|
49
|
-
raise Ramaze::Error::Template, ex.message, ex.backtrace
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
53
|
-
|
54
|
-
module MarkabyMixin
|
55
|
-
private
|
56
|
-
|
57
|
-
# use this inside your controller to directly build Markaby
|
58
|
-
# Refer to the Markaby-documentation and testsuite for more examples.
|
59
|
-
# Usage:
|
60
|
-
# mab { h1 "Apples & Oranges"} #=> "<h1>Apples & Oranges</h1>"
|
61
|
-
# mab { h1 'Apples', :class => 'fruits&floots' } #=> "<h1 class=\"fruits&floots\">Apples</h1>"
|
62
|
-
|
63
|
-
def mab(*args, &block)
|
64
|
-
builder = ::Markaby::Builder
|
65
|
-
builder.extend(Ramaze::Helper)
|
66
|
-
builder.send(:helper, :link)
|
67
|
-
builder.new(*args, &block).to_s
|
68
|
-
end
|
69
|
-
end
|
70
49
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
$KCODE = 'UTF-8'
|
5
|
+
require 'ya2yaml'
|
6
|
+
|
7
|
+
class Ramaze::Tool::Localize
|
8
|
+
|
9
|
+
# Enable Localization
|
10
|
+
trait :enable => true
|
11
|
+
|
12
|
+
# Default language that is used if the browser don't suggests otherwise or
|
13
|
+
# the language requested is not available.
|
14
|
+
trait :default_language => 'en'
|
15
|
+
|
16
|
+
# languages supported
|
17
|
+
trait :languages => %w[ en ]
|
18
|
+
|
19
|
+
# YAML files the localizations are saved to and loaded from, %s is substituded
|
20
|
+
# by the values from trait[:languages]
|
21
|
+
trait :file => 'conf/locale_%s.yaml'.freeze
|
22
|
+
|
23
|
+
# The pattern that is substituted with the translation of the current locale.
|
24
|
+
trait :regex => /\[\[(.*?)\]\]/
|
25
|
+
|
26
|
+
# Browsers may send different keys for the same language, this allows you to
|
27
|
+
# do some coercion between what you use as keys and what the browser sends.
|
28
|
+
trait :mapping => { 'en-us' => 'en', 'ja' => 'jp'}
|
29
|
+
|
30
|
+
class << self
|
31
|
+
|
32
|
+
include Ramaze::Trinity
|
33
|
+
|
34
|
+
def call(response, options = {})
|
35
|
+
return response unless trait[:enable]
|
36
|
+
return response if response.body.nil?
|
37
|
+
return response if response.body.respond_to?(:read)
|
38
|
+
response.body = localize_body(response.body, options)
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
def localize_body(body, options)
|
43
|
+
locale = session[:LOCALE] || set_session_locale
|
44
|
+
|
45
|
+
body.gsub!(trait[:regex]) do
|
46
|
+
localize($1, locale)
|
47
|
+
end
|
48
|
+
|
49
|
+
store(locale, trait[:default_language])
|
50
|
+
|
51
|
+
body
|
52
|
+
end
|
53
|
+
|
54
|
+
def localize(str, locale)
|
55
|
+
Ramaze::Inform.debug "localizing: #{locale} => '#{str}'"
|
56
|
+
|
57
|
+
trans = nil
|
58
|
+
default_language = trait[:default_language]
|
59
|
+
dict = dictionary
|
60
|
+
|
61
|
+
if dict[locale] && trans = dict[locale][str]
|
62
|
+
#
|
63
|
+
elsif trans = dict[default_language][str]
|
64
|
+
dict[locale][str] = str
|
65
|
+
else
|
66
|
+
dict[locale][str] = str
|
67
|
+
dict[default_language][str] = str
|
68
|
+
end
|
69
|
+
|
70
|
+
trans || str
|
71
|
+
rescue Object => ex
|
72
|
+
Ramaze::Inform.error(ex)
|
73
|
+
str
|
74
|
+
end
|
75
|
+
|
76
|
+
def set_session_locale
|
77
|
+
session[:LOCALE] = trait[:default_language]
|
78
|
+
accepted_langs = request.http_accept_language rescue 'en'
|
79
|
+
|
80
|
+
mapping = trait[:mapping]
|
81
|
+
dict = dictionary
|
82
|
+
accepted_langs = accepted_langs.scan(/([^,;]+)(?:;q=[^,]+)?/m)[0]
|
83
|
+
|
84
|
+
accepted_langs.each do |language|
|
85
|
+
language = mapping[language] || language
|
86
|
+
if dict.key?(language)
|
87
|
+
session[:LOCALE] = language
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
session[:LOCALE]
|
93
|
+
end # end set_session_locale
|
94
|
+
|
95
|
+
def dictionary
|
96
|
+
trait[:dictionary] || load(*trait[:languages])
|
97
|
+
end
|
98
|
+
|
99
|
+
def load(*locales)
|
100
|
+
Ramaze::Inform.debug "loading locales: #{locales.inspect}"
|
101
|
+
|
102
|
+
dict = trait[:dictionary] || {}
|
103
|
+
|
104
|
+
locales.each do |locale|
|
105
|
+
begin
|
106
|
+
dict[locale] = YAML.load_file(trait[:file] % locale)
|
107
|
+
rescue Errno::ENOENT
|
108
|
+
dict[locale] = {}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
trait[:dictionary] = dict
|
113
|
+
end
|
114
|
+
|
115
|
+
def store(*locales)
|
116
|
+
locales.uniq.compact.each do |locale|
|
117
|
+
Ramaze::Inform.debug "saving localized to: #{trait[:file] % locale}"
|
118
|
+
data = dictionary[locale].ya2yaml
|
119
|
+
file = trait[:file] % locale
|
120
|
+
File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
|
121
|
+
fd.write data
|
122
|
+
end
|
123
|
+
end
|
124
|
+
rescue Errno::ENOENT
|
125
|
+
# bleargh
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/ramaze/tool/tidy.rb
CHANGED
@@ -9,8 +9,25 @@ module Ramaze
|
|
9
9
|
|
10
10
|
module Tidy
|
11
11
|
|
12
|
+
trait[:enable] ||= false
|
13
|
+
|
12
14
|
# set this to define a custom path to your tidy.so
|
13
|
-
trait[:
|
15
|
+
trait[:paths] ||= %w[
|
16
|
+
/usr/lib/libtidy.so
|
17
|
+
/usr/local/lib/libtidy.so
|
18
|
+
]
|
19
|
+
|
20
|
+
trait[:path] ||= nil
|
21
|
+
|
22
|
+
trait[:options] ||= {
|
23
|
+
:output_xml => true,
|
24
|
+
:input_encoding => :utf8,
|
25
|
+
:output_encoding => :utf8,
|
26
|
+
:indent_spaces => 2,
|
27
|
+
:indent => :auto,
|
28
|
+
:markup => :yes,
|
29
|
+
:wrap => 500
|
30
|
+
}
|
14
31
|
|
15
32
|
# dirty html in, tidy html out
|
16
33
|
# To activate Tidy for everything outgoing (given that it is of
|
@@ -34,31 +51,44 @@ module Ramaze
|
|
34
51
|
# <body></body>
|
35
52
|
# </html>
|
36
53
|
|
37
|
-
|
38
|
-
|
54
|
+
class << self
|
55
|
+
def tidy html, options = {}
|
56
|
+
require 'tidy'
|
39
57
|
|
40
|
-
|
58
|
+
unless found = trait[:path]
|
59
|
+
found = trait[:paths].find do |path|
|
60
|
+
File.exists?(path)
|
61
|
+
end
|
62
|
+
trait[:path] = found
|
63
|
+
end
|
41
64
|
|
42
|
-
|
43
|
-
:output_xml => true,
|
44
|
-
:input_encoding => :utf8,
|
45
|
-
:output_encoding => :utf8,
|
46
|
-
:indent_spaces => 2,
|
47
|
-
:indent => :auto,
|
48
|
-
:markup => :yes,
|
49
|
-
:wrap => 500
|
50
|
-
}
|
65
|
+
path = trait[:path]
|
51
66
|
|
52
|
-
|
53
|
-
|
54
|
-
|
67
|
+
unless path
|
68
|
+
Inform.error("Could not find `libtidy.so' in #{trait[:paths].inspect}")
|
69
|
+
return html
|
55
70
|
end
|
56
|
-
|
71
|
+
|
72
|
+
::Tidy.path = path
|
73
|
+
|
74
|
+
::Tidy.open(:show_warnings => true) do |tidy|
|
75
|
+
opts = trait[:options].merge(options)
|
76
|
+
opts.each do |key, value|
|
77
|
+
tidy.options.send("#{key}=", value.to_s)
|
78
|
+
end
|
79
|
+
tidy.clean(html)
|
80
|
+
end
|
81
|
+
rescue LoadError => ex
|
82
|
+
puts ex
|
83
|
+
puts "cannot load 'tidy', please `gem install tidy`"
|
84
|
+
puts "you can find it at http://tidy.rubyforge.org/"
|
85
|
+
end
|
86
|
+
|
87
|
+
def call(response, options = {})
|
88
|
+
return response unless trait[:enable]
|
89
|
+
response.body = tidy(response.body, options)
|
90
|
+
response
|
57
91
|
end
|
58
|
-
rescue LoadError => ex
|
59
|
-
puts ex
|
60
|
-
puts "cannot load 'tidy', please `gem install tidy`"
|
61
|
-
puts "you can find it at http://tidy.rubyforge.org/"
|
62
92
|
end
|
63
93
|
|
64
94
|
# calls self#tidy
|
data/lib/ramaze/trinity.rb
CHANGED
@@ -18,21 +18,21 @@ module Ramaze
|
|
18
18
|
# Thread.current[:request]
|
19
19
|
|
20
20
|
def request
|
21
|
-
|
21
|
+
Request.current
|
22
22
|
end
|
23
23
|
|
24
24
|
# same as
|
25
25
|
# Thread.current[:response]
|
26
26
|
|
27
27
|
def response
|
28
|
-
|
28
|
+
Response.current
|
29
29
|
end
|
30
30
|
|
31
31
|
# same as
|
32
32
|
# Thread.current[:session]
|
33
33
|
|
34
34
|
def session
|
35
|
-
|
35
|
+
Session.current
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|