require File.dirname(__FILE__)+'/mixins/erubis_capture_mixin' require File.dirname(__FILE__)+'/mixins/javascript_mixin' module Merb # the ViewContext is really # just an empty container for us to fill with instance # variables from the controller, include helpers into # and then use as the context object passed to Erubis # when evaluating the templates. class ViewContext include Merb::ErubisCaptureMixin include Merb::JavascriptMixin def initialize(controller) @controller = controller (@controller.instance_variables - %w[@cookies @session @headers @params @env @in @status @root @method @request @fingerprint_before @controller @k]).each do |ivar| self.instance_variable_set(ivar, @controller.instance_variable_get(ivar)) end begin self.class.class_eval("include Merb::#{@controller.class.name}Helper") rescue NameError MERB_LOGGER.info("Missing Helper: Merb::#{@controller.class.name}Helper") end end # accessor for the view. refers to the current @controller object def controller @controller end # catch any method calls that the controller responds to # and delegate them back to the controller. def method_missing(sym, *args, &blk) if @controller.respond_to? sym @controller.send(sym, *args, &blk) else super end end end end