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:
parent
167c8d1b99
commit
60e1889072
16
stoptime.rb
16
stoptime.rb
|
@ -86,25 +86,33 @@ end
|
||||||
|
|
||||||
# = The Stop… Camping Time! Markaby extensions
|
# = The Stop… Camping Time! Markaby extensions
|
||||||
module StopTime::Mab
|
module StopTime::Mab
|
||||||
|
|
||||||
SUPPORTED = [:get, :post]
|
SUPPORTED = [:get, :post]
|
||||||
|
|
||||||
def mab_done(tag)
|
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
|
# Transform underscores into dashs in class names
|
||||||
if tag._attributes.has_key?(:class) and tag._attributes[:class].present?
|
if attrs.has_key?(:class) and attrs[:class].present?
|
||||||
tag._attributes[:class] = tag._attributes[:class].gsub('_', '-')
|
attrs[:class] = attrs[:class].gsub('_', '-')
|
||||||
end
|
end
|
||||||
|
|
||||||
# The followin method processing is only for form tags.
|
# The followin method processing is only for form tags.
|
||||||
return super unless tag._name == :form
|
return super unless tag._name == :form
|
||||||
|
|
||||||
meth = tag._attributes[:method]
|
meth = attrs[:method]
|
||||||
tag._attributes[:method] = 'post' if override = !SUPPORTED.include?(meth)
|
attrs[:method] = 'post' if override = !SUPPORTED.include?(meth)
|
||||||
# Inject a hidden input element with the proper method to the tag block
|
# Inject a hidden input element with the proper method to the tag block
|
||||||
# if the form method is unsupported.
|
# if the form method is unsupported.
|
||||||
tag._block do |orig_blk|
|
tag._block do |orig_blk|
|
||||||
input :type => 'hidden', :name => '_method', :value => meth
|
input :type => 'hidden', :name => '_method', :value => meth
|
||||||
orig_blk.call
|
orig_blk.call
|
||||||
end if override
|
end if override
|
||||||
|
|
||||||
|
return super
|
||||||
end
|
end
|
||||||
|
|
||||||
include Mab::Indentation
|
include Mab::Indentation
|
||||||
|
|
Loading…
Reference in New Issue