lib/haml/helpers/action_view_mods.rb in haml-1.8.2 vs lib/haml/helpers/action_view_mods.rb in haml-2.0.0

- old
+ new

@@ -1,24 +1,43 @@ if defined?(ActionView) and not defined?(Merb::Plugins) module ActionView class Base # :nodoc: def render_with_haml(*args, &block) - was_haml = is_haml? - @haml_is_haml = false - res = render_without_haml(*args, &block) - @haml_is_haml = was_haml - res + return non_haml { render_without_haml(*args, &block) } if is_haml? + render_without_haml(*args, &block) end alias_method :render_without_haml, :render alias_method :render, :render_with_haml end # This overrides various helpers in ActionView # to make them work more effectively with Haml. module Helpers # :stopdoc: module CaptureHelper + def capture_with_haml(*args, &block) + # Rails' #capture helper will just return the value of the block + # if it's not actually in the template context, + # as detected by the existance of an _erbout variable. + # We've got to do the same thing for compatibility. + block_is_haml = + begin + eval('_hamlout', block) + true + rescue + false + end + + if block_is_haml && is_haml? + capture_haml(*args, &block) + else + capture_without_haml(*args, &block) + end + end + alias_method :capture_without_haml, :capture + alias_method :capture, :capture_with_haml + def capture_erb_with_buffer_with_haml(*args, &block) if is_haml? capture_haml_with_buffer(*args, &block) else capture_erb_with_buffer_without_haml(*args, &block) @@ -38,10 +57,39 @@ end alias_method :concat_without_haml, :concat alias_method :concat, :concat_with_haml end + module TagHelper + def content_tag_with_haml(name, *args, &block) + content = content_tag_without_haml(name, *args, &block) + + if is_haml? && haml_buffer.options[:preserve].include?(name.to_s) + content = Haml::Helpers.preserve content + end + + content + end + alias_method :content_tag_without_haml, :content_tag + alias_method :content_tag, :content_tag_with_haml + end + + class InstanceTag + # Includes TagHelper + + def haml_buffer + @template_object.send :haml_buffer + end + + def is_haml? + @template_object.send :is_haml? + end + + alias_method :content_tag_without_haml, :content_tag + alias_method :content_tag, :content_tag_with_haml + end + module FormTagHelper def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc) if is_haml? if block_given? oldproc = proc @@ -64,10 +112,10 @@ end module FormHelper def form_for_with_haml(object_name, *args, &proc) if block_given? && is_haml? - oldproc = proc + oldproc = proc proc = haml_bind_proc do |*args| tab_up oldproc.call(*args) tab_down end