Fix up some hacks that generate errors when used with Mab

This commit is contained in:
Paul van Tilburg 2012-01-25 15:53:24 +01:00
parent 419d08a6eb
commit 3a824c2026
1 changed files with 20 additions and 12 deletions

View File

@ -78,20 +78,28 @@ module StopTime
end end
# = The Stop… Camping Time! Markaby extensions # = The Stop… Camping Time! Markaby extensions
module StopTime::Helpers module StopTime::Mab
SUPPORTED = [:get, :post] SUPPORTED = [:get, :post]
# Adds a method override field in form tags for (usually) unsupported # # Adds a method override field in form tags for (usually) unsupported
# methods by browsers (i.e. PUT and DELETE) by injecting a hidden field. # # methods by browsers (i.e. PUT and DELETE) by injecting a hidden field.
def tag!(tag, *attrs) # def tag!(tag, *attrs)
return super unless tag == :form && block_given? # return super unless tag == :form && block_given?
attrs = attrs.last.is_a?(Hash) ? attrs.last : {} # attrs = attrs.last.is_a?(Hash) ? attrs.last : {}
meth = attrs[:method] # meth = attrs[:method]
attrs[:method] = 'post' if override = !SUPPORTED.include?(meth) # attrs[:method] = 'post' if override = !SUPPORTED.include?(meth)
super(tag, attrs) do # super(tag, attrs) do
input :type => 'hidden', :name => '_method', :value => meth if override # input :type => 'hidden', :name => '_method', :value => meth if override
yield # yield
end # end
# end
def tag!(name, *args)
Kernel.p [name, args]
content = args.shift unless args.first.is_a?(Hash)
attrs = args.inject { |a,b| a.merge(b) }
Kernel.p [name, content, args]
super(name, content, attrs)
end end
end end