lib/haml/helpers/action_view_mods.rb in haml-4.1.0.beta.1 vs lib/haml/helpers/action_view_mods.rb in haml-5.0.0.beta.2

- old
+ new

@@ -1,42 +1,41 @@ -module ActionView - class Base - def render_with_haml(*args, &block) - options = args.first +module Haml + module Helpers + module ActionViewMods + 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) } + # 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 - 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 output_buffer + return haml_buffer.buffer if is_haml? + super + end - 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) + 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, ActionViewMods) end +end +module ActionView module Helpers module CaptureHelper def capture_with_haml(*args, &block) if Haml::Helpers.block_is_haml?(block) #double assignment is to avoid warnings @@ -80,15 +79,13 @@ def is_haml? @template_object.send :is_haml? end end - if ActionPack::VERSION::MAJOR == 4 - module Tags - class TextArea - include HamlSupport - end + module Tags + class TextArea + include HamlSupport end end class InstanceTag include HamlSupport @@ -111,32 +108,17 @@ proc = haml_bind_proc do |*args| concat "\n" with_tabs(1) {oldproc.call(*args)} end end - res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n" + res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) << "\n" res << "\n" if wrap_block res else form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) end end alias_method :form_tag_without_haml, :form_tag alias_method :form_tag, :form_tag_with_haml - end - - module FormHelper - def form_for_with_haml(object_name, *args, &proc) - wrap_block = block_given? && is_haml? && block_is_haml?(proc) - if wrap_block - oldproc = proc - proc = proc {|*subargs| with_tabs(1) {oldproc.call(*subargs)}} - end - res = form_for_without_haml(object_name, *args, &proc) - res << "\n" if wrap_block - res - end - alias_method :form_for_without_haml, :form_for - alias_method :form_for, :form_for_with_haml end end end