ramaze 0.1.0 → 0.1.1
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 +4 -12
- data/bin/ramaze +95 -171
- data/doc/CHANGELOG +387 -4
- data/doc/README +81 -13
- data/doc/meta/announcement.txt +51 -8
- data/doc/meta/configuration.txt +17 -34
- data/doc/meta/internals.txt +34 -4
- data/doc/migrate/1110_to_1111.txt +131 -0
- data/doc/readme_chunks/features.txt +81 -12
- data/doc/readme_chunks/installing.txt +0 -1
- data/doc/tutorial/todolist.html +293 -65
- data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
- data/examples/blog/main.rb +1 -1
- data/examples/blog/src/model.rb +0 -1
- data/examples/hello.rb +2 -5
- data/examples/templates/template/external.haml +5 -5
- data/examples/templates/template/external.liquid +1 -1
- data/examples/templates/template/external.mab +8 -8
- data/examples/templates/template/external.rem +30 -0
- data/examples/templates/template/external.rhtml +6 -7
- data/examples/templates/template/external.zmr +13 -9
- data/examples/templates/template_amrita2.rb +8 -8
- data/examples/templates/template_erubis.rb +11 -11
- data/examples/templates/template_ezamar.rb +9 -11
- data/examples/templates/template_haml.rb +13 -13
- data/examples/templates/template_liquid.rb +10 -10
- data/examples/templates/template_markaby.rb +13 -10
- data/examples/templates/template_remarkably.rb +59 -0
- data/examples/todolist/main.rb +1 -7
- data/examples/todolist/src/controller/main.rb +26 -13
- data/examples/todolist/src/element/page.rb +5 -0
- data/examples/whywiki/main.rb +1 -1
- data/lib/proto/main.rb +0 -8
- data/lib/proto/public/css/ramaze_error.css +12 -4
- data/lib/proto/public/error.zmr +6 -25
- data/lib/ramaze.rb +35 -245
- data/lib/ramaze/action.rb +21 -0
- data/lib/ramaze/adapter.rb +94 -29
- data/lib/ramaze/adapter/base.rb +57 -0
- data/lib/ramaze/adapter/mongrel.rb +12 -19
- data/lib/ramaze/adapter/webrick.rb +21 -20
- data/lib/ramaze/cache.rb +47 -3
- data/lib/ramaze/cache/memcached.rb +22 -0
- data/lib/ramaze/cache/yaml_store.rb +19 -0
- data/lib/ramaze/controller.rb +47 -271
- data/lib/ramaze/controller/error.rb +43 -0
- data/lib/ramaze/controller/render.rb +90 -0
- data/lib/ramaze/controller/resolve.rb +147 -0
- data/lib/ramaze/dispatcher.rb +41 -9
- data/lib/ramaze/dispatcher/file.rb +1 -1
- data/lib/ramaze/global.rb +73 -158
- data/lib/ramaze/global/dsl.rb +29 -0
- data/lib/ramaze/global/globalstruct.rb +90 -0
- data/lib/ramaze/helper.rb +1 -1
- data/lib/ramaze/helper/aspect.rb +39 -179
- data/lib/ramaze/helper/cache.rb +8 -9
- data/lib/ramaze/helper/cgi.rb +23 -0
- data/lib/ramaze/helper/file.rb +3 -0
- data/lib/ramaze/helper/inform.rb +3 -0
- data/lib/ramaze/helper/link.rb +56 -63
- data/lib/ramaze/helper/nitroform.rb +4 -0
- data/lib/ramaze/helper/redirect.rb +1 -1
- data/lib/ramaze/inform.rb +6 -2
- data/lib/ramaze/inform/analogger.rb +5 -1
- data/lib/ramaze/inform/hub.rb +1 -1
- data/lib/ramaze/inform/informing.rb +7 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
- data/lib/ramaze/snippets/kernel/constant.rb +2 -0
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
- data/lib/ramaze/snippets/object/traits.rb +4 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
- data/lib/ramaze/snippets/string/camel_case.rb +2 -0
- data/lib/ramaze/snippets/string/color.rb +2 -0
- data/lib/ramaze/snippets/string/each.rb +2 -0
- data/lib/ramaze/snippets/string/snake_case.rb +3 -0
- data/lib/ramaze/snippets/struct/fill.rb +8 -2
- data/lib/ramaze/snippets/struct/values_at.rb +16 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
- data/lib/ramaze/sourcereload.rb +89 -0
- data/lib/ramaze/template.rb +21 -12
- data/lib/ramaze/template/amrita2.rb +6 -6
- data/lib/ramaze/template/erubis.rb +4 -9
- data/lib/ramaze/template/ezamar.rb +13 -57
- data/lib/ramaze/template/ezamar/element.rb +10 -12
- data/lib/ramaze/template/ezamar/engine.rb +40 -101
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/haml.rb +3 -6
- data/lib/ramaze/template/liquid.rb +4 -9
- data/lib/ramaze/template/markaby.rb +16 -22
- data/lib/ramaze/template/remarkably.rb +28 -0
- data/lib/ramaze/tool/mime.rb +2 -0
- data/lib/ramaze/tool/record.rb +6 -0
- data/lib/ramaze/trinity/request.rb +44 -54
- data/lib/ramaze/trinity/response.rb +1 -1
- data/lib/ramaze/trinity/session.rb +15 -37
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/gem.rake +2 -2
- data/rake_tasks/maintaince.rake +42 -1
- data/rake_tasks/spec.rake +45 -0
- data/spec/examples/caching.rb +1 -1
- data/spec/examples/simple.rb +1 -1
- data/spec/examples/templates/template_amrita2.rb +1 -0
- data/spec/examples/templates/template_erubis.rb +2 -1
- data/spec/examples/templates/template_ezamar.rb +1 -1
- data/spec/examples/templates/template_haml.rb +2 -1
- data/spec/examples/templates/template_liquid.rb +2 -1
- data/spec/examples/templates/template_markaby.rb +2 -1
- data/spec/examples/templates/template_remarkably.rb +22 -0
- data/spec/examples/todolist.rb +125 -0
- data/spec/helper.rb +2 -23
- data/spec/helper/minimal.rb +20 -0
- data/spec/helper/mock_http.rb +24 -30
- data/spec/helper/simple_http.rb +2 -2
- data/spec/helper/wrap.rb +6 -9
- data/spec/ramaze/adapter.rb +1 -1
- data/spec/ramaze/adapter/record.rb +31 -0
- data/spec/ramaze/cache.rb +41 -54
- data/spec/ramaze/controller.rb +121 -137
- data/spec/ramaze/controller/template/list.xhtml +1 -0
- data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +27 -3
- data/spec/ramaze/element.rb +11 -7
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/gestalt.rb +2 -0
- data/spec/ramaze/helper/aspect.rb +30 -21
- data/spec/ramaze/helper/auth.rb +1 -1
- data/spec/ramaze/helper/cache.rb +2 -1
- data/spec/ramaze/helper/form.rb +14 -11
- data/spec/ramaze/helper/link.rb +18 -41
- data/spec/ramaze/localize.rb +29 -2
- data/spec/ramaze/morpher.rb +23 -12
- data/spec/ramaze/params.rb +46 -24
- data/spec/ramaze/request.rb +6 -2
- data/spec/ramaze/store/yaml.rb +5 -0
- data/spec/ramaze/template.rb +22 -27
- data/spec/ramaze/template/amrita2.rb +1 -2
- data/spec/ramaze/template/erubis.rb +1 -1
- data/spec/ramaze/template/ezamar.rb +1 -2
- data/spec/ramaze/template/haml.rb +2 -2
- data/spec/ramaze/template/haml/with_vars.haml +1 -1
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/remarkably.rb +56 -0
- data/spec/ramaze/template/remarkably/external.rem +8 -0
- data/spec/ramaze/template/remarkably/sum.rem +1 -0
- metadata +38 -63
- data/doc/README.html +0 -637
- data/doc/allison/LICENSE +0 -184
- data/doc/allison/README +0 -37
- data/doc/allison/allison.css +0 -299
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +0 -307
- data/doc/allison/allison.rb +0 -287
- data/doc/allison/cache/BODY +0 -588
- data/doc/allison/cache/CLASS_INDEX +0 -4
- data/doc/allison/cache/CLASS_PAGE +0 -1
- data/doc/allison/cache/FILE_INDEX +0 -4
- data/doc/allison/cache/FILE_PAGE +0 -1
- data/doc/allison/cache/FONTS +0 -1
- data/doc/allison/cache/FR_INDEX_BODY +0 -1
- data/doc/allison/cache/IMGPATH +0 -1
- data/doc/allison/cache/INDEX +0 -1
- data/doc/allison/cache/JAVASCRIPT +0 -307
- data/doc/allison/cache/METHOD_INDEX +0 -4
- data/doc/allison/cache/METHOD_LIST +0 -1
- data/doc/allison/cache/SRC_PAGE +0 -1
- data/doc/allison/cache/STYLE +0 -321
- data/doc/allison/cache/URL +0 -1
- data/doc/changes.txt +0 -3375
- data/doc/changes.xml +0 -3378
- data/examples/todolist/conf/benchmark.yaml +0 -35
- data/examples/todolist/conf/debug.yaml +0 -34
- data/examples/todolist/conf/live.yaml +0 -33
- data/examples/todolist/conf/silent.yaml +0 -31
- data/examples/todolist/conf/stage.yaml +0 -33
- data/examples/todolist/public/css/coderay.css +0 -105
- data/examples/todolist/public/css/ramaze_error.css +0 -42
- data/lib/proto/conf/benchmark.yaml +0 -21
- data/lib/proto/conf/debug.yaml +0 -21
- data/lib/proto/conf/live.yaml +0 -21
- data/lib/proto/conf/silent.yaml +0 -21
- data/lib/proto/conf/stage.yaml +0 -21
- data/lib/proto/public/css/coderay.css +0 -105
- data/lib/ramaze/http_status.rb +0 -66
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
- data/lib/ramaze/snippets/kernel/method.rb +0 -26
- data/lib/ramaze/snippets/method/name.rb +0 -22
- data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
- data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
- data/spec/all.rb +0 -32
- data/spec/ramaze/conf/locale_de.yaml +0 -6
- data/spec/ramaze/conf/locale_en.yaml +0 -6
- data/spec/ramaze/dependencies.rb +0 -16
- data/spec/ramaze/global.rb +0 -44
data/lib/ramaze/template.rb
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
|
3
3
|
|
|
4
4
|
# This module serves as a namespace for all templates, it will autoload
|
|
5
|
-
# Amrita2, Erubis,
|
|
5
|
+
# Amrita2, Erubis, Haml, Liquid and Markaby if you refer to them.
|
|
6
6
|
|
|
7
7
|
module Ramaze
|
|
8
8
|
module Template
|
|
9
9
|
|
|
10
|
-
%w[ Amrita2 Erubis Haml Liquid Markaby ].each do |const|
|
|
10
|
+
%w[ Amrita2 Erubis Haml Liquid Markaby Remarkably ].each do |const|
|
|
11
11
|
autoload(const, "ramaze/template/#{const.downcase}")
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -21,21 +21,30 @@ module Ramaze
|
|
|
21
21
|
|
|
22
22
|
# pass it the results of the method of the controller
|
|
23
23
|
# and a possible file, it will see if the file is an actual file
|
|
24
|
-
# and otherwise answer the contents of the response from the controller
|
|
25
|
-
# if it responds to :to_str.
|
|
26
|
-
#
|
|
27
|
-
# Answers nil if none of both is valid.
|
|
28
24
|
|
|
29
|
-
def reaction_or_file
|
|
30
|
-
|
|
25
|
+
def reaction_or_file action
|
|
26
|
+
reaction = render_method(action)
|
|
27
|
+
|
|
28
|
+
if file = action.template
|
|
31
29
|
File.read(file)
|
|
32
|
-
|
|
33
|
-
reaction
|
|
30
|
+
else
|
|
31
|
+
reaction.to_s
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def result_and_file(action)
|
|
36
|
+
result = render_method(action)
|
|
37
|
+
|
|
38
|
+
if file = action.template
|
|
39
|
+
content = File.read(file)
|
|
34
40
|
end
|
|
41
|
+
|
|
42
|
+
[result, content]
|
|
35
43
|
end
|
|
36
44
|
|
|
37
|
-
def
|
|
38
|
-
|
|
45
|
+
def render_method(action)
|
|
46
|
+
return unless method = action.method
|
|
47
|
+
action.controller.__send__(method, *action.params)
|
|
39
48
|
end
|
|
40
49
|
end
|
|
41
50
|
end
|
|
@@ -13,20 +13,20 @@ module Ramaze::Template
|
|
|
13
13
|
|
|
14
14
|
class << self
|
|
15
15
|
|
|
16
|
-
# Takes
|
|
16
|
+
# Takes an Action
|
|
17
17
|
# The file is rendered using Amrita2::TemplateFile.
|
|
18
18
|
# The Controller is used as the object for expansion.
|
|
19
19
|
#
|
|
20
20
|
# The parameters are set to @params in the controller before expansion.
|
|
21
21
|
|
|
22
|
-
def transform
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
def transform action
|
|
23
|
+
controller, params, file =
|
|
24
|
+
action.controller, action.params, action.template
|
|
25
|
+
raise_no_action(action) unless file
|
|
26
26
|
|
|
27
27
|
template = ::Amrita2::TemplateFile.new(file)
|
|
28
28
|
out = ''
|
|
29
|
-
controller.instance_variable_set('@params',
|
|
29
|
+
controller.instance_variable_set('@params', params)
|
|
30
30
|
template.expand(out, controller)
|
|
31
31
|
out
|
|
32
32
|
end
|
|
@@ -18,17 +18,12 @@ module Ramaze::Template
|
|
|
18
18
|
# Builds a template out of the method on the controller and the
|
|
19
19
|
# template-file.
|
|
20
20
|
|
|
21
|
-
def transform
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
reaction = controller.send(action, *parameter)
|
|
25
|
-
template = reaction_or_file(reaction, file)
|
|
26
|
-
|
|
27
|
-
return '' unless template
|
|
21
|
+
def transform action
|
|
22
|
+
template = reaction_or_file(action)
|
|
28
23
|
|
|
29
24
|
eruby = ::Erubis::Eruby.new(template)
|
|
30
|
-
eruby.init_evaluator(:filename =>
|
|
31
|
-
eruby.result(
|
|
25
|
+
eruby.init_evaluator(:filename => (action.template || __FILE__))
|
|
26
|
+
eruby.result(action.binding)
|
|
32
27
|
end
|
|
33
28
|
end
|
|
34
29
|
end
|
|
@@ -12,7 +12,10 @@ module Ramaze
|
|
|
12
12
|
|
|
13
13
|
Ramaze::Controller.register_engine self, %w[ xhtml zmr ]
|
|
14
14
|
|
|
15
|
-
trait :transform_pipeline => [
|
|
15
|
+
trait :transform_pipeline => [
|
|
16
|
+
::Ezamar::Element, ::Ezamar::Template
|
|
17
|
+
]
|
|
18
|
+
|
|
16
19
|
trait :actionless => true
|
|
17
20
|
|
|
18
21
|
class << self
|
|
@@ -21,55 +24,10 @@ module Ramaze
|
|
|
21
24
|
#
|
|
22
25
|
# Uses Ezamar::Template to compile the template.
|
|
23
26
|
|
|
24
|
-
def transform
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else
|
|
29
|
-
action, parameter, file, bound = *super
|
|
30
|
-
|
|
31
|
-
real_transform controller, bound, file, action, *parameter
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# The actual transformation is done here.
|
|
36
|
-
#
|
|
37
|
-
# Getting the various possible template-files and the response from
|
|
38
|
-
# the controller and then deciding based on them what goes into the
|
|
39
|
-
# #pipeline
|
|
40
|
-
|
|
41
|
-
def real_transform(controller, bound, file, action, *params)
|
|
42
|
-
file_template = file_template(file)
|
|
43
|
-
ctrl_template = render_action(controller, action, *params)
|
|
44
|
-
|
|
45
|
-
if ctrl_template.respond_to?(:exception) and not file_template
|
|
46
|
-
raise ctrl_template
|
|
47
|
-
else
|
|
48
|
-
template = file_template || ctrl_template
|
|
49
|
-
pipeline(template, :binding => bound, :path => file)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# See if a string is an actual file.
|
|
54
|
-
#
|
|
55
|
-
# Answers with the contents and otherwise nil
|
|
56
|
-
|
|
57
|
-
def file_template file
|
|
58
|
-
return File.read(file) if file
|
|
59
|
-
rescue Errno::ENOENT => ex
|
|
60
|
-
Inform.error(ex)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Render an action, on a given controller with parameter
|
|
64
|
-
|
|
65
|
-
def render_action(controller, action, *params)
|
|
66
|
-
controller.__send__(action, *params).to_s unless action.empty?
|
|
67
|
-
rescue => ex
|
|
68
|
-
ex
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def raise_no_action(controller, action)
|
|
72
|
-
raise Ramaze::Error::NoAction, "No Action found for `#{action}' on #{controller.class}"
|
|
27
|
+
def transform action
|
|
28
|
+
template = reaction_or_file(action)
|
|
29
|
+
file = (action.template || __FILE__)
|
|
30
|
+
pipeline(template.to_s, action.binding, file)
|
|
73
31
|
end
|
|
74
32
|
|
|
75
33
|
# go through the pipeline and call #transform on every object found there,
|
|
@@ -81,14 +39,12 @@ module Ramaze
|
|
|
81
39
|
# TODO
|
|
82
40
|
# - put the pipeline into the Controller for use with all templates.
|
|
83
41
|
|
|
84
|
-
def pipeline(template,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
opts[:pipeline] = :true
|
|
88
|
-
|
|
89
|
-
transform_pipeline.inject(template) do |memo, current|
|
|
90
|
-
current.transform(memo, opts)
|
|
42
|
+
def pipeline(template, binding, file)
|
|
43
|
+
class_trait[:transform_pipeline].each do |klass|
|
|
44
|
+
template = klass.transform(template, binding, file)
|
|
91
45
|
end
|
|
46
|
+
|
|
47
|
+
template
|
|
92
48
|
end
|
|
93
49
|
end
|
|
94
50
|
end
|
|
@@ -83,23 +83,21 @@ class Ezamar::Element
|
|
|
83
83
|
# a binding to be compatible to the transform-pipeline, won't have
|
|
84
84
|
# any use for it though.
|
|
85
85
|
|
|
86
|
-
def transform
|
|
87
|
-
|
|
88
|
-
string = string.to_s
|
|
89
|
-
matches = string.scan(/<([A-Z][a-zA-Z0-9]*)(.*?)?>/)
|
|
86
|
+
def transform template, binding, file = __FILE__
|
|
87
|
+
matches = template.scan(/<([A-Z][a-zA-Z0-9]*)(.*?)?>/)
|
|
90
88
|
|
|
91
89
|
matches.each do |(klass, params)|
|
|
92
90
|
transformer = (params[-1,1] == '/' ? :without : :with)
|
|
93
|
-
|
|
91
|
+
template = send("transform_#{transformer}_content", template, klass)
|
|
94
92
|
end
|
|
95
|
-
|
|
93
|
+
template
|
|
96
94
|
end
|
|
97
95
|
|
|
98
96
|
# transforms elements like:
|
|
99
97
|
# <Page> some content </Page>
|
|
100
98
|
|
|
101
|
-
def transform_with_content(
|
|
102
|
-
|
|
99
|
+
def transform_with_content(template, klass)
|
|
100
|
+
template.gsub(/<#{klass}( .*?)?>(.*?)<\/#{klass}>/m) do |m|
|
|
103
101
|
params, content = $1.to_s, $2.to_s
|
|
104
102
|
finish_transform(klass, params, content)
|
|
105
103
|
end
|
|
@@ -108,8 +106,8 @@ class Ezamar::Element
|
|
|
108
106
|
# transforms elements like:
|
|
109
107
|
# <Page />
|
|
110
108
|
|
|
111
|
-
def transform_without_content(
|
|
112
|
-
|
|
109
|
+
def transform_without_content(template, klass)
|
|
110
|
+
template.gsub(/<#{klass}( .*?)?\/>/) do |m|
|
|
113
111
|
params = $1.to_s
|
|
114
112
|
finish_transform(klass, params, content = '')
|
|
115
113
|
end
|
|
@@ -148,8 +146,8 @@ class Ezamar::Element
|
|
|
148
146
|
#
|
|
149
147
|
# Just remember, walk like a duck, talk like a duck.
|
|
150
148
|
|
|
151
|
-
def demunge_passed_variables(
|
|
152
|
-
|
|
149
|
+
def demunge_passed_variables(template)
|
|
150
|
+
template.scan(/\s?(.*?)="(.*?)"/).inject({}) do |hash, (key, value)|
|
|
153
151
|
value =
|
|
154
152
|
case value
|
|
155
153
|
when 'true'
|
|
@@ -17,108 +17,47 @@ module Ezamar
|
|
|
17
17
|
# This class is responsible for initializing and compiling the template.
|
|
18
18
|
|
|
19
19
|
class Template
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# class Controller
|
|
61
|
-
# def hello
|
|
62
|
-
# @hello = 'Hello, World!'
|
|
63
|
-
# end
|
|
64
|
-
# end
|
|
65
|
-
#
|
|
66
|
-
# controller = Controller.new
|
|
67
|
-
# controller.hello
|
|
68
|
-
# binding = controller.send(:binding)
|
|
69
|
-
#
|
|
70
|
-
# Ezamar.new('#{@hello}').transform(binding)
|
|
71
|
-
|
|
72
|
-
def transform(_binding_ = @binding)
|
|
73
|
-
@compiled = compile if old?
|
|
74
|
-
|
|
75
|
-
args = @file ? [@file] : []
|
|
76
|
-
|
|
77
|
-
@last_result = eval(@compiled, _binding_, *args)
|
|
78
|
-
|
|
79
|
-
@last_result.map! do |line|
|
|
80
|
-
line.to_s.chomp
|
|
20
|
+
class << self
|
|
21
|
+
|
|
22
|
+
# All ye who seek magic, look elsewhere, this method is ASAP (as simple as possible)
|
|
23
|
+
#
|
|
24
|
+
# There are some simple gsubs that build a final template which is evaluated
|
|
25
|
+
#
|
|
26
|
+
# The rules are following:
|
|
27
|
+
# <?r rubycode ?>
|
|
28
|
+
# evaluate the code inside the tag, this is considered XHTML-valid and so is the
|
|
29
|
+
# preferred method for executing code inside your templates.
|
|
30
|
+
# The return-value is ignored
|
|
31
|
+
# <% rubycode %>
|
|
32
|
+
# The same as <?r ?>, ERB-style and not valid XHTML, but should give someone who
|
|
33
|
+
# is already familiar with ERB some common ground
|
|
34
|
+
# #{ rubycode }
|
|
35
|
+
# You know this from normal ruby already and it's actually nothing else.
|
|
36
|
+
# Interpolation at the position in the template, isn't any special taggy format
|
|
37
|
+
# and therefor safe to use.
|
|
38
|
+
# <%= rubycode %>
|
|
39
|
+
# The result of this will be interpolated at the position in the template.
|
|
40
|
+
# Not valid XHTML either.
|
|
41
|
+
#
|
|
42
|
+
# TODO
|
|
43
|
+
# - provide C version or maybe use erbuis
|
|
44
|
+
|
|
45
|
+
def transform(template, binding, file = __FILE__)
|
|
46
|
+
start_heredoc = "T" << Digest::SHA1.hexdigest(template)
|
|
47
|
+
start_heredoc, end_heredoc = "\n<<#{start_heredoc}\n", "\n#{start_heredoc}\n"
|
|
48
|
+
bufadd = "_out_ << "
|
|
49
|
+
|
|
50
|
+
template.gsub!(/<%\s+(.*?)\s+%>/m,
|
|
51
|
+
"#{end_heredoc} \\1; #{bufadd} #{start_heredoc}")
|
|
52
|
+
template.gsub!(/<\?r\s+(.*?)\s+\?>/m,
|
|
53
|
+
"#{end_heredoc} \\1; #{bufadd} #{start_heredoc}")
|
|
54
|
+
template.gsub!(/<%=\s+(.*?)\s+%>/m,
|
|
55
|
+
"#{end_heredoc} #{bufadd} (\\1); #{bufadd} #{start_heredoc}")
|
|
56
|
+
|
|
57
|
+
template = "_out_ = ''; #{bufadd} #{start_heredoc} #{template} #{end_heredoc}; _out_"
|
|
58
|
+
|
|
59
|
+
eval(template, binding, file).strip
|
|
81
60
|
end
|
|
82
|
-
|
|
83
|
-
@last_result = @last_result.join.strip
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# The actual compilation of the @source
|
|
87
|
-
#
|
|
88
|
-
# All ye who seek magic, look elsewhere, this method is ASAP (as simple as possible)
|
|
89
|
-
#
|
|
90
|
-
# There are some simple gsubs that build a final template which is evaluated
|
|
91
|
-
#
|
|
92
|
-
# The rules are following:
|
|
93
|
-
# <?r rubycode ?>
|
|
94
|
-
# evaluate the code inside the tag, this is considered XHTML-valid and so is the
|
|
95
|
-
# preferred method for executing code inside your templates.
|
|
96
|
-
# The return-value is ignored
|
|
97
|
-
# <% rubycode %>
|
|
98
|
-
# The same as <?r ?>, ERB-style and not valid XHTML, but should give someone who
|
|
99
|
-
# is already familiar with ERB some common ground
|
|
100
|
-
# #{ rubycode }
|
|
101
|
-
# You know this from normal ruby already and it's actually nothing else.
|
|
102
|
-
# Interpolation at the position in the template, isn't any special taggy format
|
|
103
|
-
# and therefor safe to use.
|
|
104
|
-
# <%= rubycode %>
|
|
105
|
-
# The result of this will be interpolated at the position in the template.
|
|
106
|
-
# Not valid XHTML either.
|
|
107
|
-
#
|
|
108
|
-
# The result of the compilation will be stored in @compiled.
|
|
109
|
-
|
|
110
|
-
def compile
|
|
111
|
-
@source.gsub!(/<%\s+(.*?)\s+%>/m,
|
|
112
|
-
"#{@end_heredoc} \\1; #{@bufadd} #{@start_heredoc}")
|
|
113
|
-
@source.gsub!(/<\?r\s+(.*?)\s+\?>/m,
|
|
114
|
-
"#{@end_heredoc} \\1; #{@bufadd} #{@start_heredoc}")
|
|
115
|
-
@source.gsub!(/<%=\s+(.*?)\s+%>/m,
|
|
116
|
-
"#{@end_heredoc} #{@bufadd} (\\1); #{@bufadd} #{@start_heredoc}")
|
|
117
|
-
|
|
118
|
-
@source = [@bufadd, @start_heredoc, @source, @end_heredoc].join(' ')
|
|
119
|
-
|
|
120
|
-
@old = false
|
|
121
|
-
@compiled = "_out_ = []; #{@source}; _out_"
|
|
122
61
|
end
|
|
123
62
|
end
|
|
124
63
|
end
|
|
@@ -106,10 +106,10 @@ class Ezamar::Morpher
|
|
|
106
106
|
# TODO:
|
|
107
107
|
# - Add pure Ruby implementation as a fall-back.
|
|
108
108
|
|
|
109
|
-
def self.transform template,
|
|
109
|
+
def self.transform template, action, file = __FILE__
|
|
110
110
|
morphs =
|
|
111
111
|
trait[:morphs].map{|k,v| [k.to_s, v.to_s]}.select do |(k,v)|
|
|
112
|
-
|
|
112
|
+
template.to_s.include?("#{k}=")
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
morphs = Hash[*morphs.flatten]
|
|
@@ -145,7 +145,7 @@ class Ezamar::Morpher
|
|
|
145
145
|
# replace this method with a stub that only returns the template.
|
|
146
146
|
|
|
147
147
|
self.class_eval do
|
|
148
|
-
def self.transform(template,
|
|
148
|
+
def self.transform(template, action)
|
|
149
149
|
template
|
|
150
150
|
end
|
|
151
151
|
end
|
data/lib/ramaze/template/haml.rb
CHANGED
|
@@ -22,16 +22,13 @@ module Ramaze::Template
|
|
|
22
22
|
# if you pass the options it will merge the trait with them. (your options
|
|
23
23
|
# override the defaults from trait[:haml_options]
|
|
24
24
|
|
|
25
|
-
def transform
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
reaction = controller.send(action, *parameter)
|
|
29
|
-
template = reaction_or_file(reaction, file)
|
|
25
|
+
def transform action
|
|
26
|
+
template = reaction_or_file(action)
|
|
30
27
|
|
|
31
28
|
return '' unless template
|
|
32
29
|
|
|
33
30
|
haml = ::Haml::Engine.new(template, ancestral_trait[:haml_options])
|
|
34
|
-
haml.to_html(controller)
|
|
31
|
+
haml.to_html(action.controller)
|
|
35
32
|
end
|
|
36
33
|
end
|
|
37
34
|
end
|
|
@@ -15,17 +15,12 @@ module Ramaze
|
|
|
15
15
|
# Also tries to render the template.
|
|
16
16
|
# In Theory you can use this standalone, this has not been tested though.
|
|
17
17
|
|
|
18
|
-
def transform
|
|
19
|
-
|
|
18
|
+
def transform action
|
|
19
|
+
template = reaction_or_file(action)
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
template = reaction_or_file(reaction, file)
|
|
23
|
-
|
|
24
|
-
return '' unless template
|
|
25
|
-
|
|
26
|
-
hash = controller.instance_variable_get("@hash") || {}
|
|
21
|
+
hash = action.controller.instance_variable_get("@hash") || {}
|
|
27
22
|
template = ::Liquid::Template.parse(template)
|
|
28
|
-
options = controller.ancestral_trait[:liquid_options]
|
|
23
|
+
options = action.controller.ancestral_trait[:liquid_options]
|
|
29
24
|
|
|
30
25
|
template.render(hash, options)
|
|
31
26
|
end
|