diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-03-03 16:42:20 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-03-03 16:42:20 -0800 |
commit | 6001cea5d70344d4c13b5cff94ee853f5f5462ce (patch) | |
tree | 10fb155f964c040c9f88e471570d2b99fe024e4c /actionpack/lib | |
parent | cde9aab8238c9acccc0ecc3efc988d752d4cc940 (diff) | |
download | rails-6001cea5d70344d4c13b5cff94ee853f5f5462ce.tar.gz rails-6001cea5d70344d4c13b5cff94ee853f5f5462ce.tar.bz2 rails-6001cea5d70344d4c13b5cff94ee853f5f5462ce.zip |
Helpers with an initial test
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/abstract/base.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_controller/abstract/helpers.rb | 55 |
2 files changed, 58 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/abstract/base.rb b/actionpack/lib/action_controller/abstract/base.rb index fe84c0f479..fa86d68c04 100644 --- a/actionpack/lib/action_controller/abstract/base.rb +++ b/actionpack/lib/action_controller/abstract/base.rb @@ -9,6 +9,9 @@ module AbstractController new.process(action) end + def self.inherited(klass) + end + def initialize self.response_obj = {} end diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb new file mode 100644 index 0000000000..b942a7ea80 --- /dev/null +++ b/actionpack/lib/action_controller/abstract/helpers.rb @@ -0,0 +1,55 @@ +module AbstractController + module Helpers + + def self.included(klass) + klass.class_eval do + extend ClassMethods + unless self < ::AbstractController::Renderer + raise "You need to include AbstractController::Renderer before including " \ + "AbstractController::Helpers" + end + extlib_inheritable_accessor :master_helper_module + self.master_helper_module = Module.new + end + end + + def _action_view + av = super + av.helpers.send(:include, master_helper_module) + end + + module ClassMethods + def inherited(klass) + klass.master_helper_module = Module.new + klass.master_helper_module.__send__ :include, master_helper_module + + super + end + + def add_template_helper(mod) + master_helper_module.module_eval { include mod } + end + + def helper_method(*meths) + meths.flatten.each do |meth| + master_helper_module.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 + def #{meth}(*args, &blk) + controller.send(%(#{meth}), *args, &blk) + end + ruby_eval + end + end + + def helper(*args, &blk) + args.flatten.each do |arg| + case arg + when Module + add_template_helper(arg) + end + end + master_helper_module.module_eval(&blk) if block_given? + end + end + + end +end
\ No newline at end of file |