mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Working form_tag on edge. Rcov for helpers/action_view_mods.rb isn't
100% unless the Edge Rails gem is installed, because the new form_for stuff isn't properly tested. git-svn-id: svn://hamptoncatlin.com/haml/branches/edge@140 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
eb5e0b03c7
commit
61eac1df2f
3 changed files with 43 additions and 1 deletions
|
@ -65,6 +65,14 @@ module Haml
|
||||||
@haml_stack[-1]
|
@haml_stack[-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
||||||
|
# that the current template has.
|
||||||
|
def bind_proc(&proc)
|
||||||
|
_hamlout = buffer
|
||||||
|
_erbout = _hamlout.buffer
|
||||||
|
proc { |*args| proc.call(*args) }
|
||||||
|
end
|
||||||
|
|
||||||
include ActionViewMods if self.const_defined? "ActionViewMods"
|
include ActionViewMods if self.const_defined? "ActionViewMods"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ end
|
||||||
if action_view_included
|
if action_view_included
|
||||||
class ActionView::Base
|
class ActionView::Base
|
||||||
alias_method :old_concat, :concat unless instance_methods.include? "old_concat"
|
alias_method :old_concat, :concat unless instance_methods.include? "old_concat"
|
||||||
|
alias_method :old_form_tag, :form_tag unless instance_methods.include? "old_form_tag"
|
||||||
end
|
end
|
||||||
|
|
||||||
module Haml
|
module Haml
|
||||||
|
@ -25,6 +26,19 @@ if action_view_included
|
||||||
def concat(string, binding = nil)
|
def concat(string, binding = nil)
|
||||||
buffer.buffer.concat(string)
|
buffer.buffer.concat(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)
|
||||||
|
if block_given?
|
||||||
|
oldproc = proc
|
||||||
|
proc = bind_proc do |*args|
|
||||||
|
concat "\n"
|
||||||
|
tab_up
|
||||||
|
oldproc.call(*args)
|
||||||
|
tab_down
|
||||||
|
end
|
||||||
|
end
|
||||||
|
old_form_tag(url_for_options, options, *parameters_for_url, &proc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,19 @@ require File.dirname(__FILE__) + '/../lib/haml/helpers'
|
||||||
|
|
||||||
class HelperTest < Test::Unit::TestCase
|
class HelperTest < Test::Unit::TestCase
|
||||||
include Haml::Helpers
|
include Haml::Helpers
|
||||||
|
|
||||||
|
def setup
|
||||||
|
ActionView::Base.register_template_handler("haml", Haml::Template)
|
||||||
|
@base = ActionView::Base.new
|
||||||
|
@base.controller = ActionController::Base.new
|
||||||
|
end
|
||||||
|
|
||||||
def render(text, options = {})
|
def render(text, options = {})
|
||||||
Haml::Engine.new(text, options).to_html
|
if options == :action_view
|
||||||
|
@base.render :inline => text, :type => :haml
|
||||||
|
else
|
||||||
|
Haml::Engine.new(text, options).to_html
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_flatten
|
def test_flatten
|
||||||
|
@ -75,5 +85,15 @@ class HelperTest < Test::Unit::TestCase
|
||||||
alias_method :require, :old_require
|
alias_method :require, :old_require
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_form_tag
|
||||||
|
# Until the next Rails is released, form_tag with a block can have one of
|
||||||
|
# two behaviors.
|
||||||
|
|
||||||
|
result = render("- form_tag 'foo' do\n %p bar\n %strong baz", :action_view)
|
||||||
|
new_rails = "<form action=\"foo\" method=\"post\">\n <p>foo</p>\n</form>\n"
|
||||||
|
old_rails = ""
|
||||||
|
assert(result == new_rails || result == old_rails)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue