Migrate ActionView::Base monkey patches to prepend

This commit is contained in:
Takashi Kokubun 2017-02-10 00:44:45 +09:00
parent d297f50298
commit c819a8de99
1 changed files with 30 additions and 31 deletions

View File

@ -1,40 +1,39 @@
module ActionView
class Base
def render_with_haml(*args, &block)
options = args.first
module Haml
module Helpers
module ActionViewBaseExtension
def render(*args, &block)
options = args.first
# If render :layout is used with a block, it concats rather than returning
# a string so we need it to keep thinking it's Haml until it hits the
# sub-render.
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
return non_haml { render_without_haml(*args, &block) }
end
render_without_haml(*args, &block)
end
alias_method :render_without_haml, :render
alias_method :render, :render_with_haml
def output_buffer_with_haml
return haml_buffer.buffer if is_haml?
output_buffer_without_haml
end
alias_method :output_buffer_without_haml, :output_buffer
alias_method :output_buffer, :output_buffer_with_haml
def set_output_buffer_with_haml(new_buffer)
if is_haml?
if Haml::Util.rails_xss_safe? && new_buffer.is_a?(ActiveSupport::SafeBuffer)
new_buffer = String.new(new_buffer)
# If render :layout is used with a block, it concats rather than returning
# a string so we need it to keep thinking it's Haml until it hits the
# sub-render.
if is_haml? && !(options.is_a?(Hash) && options[:layout] && block_given?)
return non_haml { super }
end
super
end
def output_buffer
return haml_buffer.buffer if is_haml?
super
end
def output_buffer=(new_buffer)
if is_haml?
if Haml::Util.rails_xss_safe? && new_buffer.is_a?(ActiveSupport::SafeBuffer)
new_buffer = String.new(new_buffer)
end
haml_buffer.buffer = new_buffer
else
super
end
haml_buffer.buffer = new_buffer
else
set_output_buffer_without_haml new_buffer
end
end
alias_method :set_output_buffer_without_haml, :output_buffer=
alias_method :output_buffer=, :set_output_buffer_with_haml
ActionView::Base.send(:prepend, ActionViewBaseExtension)
end
end
module ActionView
module Helpers
module CaptureHelper
def capture_with_haml(*args, &block)