module Draper::ViewContext
def self.build
Builds a new view context for usage in tests. See {test_strategy} for
def self.build build_strategy.call end
def self.build!
-
(HelperProxy)
-
def self.build! # send because we want to return the HelperProxy returned from #current= send :current=, build end
def self.build_strategy
- Private: -
def self.build_strategy @build_strategy ||= Draper::ViewContext::BuildStrategy.new(:full) end
def self.clear!
def self.clear! RequestStore.store.delete :current_controller RequestStore.store.delete :current_view_context end
def self.controller
def self.controller RequestStore.store[:current_controller] end
def self.controller=(controller)
Sets the current controller. Clears view context when we are setting
def self.controller=(controller) clear! if RequestStore.store[:current_controller] != controller RequestStore.store[:current_controller] = controller end
def self.current
-
(HelperProxy)
-
def self.current RequestStore.store.fetch(:current_view_context) { build! } end
def self.current=(view_context)
def self.current=(view_context) RequestStore.store[:current_view_context] = Draper::HelperProxy.new(view_context) end
def self.test_strategy(name, &block)
-
name
(:full, :fast
) --
Other tags:
- Example: Pass a block to add helper methods to the view context: -
def self.test_strategy(name, &block) @build_strategy = Draper::ViewContext::BuildStrategy.new(name, &block) end
def activate_draper
def activate_draper Draper::ViewContext.controller = self end
def view_context
def view_context super.tap do |context| Draper::ViewContext.current = context end end