From a61360688cd0e1f43f523866384d0d0796a4ea73 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Mar 2005 22:02:22 +0000 Subject: Changed .htaccess to allow dispatch.* to be called from a sub-directory as part of the push with Action Pack to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke] Fixed routing and helpers to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@945 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/asset_tag_helper.rb | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 6328ff6f71..f6159e5246 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -33,8 +33,7 @@ module ActionView # def javascript_include_tag(*sources) sources.collect { |source| - source = "/javascripts/#{source}" unless source.include?("/") - source = "#{source}.js" unless source.include?(".") + source = compute_public_path(source, 'javascripts', 'js') content_tag("script", "", "language" => "JavaScript", "type" => "text/javascript", "src" => source) }.join("\n") end @@ -49,8 +48,7 @@ module ActionView # def stylesheet_link_tag(*sources) sources.collect { |source| - source = "/stylesheets/#{source}" unless source.include?("/") - source = "#{source}.css" unless source.include?(".") + source = compute_public_path(source, 'stylesheets', 'css') tag("link", "rel" => "Stylesheet", "type" => "text/css", "media" => "screen", "href" => source) }.join("\n") end @@ -64,13 +62,11 @@ module ActionView # * full path, like "/my_images/image.gif" # * file name, like "rss.gif", that gets expanded to "/images/rss.gif" # * file name without extension, like "logo", that gets expanded to "/images/logo.png" - def image_tag(src, options = {}) + def image_tag(source, options = {}) options.symbolize_keys - - options.update({ :src => src.include?("/") ? src : "/images/#{src}" }) - options[:src] += ".png" unless options[:src].include?(".") - - options[:alt] ||= src.split("/").last.split(".").first.capitalize + + options[:src] = compute_public_path(source, 'images', 'png') + options[:alt] ||= source.split("/").last.split(".").first.capitalize if options[:size] options[:width], options[:height] = options[:size].split("x") @@ -79,6 +75,16 @@ module ActionView tag("img", options) end + + private + + def compute_public_path(source, dir, ext) + source = "/#{dir}/#{source}" unless source.include?("/") + source = "#{source}.#{ext}" unless source.include?(".") + source = "#{@request.relative_url_root}#{source}" + source + end + end end end -- cgit v1.2.3