Bug fix: make the path-based configuration really work right.

This commit is contained in:
Chris Eppstein 2010-08-25 08:39:59 -07:00
parent 64a5527ecf
commit ec648f17b0
6 changed files with 73 additions and 37 deletions

View File

@ -108,6 +108,18 @@ command line will override the corresponding settings in your configuration file
Defaults to <code>"stylesheets"</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>css_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full path to where css stylesheets are kept.
Defaults to <code>&lt;project_path&gt;/&lt;css_dir&gt;</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>http_stylesheets_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full http path to stylesheets on the web server. Defaults to <code>http_path + "/" + css_dir</code>. </td>
</tr>
<tr>
<td style="vertical-align:top;"><code>sass_dir</code> </td>
<td style="vertical-align:top;">String </td>
@ -115,6 +127,13 @@ command line will override the corresponding settings in your configuration file
It is relative to the <code>project_path</code>. Defaults to <code>"src"</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>sass_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full path to where sass stylesheets are kept.
Defaults to <code>&lt;project_path&gt;/&lt;sass_dir&gt;</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>images_dir</code> </td>
<td style="vertical-align:top;">String </td>
@ -123,6 +142,20 @@ command line will override the corresponding settings in your configuration file
Defaults to <code>"images"</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>images_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full path to where images are kept.
Defaults to <code>&lt;project_path&gt;/&lt;images_dir&gt;</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>http_images_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full http path to images on the web server.
Defaults to <code>http_path + "/" + images_dir</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>javascripts_dir</code> </td>
<td style="vertical-align:top;">String </td>
@ -131,6 +164,20 @@ command line will override the corresponding settings in your configuration file
<code>"javascripts"</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>javascripts_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full path to where javascripts are kept.
Defaults to <code>&lt;project_path&gt;/&lt;javascripts_dir&gt;</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>http_javascripts_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full http path to javascripts on the web server.
Defaults to <code>http_path + "/" + javascripts_dir</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>output_style</code> </td>
<td style="vertical-align:top;">Symbol </td>
@ -147,25 +194,6 @@ command line will override the corresponding settings in your configuration file
using the http path for that asset type.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>http_images_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full http path to images on the web server.
Defaults to <code>http_path + "/" + images_dir</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>http_stylesheets_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full http path to stylesheets on the web server. Defaults to <code>http_path + "/" + css_dir</code>. </td>
</tr>
<tr>
<td style="vertical-align:top;"><code>http_javascripts_path</code> </td>
<td style="vertical-align:top;">String </td>
<td style="vertical-align:top;">The full http path to javascripts on the web server.
Defaults to <code>http_path + "/" + javascripts_dir</code>.
</td>
</tr>
<tr>
<td style="vertical-align:top;"><code>additional_import_paths</code> </td>
<td style="vertical-align:top;">Array of Strings </td>

View File

@ -53,8 +53,8 @@ module Compass
:dry_run => options[:dry_run])
compiler_opts.merge!(additional_options)
Compass::Compiler.new(working_path,
projectize(Compass.configuration.sass_dir),
projectize(Compass.configuration.css_dir),
Compass.configuration.sass_path,
Compass.configuration.css_path,
compiler_opts)
end

View File

@ -44,43 +44,43 @@ module Compass
def default_sass_path
if (pp = top_level.project_path) && (dir = top_level.sass_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end
def default_css_path
if (pp = top_level.project_path) && (dir = top_level.css_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end
def default_images_path
if (pp = top_level.project_path) && (dir = top_level.images_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end
def default_javascripts_path
if (pp = top_level.project_path) && (dir = top_level.javascripts_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end
def default_extensions_path
if (pp = top_level.project_path) && (dir = top_level.extensions_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end
def default_fonts_path
if (pp = top_level.project_path) && (dir = top_level.fonts_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end
def default_cache_path
if (pp = top_level.project_path) && (dir = top_level.cache_dir)
File.join(pp, dir)
Compass.projectize(dir, pp)
end
end

View File

@ -6,6 +6,7 @@ require 'compass/actions'
require 'compass/installers'
require 'compass/commands'
require 'rbconfig'
require 'pathname'
begin
require 'win32console' if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
rescue LoadError

View File

@ -3,6 +3,14 @@ module Compass::Exec::ProjectOptionsParser
super
set_project_options(opts)
end
def set_dir_or_path(type, dir)
if Pathname.new(dir).absolute?
self.options[:"#{type}_path"] = dir.tr('\\','/')
else
self.options[:"#{type}_dir"] = dir.tr('\\','/')
end
end
def set_project_options(opts)
opts.on('-c', '--config CONFIG_FILE', 'Specify the location of the configuration file explicitly.') do |configuration_file|
self.options[:configuration_file] = configuration_file
@ -13,19 +21,19 @@ module Compass::Exec::ProjectOptionsParser
end
opts.on('--sass-dir SRC_DIR', "The source directory where you keep your sass stylesheets.") do |sass_dir|
self.options[:sass_dir] = sass_dir.tr('\\','/')
set_dir_or_path(:sass, sass_dir)
end
opts.on('--css-dir CSS_DIR', "The target directory where you keep your css stylesheets.") do |css_dir|
self.options[:css_dir] = css_dir.tr('\\','/')
set_dir_or_path(:css, css_dir)
end
opts.on('--images-dir IMAGES_DIR', "The directory where you keep your images.") do |images_dir|
self.options[:images_dir] = images_dir.tr('\\','/')
set_dir_or_path(:images, images_dir)
end
opts.on('--javascripts-dir JS_DIR', "The directory where you keep your javascripts.") do |javascripts_dir|
self.options[:javascripts_dir] = javascripts_dir.tr('\\','/')
set_dir_or_path(:javascripts, javascripts_dir)
end
opts.on('-e ENV', '--environment ENV', [:development, :production], 'Use sensible defaults for your current environment.',

View File

@ -4,7 +4,7 @@ module Compass::SassExtensions::Functions::Urls
# Compute the path to the stylesheet, either root relative or stylesheet relative
# or nil if the http_images_path is not set in the configuration.
http_stylesheets_path = if relative?
compute_relative_path(Compass.configuration.css_dir)
compute_relative_path(Compass.configuration.css_path)
elsif Compass.configuration.http_stylesheets_path
Compass.configuration.http_stylesheets_path
else
@ -30,7 +30,7 @@ module Compass::SassExtensions::Functions::Urls
# Compute the path to the font file, either root relative or stylesheet relative
# or nil if the http_fonts_path cannot be determined from the configuration.
http_fonts_path = if relative?
compute_relative_path(Compass.configuration.fonts_dir)
compute_relative_path(Compass.configuration.fonts_path)
else
Compass.configuration.http_fonts_path
end
@ -59,7 +59,7 @@ module Compass::SassExtensions::Functions::Urls
# Compute the path to the image, either root relative or stylesheet relative
# or nil if the http_images_path is not set in the configuration.
http_images_path = if relative?
compute_relative_path(Compass.configuration.images_dir)
compute_relative_path(Compass.configuration.images_path)
elsif Compass.configuration.http_images_path
Compass.configuration.http_images_path
else
@ -118,9 +118,8 @@ module Compass::SassExtensions::Functions::Urls
path[0..0] == "/" || path[0..3] == "http"
end
def compute_relative_path(dir)
def compute_relative_path(path)
if (target_css_file = options[:css_filename])
path = File.join(Compass.configuration.project_path, dir)
Pathname.new(path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
end
end