[Configuration] [Command Line] Whether to generate relative links to assets is now controlled by a separate configuration flag and can be set via a command-line switch.

This commit is contained in:
Chris Eppstein 2009-07-03 18:42:16 -07:00
parent a6bc874cf6
commit 956c437fe9
7 changed files with 40 additions and 16 deletions

View File

@ -4,5 +4,4 @@ css_dir = "stylesheets"
sass_dir = "src" sass_dir = "src"
images_dir = "images" images_dir = "images"
output_style = :compact output_style = :compact
# To enable relative image paths using the images_url() function: relative_assets = true
http_images_path = :relative

View File

@ -4,6 +4,5 @@ css_dir = "stylesheets"
sass_dir = "src" sass_dir = "src"
images_dir = "images" images_dir = "images"
output_style = :compact output_style = :compact
# To enable relative image paths using the images_url() function: relative_assets = true
# http_images_path = :relative
http_images_path = :relative

View File

@ -4,5 +4,4 @@ css_dir = "stylesheets"
sass_dir = "src" sass_dir = "src"
images_dir = "images" images_dir = "images"
output_style = :compact output_style = :compact
# To enable relative image paths using the images_url() function: relative_assets = true
http_images_path = :relative

View File

@ -4,5 +4,4 @@ css_dir = "stylesheets"
sass_dir = "src" sass_dir = "src"
images_dir = "images" images_dir = "images"
output_style = :compact output_style = :compact
# To enable relative image paths using the images_url() function: relative_assets = true
http_images_path = :relative

View File

@ -13,6 +13,7 @@ module Compass
:javascripts_dir, :javascripts_dir,
:output_style, :output_style,
:environment, :environment,
:relative_assets,
:http_images_path, :http_images_path,
:additional_import_paths, :additional_import_paths,
:sass_options :sass_options
@ -44,6 +45,7 @@ module Compass
self.additional_import_paths ||= [] self.additional_import_paths ||= []
self.additional_import_paths += @added_import_paths self.additional_import_paths += @added_import_paths
end end
issue_deprecation_warnings
end end
def set_all(options) def set_all(options)
@ -99,6 +101,21 @@ module Compass
"# To enable relative image paths using the images_url() function:\n# http_images_path = :relative\n" "# To enable relative image paths using the images_url() function:\n# http_images_path = :relative\n"
end end
def relative_assets?
# the http_images_path is deprecated, but here for backwards compatibility.
relative_assets || http_images_path == :relative
end
def comment_for_relative_assets
unless relative_assets
%q{# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
}
else
""
end
end
def default_output_style def default_output_style
if environment == :development if environment == :development
:expanded :expanded
@ -249,6 +266,12 @@ module Compass
self.required_libraries = [] self.required_libraries = []
end end
def issue_deprecation_warnings
if http_images_path == :relative
puts "DEPRECATION WARNING: Please set relative_assets = true to enable relative paths."
end
end
def require(lib) def require(lib)
required_libraries << lib required_libraries << lib
super super

View File

@ -184,6 +184,10 @@ END
self.options[:output_style] = style self.options[:output_style] = style
end end
opts.on('--relative-assets', :NONE, 'Make compass asset helpers generate relative urls to assets.') do
self.options[:relative_assets] = true
end
opts.separator '' opts.separator ''
opts.separator 'General Options:' opts.separator 'General Options:'

View File

@ -18,9 +18,8 @@ class ConfigurationTest < Test::Unit::TestCase
images_dir = "img" images_dir = "img"
javascripts_dir = "js" javascripts_dir = "js"
output_style = :nested output_style = :nested
# To enable relative image paths using the images_url() function: # To enable relative paths to assets via compass helper functions. Uncomment:
# http_images_path = :relative # relative_assets = true
http_images_path = "/images"
CONFIG CONFIG
Compass.configuration.parse_string(contents, "test_parse") Compass.configuration.parse_string(contents, "test_parse")
@ -82,8 +81,8 @@ class ConfigurationTest < Test::Unit::TestCase
# Require any additional compass plugins here. # Require any additional compass plugins here.
project_path = "/home/chris/my_compass_project" project_path = "/home/chris/my_compass_project"
css_dir = "css" css_dir = "css"
# To enable relative image paths using the images_url() function: # To enable relative paths to assets via compass helper functions. Uncomment:
# http_images_path = :relative # relative_assets = true
additional_import_paths = ["../foo", "/path/to/my/framework"] additional_import_paths = ["../foo", "/path/to/my/framework"]
EXPECTED EXPECTED
assert_equal expected_serialization, Compass.configuration.serialize assert_equal expected_serialization, Compass.configuration.serialize
@ -101,10 +100,12 @@ EXPECTED
expected_serialization = <<EXPECTED expected_serialization = <<EXPECTED
# Require any additional compass plugins here. # Require any additional compass plugins here.
# To enable relative image paths using the images_url() function: # Set this to the root of your project when deployed:
# http_images_path = :relative # To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
sass_options = {:foo=>"bar"} sass_options = {:foo=>"bar"}
EXPECTED EXPECTED
assert_equal expected_serialization, Compass.configuration.serialize assert_equal expected_serialization, Compass.configuration.serialize
end end