Fix missing root prefix calls for views

Because we override mab_done in StopTime::Mab, we override the functionality
in Camping::Mab that applies 'self /' on :href, :src and :action attributes
of tags.  Thus, all kinds of links don't get a root/mount prefix.
This commit is contained in:
Paul van Tilburg 2013-06-23 22:28:28 +02:00
parent 167c8d1b99
commit 60e1889072
1 changed files with 12 additions and 4 deletions

View File

@ -86,25 +86,33 @@ end
# = The Stop… Camping Time! Markaby extensions
module StopTime::Mab
SUPPORTED = [:get, :post]
def mab_done(tag)
attrs = tag._attributes
# Fix up URLs (normally done by Camping::Mab::mab_done
[:href, :action, :src].map { |a| attrs[a] &&= self/attrs[a] }
# Transform underscores into dashs in class names
if tag._attributes.has_key?(:class) and tag._attributes[:class].present?
tag._attributes[:class] = tag._attributes[:class].gsub('_', '-')
if attrs.has_key?(:class) and attrs[:class].present?
attrs[:class] = attrs[:class].gsub('_', '-')
end
# The followin method processing is only for form tags.
return super unless tag._name == :form
meth = tag._attributes[:method]
tag._attributes[:method] = 'post' if override = !SUPPORTED.include?(meth)
meth = attrs[:method]
attrs[:method] = 'post' if override = !SUPPORTED.include?(meth)
# Inject a hidden input element with the proper method to the tag block
# if the form method is unsupported.
tag._block do |orig_blk|
input :type => 'hidden', :name => '_method', :value => meth
orig_blk.call
end if override
return super
end
include Mab::Indentation