From 4f9b23c077121267e6802dfaa598d05999f3010a Mon Sep 17 00:00:00 2001 From: Andrew Haines Date: Tue, 13 Nov 2012 20:44:39 +0000 Subject: [PATCH] Remove System namespace --- lib/draper.rb | 24 +++++++++++++++++++++++- lib/draper/railtie.rb | 6 +++--- lib/draper/system.rb | 20 -------------------- spec/support/action_controller.rb | 2 +- 4 files changed, 27 insertions(+), 25 deletions(-) delete mode 100755 lib/draper/system.rb diff --git a/lib/draper.rb b/lib/draper.rb index 3ced90f..27a50e2 100644 --- a/lib/draper.rb +++ b/lib/draper.rb @@ -1,7 +1,6 @@ require 'action_view' require 'draper/version' -require 'draper/system' require 'draper/view_helpers' require 'draper/finders' require 'draper/decorator' @@ -20,6 +19,29 @@ require 'draper/test/rspec_integration' if defined?(RSpec) and RSpec.respond_ require 'draper/test/minitest_integration' if defined?(MiniTest::Rails) module Draper + def self.setup_action_controller(base) + base.class_eval do + include Draper::ViewContext + extend Draper::HelperSupport + before_filter ->(controller) { + Draper::ViewContext.current = nil + Draper::ViewContext.current_controller = controller + } + end + end + + def self.setup_action_mailer(base) + base.class_eval do + include Draper::ViewContext + end + end + + def self.setup_active_record(base) + base.class_eval do + include Draper::Decoratable + end + end + class UninferrableDecoratorError < NameError def initialize(klass) super("Could not infer a decorator for #{klass}.") diff --git a/lib/draper/railtie.rb b/lib/draper/railtie.rb index c42522a..acd50ec 100755 --- a/lib/draper/railtie.rb +++ b/lib/draper/railtie.rb @@ -24,19 +24,19 @@ module Draper initializer "draper.extend_action_controller_base" do |app| ActiveSupport.on_load(:action_controller) do - Draper::System.setup_action_controller(self) + Draper.setup_action_controller(self) end end initializer "draper.extend_action_mailer_base" do |app| ActiveSupport.on_load(:action_mailer) do - Draper::System.setup_action_mailer(self) + Draper.setup_action_mailer(self) end end initializer "draper.extend_active_record_base" do |app| ActiveSupport.on_load(:active_record) do - self.send(:include, Draper::Decoratable) + Draper.setup_active_record(self) end end diff --git a/lib/draper/system.rb b/lib/draper/system.rb deleted file mode 100755 index 03237c4..0000000 --- a/lib/draper/system.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Draper - class System - def self.setup_action_controller(component) - component.class_eval do - include Draper::ViewContext - extend Draper::HelperSupport - before_filter lambda {|controller| - Draper::ViewContext.current = nil - Draper::ViewContext.current_controller = controller - } - end - end - - def self.setup_action_mailer(component) - component.class_eval do - include Draper::ViewContext - end - end - end -end diff --git a/spec/support/action_controller.rb b/spec/support/action_controller.rb index 3146904..448d235 100644 --- a/spec/support/action_controller.rb +++ b/spec/support/action_controller.rb @@ -1,6 +1,6 @@ module ActionController class Base - Draper::System.setup_action_controller(self) + Draper.setup_action_controller(self) end end