Skip to content

Commit

Permalink
[Configuration] [Command Line] Whether to generate relative links to …
Browse files Browse the repository at this point in the history
…assets is now controlled by a separate configuration flag and can be set via a command-line switch.
  • Loading branch information
chriseppstein committed Jul 6, 2009
1 parent a6bc874 commit 956c437
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
3 changes: 1 addition & 2 deletions examples/blueprint_default/config.rb
Expand Up @@ -4,5 +4,4 @@
sass_dir = "src"
images_dir = "images"
output_style = :compact
# To enable relative image paths using the images_url() function:
http_images_path = :relative
relative_assets = true
5 changes: 2 additions & 3 deletions examples/blueprint_plugins/config.rb
Expand Up @@ -4,6 +4,5 @@
sass_dir = "src"
images_dir = "images"
output_style = :compact
# To enable relative image paths using the images_url() function:
# http_images_path = :relative
http_images_path = :relative
relative_assets = true

3 changes: 1 addition & 2 deletions examples/blueprint_semantic/config.rb
Expand Up @@ -4,5 +4,4 @@
sass_dir = "src"
images_dir = "images"
output_style = :compact
# To enable relative image paths using the images_url() function:
http_images_path = :relative
relative_assets = true
3 changes: 1 addition & 2 deletions examples/compass/config.rb
Expand Up @@ -4,5 +4,4 @@
sass_dir = "src"
images_dir = "images"
output_style = :compact
# To enable relative image paths using the images_url() function:
http_images_path = :relative
relative_assets = true
23 changes: 23 additions & 0 deletions lib/compass/configuration.rb
Expand Up @@ -13,6 +13,7 @@ class Configuration
:javascripts_dir,
:output_style,
:environment,
:relative_assets,
:http_images_path,
:additional_import_paths,
:sass_options
Expand Down Expand Up @@ -44,6 +45,7 @@ def parse_string(contents, filename)
self.additional_import_paths ||= []
self.additional_import_paths += @added_import_paths
end
issue_deprecation_warnings
end

def set_all(options)
Expand Down Expand Up @@ -99,6 +101,21 @@ def comment_for_http_images_path
"# To enable relative image paths using the images_url() function:\n# http_images_path = :relative\n"
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
if environment == :development
:expanded
Expand Down Expand Up @@ -249,6 +266,12 @@ def reset!
self.required_libraries = []
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)
required_libraries << lib
super
Expand Down
4 changes: 4 additions & 0 deletions lib/compass/exec.rb
Expand Up @@ -184,6 +184,10 @@ def set_opts(opts)
self.options[:output_style] = style
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 'General Options:'

Expand Down
15 changes: 8 additions & 7 deletions test/configuration_test.rb
Expand Up @@ -18,9 +18,8 @@ def test_parse_and_serialize
images_dir = "img"
javascripts_dir = "js"
output_style = :nested
# To enable relative image paths using the images_url() function:
# http_images_path = :relative
http_images_path = "/images"
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
CONFIG

Compass.configuration.parse_string(contents, "test_parse")
Expand Down Expand Up @@ -82,8 +81,8 @@ def test_additional_import_paths
# Require any additional compass plugins here.
project_path = "/home/chris/my_compass_project"
css_dir = "css"
# To enable relative image paths using the images_url() function:
# http_images_path = :relative
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
additional_import_paths = ["../foo", "/path/to/my/framework"]
EXPECTED
assert_equal expected_serialization, Compass.configuration.serialize
Expand All @@ -101,10 +100,12 @@ def test_sass_options

expected_serialization = <<EXPECTED
# Require any additional compass plugins here.
# To enable relative image paths using the images_url() function:
# http_images_path = :relative
# Set this to the root of your project when deployed:
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true
sass_options = {:foo=>"bar"}
EXPECTED

assert_equal expected_serialization, Compass.configuration.serialize
end

Expand Down

0 comments on commit 956c437

Please sign in to comment.