From 60e188907296fe427d055f5a40ccae6528b8dacd Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 23 Jun 2013 22:28:28 +0200 Subject: [PATCH] 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. --- stoptime.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 6248cda..e101903 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -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