Port the Markaby method override support to Mab
This commit is contained in:
parent
e100fec8e3
commit
474b2a22d9
1 changed files with 17 additions and 14 deletions
31
stoptime.rb
31
stoptime.rb
|
@ -77,21 +77,24 @@ end
|
||||||
|
|
||||||
# = The Stop… Camping Time! Markaby extensions
|
# = The Stop… Camping Time! Markaby extensions
|
||||||
# FIXME: update for Mab!
|
# FIXME: update for Mab!
|
||||||
module StopTime::Helpers
|
module StopTime::Mab
|
||||||
#SUPPORTED = [:get, :post]
|
SUPPORTED = [:get, :post]
|
||||||
|
|
||||||
# # Adds a method override field in form tags for (usually) unsupported
|
def mab_done(tag)
|
||||||
# # methods by browsers (i.e. PUT and DELETE) by injecting a hidden field.
|
return super unless tag.name == :form
|
||||||
# def tag!(tag, *attrs)
|
|
||||||
# return super unless tag == :form && block_given?
|
meth = tag.attributes[:method]
|
||||||
# attrs = attrs.last.is_a?(Hash) ? attrs.last : {}
|
tag.attributes[:method] = 'post' if override = !SUPPORTED.include?(meth)
|
||||||
# meth = attrs[:method]
|
# Inject a hidden input element with the proper method to the tag block
|
||||||
# attrs[:method] = 'post' if override = !SUPPORTED.include?(meth)
|
# if the form method is unsupported.
|
||||||
# super(tag, attrs) do
|
orig_blk = tag.block
|
||||||
# input :type => 'hidden', :name => '_method', :value => meth if override
|
tag.block = proc do
|
||||||
# yield
|
input :type => 'hidden', :name => '_method', :value => meth
|
||||||
# end
|
orig_blk.call
|
||||||
# end
|
end if override
|
||||||
|
end
|
||||||
|
|
||||||
|
include Mab::Indentation
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue