lib/action_view/component/base.rb in actionview-component-1.7.0 vs lib/action_view/component/base.rb in actionview-component-1.8.0
- old
+ new
@@ -45,10 +45,13 @@
@view_renderer ||= view_context.view_renderer
@lookup_context ||= view_context.lookup_context
@view_flow ||= view_context.view_flow
@virtual_path ||= virtual_path
@variant = @lookup_context.variants.first
+
+ return "" unless render?
+
old_current_template = @current_template
@current_template = self
@content = view_context.capture(self, &block) if block_given?
@@ -57,10 +60,14 @@
send(self.class.call_method_name(@variant))
ensure
@current_template = old_current_template
end
+ def render?
+ true
+ end
+
def initialize(*); end
def render(options = {}, args = {}, &block)
if options.is_a?(String) || (options.is_a?(Hash) && options.has_key?(:partial))
view_context.render(options, args, &block)
@@ -110,10 +117,16 @@
@request ||= controller.request
end
attr_reader :content, :view_context
+ # The controller used for testing components.
+ # Defaults to ApplicationController. This should be set early
+ # in the initialization process and should be set to a string.
+ mattr_accessor :test_controller
+ @@test_controller = "ApplicationController"
+
class << self
def inherited(child)
child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
super
@@ -197,10 +210,10 @@
private
def matching_views_in_source_location
return [] unless source_location
- (Dir["#{source_location.sub(/#{File.extname(source_location)}$/, '')}.*{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [source_location])
+ (Dir["#{source_location.chomp(File.extname(source_location))}.*{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [source_location])
end
def templates
@templates ||=
matching_views_in_source_location.each_with_object([]) do |path, memo|