Permalink
Browse files

support all helpers in view context

  • Loading branch information...
1 parent a1ebf6e commit a44f8f5bb9d5128baad09310181fc4cf67922254 @ursm ursm committed Feb 24, 2012
View
@@ -1,4 +1,3 @@
require 'active_decorator/version'
require 'active_decorator/decorator'
require 'active_decorator/railtie'
-
@@ -1,21 +1,14 @@
-require 'action_view'
-
module ActiveDecorator
module Helpers
def method_missing(method, *args, &block)
super
#TODO need to make sure who raised the error?
rescue NoMethodError => no_method_error
begin
- @@_decorator_view_proxy ||= DecoratorViewProxy.new
- @@_decorator_view_proxy.send method, *args, &block
+ ActiveDecorator::ViewContext.current.send method, *args, &block
rescue NoMethodError
raise no_method_error
end
end
-
- class DecoratorViewProxy
- include ::ActionView::Helpers
- end
end
end
@@ -1,3 +1,4 @@
+require 'active_decorator/view_context'
require 'rails'
module ActiveDecorator
@@ -8,6 +9,7 @@ class Railtie < ::Rails::Railtie
end
ActiveSupport.on_load(:action_controller) do
require 'active_decorator/monkey/abstract_controller/rendering'
+ ActionController::Base.send :include, ActiveDecorator::ViewContext::Filter
end
ActiveSupport.on_load(:action_mailer) do
require 'active_decorator/monkey/abstract_controller/rendering'
@@ -0,0 +1,23 @@
+module ActiveDecorator
+ module ViewContext
+ class << self
+ def current
+ Thread.current[:view_context]
+ end
+
+ def current=(view_context)
+ Thread.current[:view_context] = view_context
+ end
+ end
+
+ module Filter
+ extend ActiveSupport::Concern
+
+ included do
+ before_filter do |controller|
+ ActiveDecorator::ViewContext.current = controller.view_context
+ end
+ end
+ end
+ end
+end
@@ -1 +1,2 @@
<%= @book.link %>
+<%= @book.cover_image %>
@@ -54,6 +54,10 @@ def upcased_title
def link
link_to title, 'http://example.com'
end
+
+ def cover_image
+ image_tag 'cover.png'
+ end
end
# controllers
@@ -11,5 +11,6 @@
within 'a' do
page.should have_content 'RHG'
end
+ page.should have_css('img')
end
end

0 comments on commit a44f8f5

Please sign in to comment.