lib/ramaze/template/erubis.rb in ramaze-0.0.7 vs lib/ramaze/template/erubis.rb in ramaze-0.0.8

- old
+ new

@@ -2,57 +2,34 @@ # All files in this distribution are subject to the terms of the Ruby license. require 'erubis' module Ramaze::Template - class Erubis < Template - extend Ramaze::Helper - # Actions consist of both templates and methods on the controller. - trait :actionless => false + # Is responsible for compiling a template using the Erubis templating engine. - # usual extensions for templates. - trait :template_extensions => %w[rhtml rmze xhtml html] + class Erubis < Template + Ramaze::Controller.register_engine self, %w[ rhtml ] + class << self - # initializes the handling of a request on the controller. - # Creates a new instances of itself and sends the action and params. - # Also tries to render the template. - # In Theory you can use this standalone, this has not been tested though. - def handle_request action, *params - controller = self.new - controller.instance_variable_set('@action', action) - result = controller.send(action, *params) if controller.respond_to?(action) + # Takes a controller and the options :action, :parameter, :file and :binding + # + # Builds a template out of the method on the controller and the + # template-file. - file = find_template(action) + def transform controller, options = {} + action, parameter, file, bound = *super - template = - if file - File.read(file) - elsif result.respond_to? :to_str - result - end + reaction = controller.send(action, *parameter) + template = reaction_or_file(reaction, file) return '' unless template - bound = result.is_a?(Binding) ? result : controller.send(:send, :binding) - - controller.send(:transform, template, bound, file) - rescue Object => ex - puts ex - Informer.error ex - '' + eruby = ::Erubis::Eruby.new(template) + eruby.init_evaluator(:filename => file) if file + eruby.result(bound) end - end - - private - - # Transform any String via Erubis, takes an optional binding and filename - - def transform string, bound = binding, file = nil - eruby = ::Erubis::Eruby.new(string) - eruby.init_evaluator(:filename => file) if file - eruby.result(bound) end end end