Sha256: 0789af339eeb06d8358426508bdf52c731de9bceb4b54c834628758ec569c82b
Contents?: true
Size: 1.88 KB
Versions: 3
Compression:
Stored size: 1.88 KB
Contents
require File.dirname(__FILE__)+'/mixins/erubis_capture_mixin' require File.dirname(__FILE__)+'/mixins/view_context_mixin' require File.dirname(__FILE__)+'/mixins/form_control_mixin' module Merb PROTECTED_IVARS = %w[@cookies @session @headers @params @env @in @status @root @method @request @fingerprint_before @_new_cookie @tmpl_ext_cache @body] module GlobalHelper end # 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::ViewContextMixin include Merb::FormControls include Merb::GlobalHelper def initialize(controller) @controller = controller (@controller.instance_variables - PROTECTED_IVARS).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 # hack so markaby doesn't dup us and lose ivars. def dup self end # accessor for the view. refers to the current @controller object def controller @controller end alias_method :old_respond_to?, :respond_to? def respond_to?(sym, include_private=false) old_respond_to?(sym, include_private) || @controller.respond_to?(sym, include_private) 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
merb-0.2.0 | lib/merb/merb_view_context.rb |
merb-0.3.0 | lib/merb/merb_view_context.rb |
merb-0.3.1 | lib/merb/merb_view_context.rb |