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.
Files changed (195) hide show
  1. data/Rakefile +4 -12
  2. data/bin/ramaze +95 -171
  3. data/doc/CHANGELOG +387 -4
  4. data/doc/README +81 -13
  5. data/doc/meta/announcement.txt +51 -8
  6. data/doc/meta/configuration.txt +17 -34
  7. data/doc/meta/internals.txt +34 -4
  8. data/doc/migrate/1110_to_1111.txt +131 -0
  9. data/doc/readme_chunks/features.txt +81 -12
  10. data/doc/readme_chunks/installing.txt +0 -1
  11. data/doc/tutorial/todolist.html +293 -65
  12. data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
  13. data/examples/blog/main.rb +1 -1
  14. data/examples/blog/src/model.rb +0 -1
  15. data/examples/hello.rb +2 -5
  16. data/examples/templates/template/external.haml +5 -5
  17. data/examples/templates/template/external.liquid +1 -1
  18. data/examples/templates/template/external.mab +8 -8
  19. data/examples/templates/template/external.rem +30 -0
  20. data/examples/templates/template/external.rhtml +6 -7
  21. data/examples/templates/template/external.zmr +13 -9
  22. data/examples/templates/template_amrita2.rb +8 -8
  23. data/examples/templates/template_erubis.rb +11 -11
  24. data/examples/templates/template_ezamar.rb +9 -11
  25. data/examples/templates/template_haml.rb +13 -13
  26. data/examples/templates/template_liquid.rb +10 -10
  27. data/examples/templates/template_markaby.rb +13 -10
  28. data/examples/templates/template_remarkably.rb +59 -0
  29. data/examples/todolist/main.rb +1 -7
  30. data/examples/todolist/src/controller/main.rb +26 -13
  31. data/examples/todolist/src/element/page.rb +5 -0
  32. data/examples/whywiki/main.rb +1 -1
  33. data/lib/proto/main.rb +0 -8
  34. data/lib/proto/public/css/ramaze_error.css +12 -4
  35. data/lib/proto/public/error.zmr +6 -25
  36. data/lib/ramaze.rb +35 -245
  37. data/lib/ramaze/action.rb +21 -0
  38. data/lib/ramaze/adapter.rb +94 -29
  39. data/lib/ramaze/adapter/base.rb +57 -0
  40. data/lib/ramaze/adapter/mongrel.rb +12 -19
  41. data/lib/ramaze/adapter/webrick.rb +21 -20
  42. data/lib/ramaze/cache.rb +47 -3
  43. data/lib/ramaze/cache/memcached.rb +22 -0
  44. data/lib/ramaze/cache/yaml_store.rb +19 -0
  45. data/lib/ramaze/controller.rb +47 -271
  46. data/lib/ramaze/controller/error.rb +43 -0
  47. data/lib/ramaze/controller/render.rb +90 -0
  48. data/lib/ramaze/controller/resolve.rb +147 -0
  49. data/lib/ramaze/dispatcher.rb +41 -9
  50. data/lib/ramaze/dispatcher/file.rb +1 -1
  51. data/lib/ramaze/global.rb +73 -158
  52. data/lib/ramaze/global/dsl.rb +29 -0
  53. data/lib/ramaze/global/globalstruct.rb +90 -0
  54. data/lib/ramaze/helper.rb +1 -1
  55. data/lib/ramaze/helper/aspect.rb +39 -179
  56. data/lib/ramaze/helper/cache.rb +8 -9
  57. data/lib/ramaze/helper/cgi.rb +23 -0
  58. data/lib/ramaze/helper/file.rb +3 -0
  59. data/lib/ramaze/helper/inform.rb +3 -0
  60. data/lib/ramaze/helper/link.rb +56 -63
  61. data/lib/ramaze/helper/nitroform.rb +4 -0
  62. data/lib/ramaze/helper/redirect.rb +1 -1
  63. data/lib/ramaze/inform.rb +6 -2
  64. data/lib/ramaze/inform/analogger.rb +5 -1
  65. data/lib/ramaze/inform/hub.rb +1 -1
  66. data/lib/ramaze/inform/informing.rb +7 -0
  67. data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
  68. data/lib/ramaze/snippets/kernel/constant.rb +2 -0
  69. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
  70. data/lib/ramaze/snippets/object/traits.rb +4 -0
  71. data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
  72. data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
  73. data/lib/ramaze/snippets/string/camel_case.rb +2 -0
  74. data/lib/ramaze/snippets/string/color.rb +2 -0
  75. data/lib/ramaze/snippets/string/each.rb +2 -0
  76. data/lib/ramaze/snippets/string/snake_case.rb +3 -0
  77. data/lib/ramaze/snippets/struct/fill.rb +8 -2
  78. data/lib/ramaze/snippets/struct/values_at.rb +16 -0
  79. data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
  80. data/lib/ramaze/sourcereload.rb +89 -0
  81. data/lib/ramaze/template.rb +21 -12
  82. data/lib/ramaze/template/amrita2.rb +6 -6
  83. data/lib/ramaze/template/erubis.rb +4 -9
  84. data/lib/ramaze/template/ezamar.rb +13 -57
  85. data/lib/ramaze/template/ezamar/element.rb +10 -12
  86. data/lib/ramaze/template/ezamar/engine.rb +40 -101
  87. data/lib/ramaze/template/ezamar/morpher.rb +3 -3
  88. data/lib/ramaze/template/haml.rb +3 -6
  89. data/lib/ramaze/template/liquid.rb +4 -9
  90. data/lib/ramaze/template/markaby.rb +16 -22
  91. data/lib/ramaze/template/remarkably.rb +28 -0
  92. data/lib/ramaze/tool/mime.rb +2 -0
  93. data/lib/ramaze/tool/record.rb +6 -0
  94. data/lib/ramaze/trinity/request.rb +44 -54
  95. data/lib/ramaze/trinity/response.rb +1 -1
  96. data/lib/ramaze/trinity/session.rb +15 -37
  97. data/lib/ramaze/version.rb +1 -1
  98. data/rake_tasks/gem.rake +2 -2
  99. data/rake_tasks/maintaince.rake +42 -1
  100. data/rake_tasks/spec.rake +45 -0
  101. data/spec/examples/caching.rb +1 -1
  102. data/spec/examples/simple.rb +1 -1
  103. data/spec/examples/templates/template_amrita2.rb +1 -0
  104. data/spec/examples/templates/template_erubis.rb +2 -1
  105. data/spec/examples/templates/template_ezamar.rb +1 -1
  106. data/spec/examples/templates/template_haml.rb +2 -1
  107. data/spec/examples/templates/template_liquid.rb +2 -1
  108. data/spec/examples/templates/template_markaby.rb +2 -1
  109. data/spec/examples/templates/template_remarkably.rb +22 -0
  110. data/spec/examples/todolist.rb +125 -0
  111. data/spec/helper.rb +2 -23
  112. data/spec/helper/minimal.rb +20 -0
  113. data/spec/helper/mock_http.rb +24 -30
  114. data/spec/helper/simple_http.rb +2 -2
  115. data/spec/helper/wrap.rb +6 -9
  116. data/spec/ramaze/adapter.rb +1 -1
  117. data/spec/ramaze/adapter/record.rb +31 -0
  118. data/spec/ramaze/cache.rb +41 -54
  119. data/spec/ramaze/controller.rb +121 -137
  120. data/spec/ramaze/controller/template/list.xhtml +1 -0
  121. data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
  122. data/spec/ramaze/controller/template_resolving.rb +27 -3
  123. data/spec/ramaze/element.rb +11 -7
  124. data/spec/ramaze/error.rb +1 -1
  125. data/spec/ramaze/gestalt.rb +2 -0
  126. data/spec/ramaze/helper/aspect.rb +30 -21
  127. data/spec/ramaze/helper/auth.rb +1 -1
  128. data/spec/ramaze/helper/cache.rb +2 -1
  129. data/spec/ramaze/helper/form.rb +14 -11
  130. data/spec/ramaze/helper/link.rb +18 -41
  131. data/spec/ramaze/localize.rb +29 -2
  132. data/spec/ramaze/morpher.rb +23 -12
  133. data/spec/ramaze/params.rb +46 -24
  134. data/spec/ramaze/request.rb +6 -2
  135. data/spec/ramaze/store/yaml.rb +5 -0
  136. data/spec/ramaze/template.rb +22 -27
  137. data/spec/ramaze/template/amrita2.rb +1 -2
  138. data/spec/ramaze/template/erubis.rb +1 -1
  139. data/spec/ramaze/template/ezamar.rb +1 -2
  140. data/spec/ramaze/template/haml.rb +2 -2
  141. data/spec/ramaze/template/haml/with_vars.haml +1 -1
  142. data/spec/ramaze/template/liquid.rb +1 -1
  143. data/spec/ramaze/template/markaby.rb +1 -1
  144. data/spec/ramaze/template/remarkably.rb +56 -0
  145. data/spec/ramaze/template/remarkably/external.rem +8 -0
  146. data/spec/ramaze/template/remarkably/sum.rem +1 -0
  147. metadata +38 -63
  148. data/doc/README.html +0 -637
  149. data/doc/allison/LICENSE +0 -184
  150. data/doc/allison/README +0 -37
  151. data/doc/allison/allison.css +0 -299
  152. data/doc/allison/allison.gif +0 -0
  153. data/doc/allison/allison.js +0 -307
  154. data/doc/allison/allison.rb +0 -287
  155. data/doc/allison/cache/BODY +0 -588
  156. data/doc/allison/cache/CLASS_INDEX +0 -4
  157. data/doc/allison/cache/CLASS_PAGE +0 -1
  158. data/doc/allison/cache/FILE_INDEX +0 -4
  159. data/doc/allison/cache/FILE_PAGE +0 -1
  160. data/doc/allison/cache/FONTS +0 -1
  161. data/doc/allison/cache/FR_INDEX_BODY +0 -1
  162. data/doc/allison/cache/IMGPATH +0 -1
  163. data/doc/allison/cache/INDEX +0 -1
  164. data/doc/allison/cache/JAVASCRIPT +0 -307
  165. data/doc/allison/cache/METHOD_INDEX +0 -4
  166. data/doc/allison/cache/METHOD_LIST +0 -1
  167. data/doc/allison/cache/SRC_PAGE +0 -1
  168. data/doc/allison/cache/STYLE +0 -321
  169. data/doc/allison/cache/URL +0 -1
  170. data/doc/changes.txt +0 -3375
  171. data/doc/changes.xml +0 -3378
  172. data/examples/todolist/conf/benchmark.yaml +0 -35
  173. data/examples/todolist/conf/debug.yaml +0 -34
  174. data/examples/todolist/conf/live.yaml +0 -33
  175. data/examples/todolist/conf/silent.yaml +0 -31
  176. data/examples/todolist/conf/stage.yaml +0 -33
  177. data/examples/todolist/public/css/coderay.css +0 -105
  178. data/examples/todolist/public/css/ramaze_error.css +0 -42
  179. data/lib/proto/conf/benchmark.yaml +0 -21
  180. data/lib/proto/conf/debug.yaml +0 -21
  181. data/lib/proto/conf/live.yaml +0 -21
  182. data/lib/proto/conf/silent.yaml +0 -21
  183. data/lib/proto/conf/stage.yaml +0 -21
  184. data/lib/proto/public/css/coderay.css +0 -105
  185. data/lib/ramaze/http_status.rb +0 -66
  186. data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
  187. data/lib/ramaze/snippets/kernel/method.rb +0 -26
  188. data/lib/ramaze/snippets/method/name.rb +0 -22
  189. data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
  190. data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
  191. data/spec/all.rb +0 -32
  192. data/spec/ramaze/conf/locale_de.yaml +0 -6
  193. data/spec/ramaze/conf/locale_en.yaml +0 -6
  194. data/spec/ramaze/dependencies.rb +0 -16
  195. data/spec/ramaze/global.rb +0 -44
@@ -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, Ezamar, Haml, Liquid and Markaby if you refer to them.
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 reaction, file
30
- if file
25
+ def reaction_or_file action
26
+ reaction = render_method(action)
27
+
28
+ if file = action.template
31
29
  File.read(file)
32
- elsif reaction.respond_to? :to_str
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 transform controller, options = {}
38
- options.values_at(:action, :parameter, :file, :binding)
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 a controller and the options :action, :parameter, :file and :binding
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 controller, options = {}
23
- action, parameter, file, bound = *super
24
-
25
- raise Ramaze::Error::Template, "No Template found for #{Request.current.request_path}" unless file
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', parameter)
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 controller, options = {}
22
- action, parameter, file, bound = *super
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 => file) if file
31
- eruby.result(bound)
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 => [ ::Ezamar::Element, ::Ezamar::Morpher, self ]
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 controller, options = {}
25
- if options.has_key?(:pipeline)
26
- template = ::Ezamar::Template.new(controller, options)
27
- template.transform(options[:binding])
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, options = {})
85
- transform_pipeline = ancestral_trait[:transform_pipeline]
86
- opts = options.reject{|k,v| [:template, :path, :binding].all?{|o| k != o}}
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 string = '', options = {}
87
- binding, path = options.values_at(:binding, :path)
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
- string = send("transform_#{transformer}_content", string, klass)
91
+ template = send("transform_#{transformer}_content", template, klass)
94
92
  end
95
- string
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(string, klass)
102
- string.gsub(/<#{klass}( .*?)?>(.*?)<\/#{klass}>/m) do |m|
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(string, klass)
112
- string.gsub(/<#{klass}( .*?)?\/>/) do |m|
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(string)
152
- string.scan(/\s?(.*?)="(.*?)"/).inject({}) do |hash, (key, value)|
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
- attr_accessor :last_result, :file
21
- attr_reader :original
22
-
23
- # Start a new template with some string for your template
24
- # that's going to be transformed.
25
-
26
- def initialize source, options = {}
27
- @original = @source = source
28
- @binding, @file = options.values_at(:binding, :path)
29
- @start_heredoc = "T" << Digest::SHA1.hexdigest(@source)
30
- @start_heredoc, @end_heredoc = "\n<<#{@start_heredoc}\n", "\n#{@start_heredoc}\n"
31
- @bufadd = "_out_ << "
32
- @old = true
33
- compile
34
- end
35
-
36
- # reset the original template you gave
37
-
38
- def original=(original)
39
- compile
40
- end
41
-
42
- # is the template old?
43
-
44
- def old?
45
- !!@old
46
- end
47
-
48
- # make the template old - mark it for recompilation.
49
-
50
- def touch
51
- @old = true
52
- end
53
-
54
- # transform a String to a final xhtml
55
- #
56
- # You can pass it a binding, for example from your controller.
57
- #
58
- # Example:
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, options = {}
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
- template.to_s.include?("#{k}=")
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, options = {})
148
+ def self.transform(template, action)
149
149
  template
150
150
  end
151
151
  end
@@ -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 controller, options = {}
26
- action, parameter, file, bound = *super
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 controller, options = {}
19
- action, parameter, file, bound = *super
18
+ def transform action
19
+ template = reaction_or_file(action)
20
20
 
21
- reaction = controller.send(action, *parameter)
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