Changeset 1090

Show
Ignore:
Timestamp:
12/13/07 16:00:24 (1 year ago)
Author:
dudl..@misnomer.us
Message:

Fixed image_tag, css_include_tag, and js_include_tag to work with path_prefix

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG

    r1081 r1090  
    55* merb_helpers: form field labels are now explicit, huge documentation update, added select, fieldset, more helpers 
    66* Fixed merb.show_routes within merb -i 
     7* Fixed image_tag, css_include_tag, and js_include_tag to work with path_prefix 
    78 
    89== 0.4.1 "Faster Partials or Partially Faster?" 2007-11-12 
  • trunk/lib/merb/mixins/general_controller.rb

    r1079 r1090  
    8686          raise "URL not generated: #{route_name.inspect}, #{new_params.inspect}" 
    8787        end 
    88       url = MerbHandler.path_prefix + url if MerbHandler.path_prefix 
     88      url = Merb::Server.config[:path_prefix] + url if Merb::Server.config[:path_prefix] 
    8989      url 
    9090    end 
  • trunk/lib/merb/mixins/view_context.rb

    r1063 r1090  
    4949    #   # => <img src="http://test.com/foo.gif"> 
    5050    def image_tag(img, opts={}) 
    51       opts[:path] ||= (img =~ %r{^https?://}) ? '' : '/images/' 
     51      opts[:path] ||=  
     52        if img =~ %r{^https?://} 
     53          '' 
     54        else 
     55          if Merb::Server.config[:path_prefix] 
     56            Merb::Server.config[:path_prefix] + '/images/' 
     57          else 
     58            '/images/' 
     59          end 
     60        end 
    5261      opts[:src] ||= opts.delete(:path) + img 
    5362      %{<img #{ opts.to_xml_attributes } />}     
     
    259268      scripts.each do |script| 
    260269        script = script.to_s 
    261         include_tag << %Q|<script src="/javascripts/#{script=~/\.js$/ ? script : script+'.js' }" type="text/javascript">//</script>\n| 
     270        url = "/javascripts/#{script =~ /\.js$/ ? script : script + '.js'}" 
     271        url = Merb::Server.config[:path_prefix] + url if Merb::Server.config[:path_prefix] 
     272        include_tag << %Q|<script src="#{url}" type="text/javascript">//</script>\n| 
    262273      end 
    263274      include_tag 
     
    288299      scripts.each do |script| 
    289300        script = script.to_s 
    290         include_tag << %Q|<link href="/stylesheets/#{script=~/\.css$/ ? script : script+'.css' }" media="all" rel="Stylesheet" type="text/css"/>\n| 
     301        url = "/stylesheets/#{script =~ /\.css$/ ? script : script + '.css'}" 
     302        url = Merb::Server.config[:path_prefix] + url if Merb::Server.config[:path_prefix] 
     303        include_tag << %Q|<link href="#{url}" media="all" rel="Stylesheet" type="text/css"/>\n| 
    291304      end 
    292305      include_tag 
  • trunk/spec/merb/view_context_spec.rb

    r1063 r1090  
    1414  it "should render local image" do 
    1515    image_tag('foo.gif').clean.should == %[<img src="/images/foo.gif"/>].clean 
     16  end 
     17 
     18  it "should render a local image with a path_prefix" do 
     19    Merb::Server.config[:path_prefix] = '/inky' 
     20    image_tag('foo.gif').clean.should == %[<img src="/inky/images/foo.gif"/>].clean 
     21    Merb::Server.config.delete(:path_prefix) 
    1622  end 
    1723   
     
    4854    css_include_tag('bar') 
    4955  end 
     56   
     57  it "should render a link tag with a path_prefix" do 
     58    Merb::Server.config[:path_prefix] = '/inky' 
     59    css_include_tag('foo.css').clean.should == 
     60      %[<link href="/inky/stylesheets/foo.css" media="all" rel="Stylesheet" type="text/css"/>].clean 
     61    Merb::Server.config.delete(:path_prefix) 
     62  end 
     63   
    5064  it "should not generate a script tag with the include_required_css" do 
    5165    include_required_css.clean.should == '' 
    52 end 
     66  end 
     67   
    5368  it "should generate script tags with the include_required_css" do 
    5469    require_css('foo') 
     
    7287    js_include_tag('bar') 
    7388  end 
     89   
     90  it "should render a script tag with a path_prefix" do 
     91    Merb::Server.config[:path_prefix] = '/inky' 
     92    js_include_tag('foo.js').clean.should == 
     93      %[<script src="/inky/javascripts/foo.js" type="text/javascript">//</script>].clean 
     94    Merb::Server.config.delete(:path_prefix) 
     95  end 
     96   
    7497  it "should not generate a script tag with the include_required_js" do 
    7598    include_required_js.clean.should == '' 
    76 end 
     99  end 
     100   
    77101  it "should generate script tags with the include_required_js" do 
    78102    require_js('foo')