lib/phlex/renderable.rb in phlex-0.4.0 vs lib/phlex/renderable.rb in phlex-0.5.0

- old
+ new

@@ -1,17 +1,17 @@ # frozen_string_literal: true module Phlex module Renderable def render(renderable, *args, **kwargs, &block) - if renderable.is_a?(View) + if renderable.is_a?(HTML) if block_given? && !block.binding.receiver.is_a?(Phlex::Block) block = Phlex::Block.new(self, &block) end renderable.call(@_target, view_context: @_view_context, parent: self, &block) - elsif renderable.is_a?(Class) && renderable < View + elsif renderable.is_a?(Class) && renderable < Phlex::HTML raise ArgumentError, "You tried to render the Phlex view class: #{renderable.name} but you probably meant to render an instance of that class instead." else @_target << @_view_context.render(renderable, *args, **kwargs, &block) end @@ -24,10 +24,16 @@ view_context.with_output_buffer(self) do original_length = @_target.length output = yield(*args, **kwargs) unchanged = (original_length == @_target.length) - text(output) if unchanged && output.is_a?(String) + if unchanged + if defined?(ActiveSupport::SafeBuffer) && output.is_a?(ActiveSupport::SafeBuffer) + unsafe_raw(output) + else + text(output) + end + end end end.html_safe else call(view_context: view_context).html_safe end