From 380c7773b732059d5a8a364f34e9bd16d5923cd5 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Mon, 5 Jul 2010 14:39:57 -0700 Subject: [PATCH] [Sass] Properly handle drive-letter paths. Closes gh-191 --- doc-src/SASS_CHANGELOG.md | 5 +++++ lib/haml/exec.rb | 30 ++++++++++++++++++++++++------ lib/haml/util.rb | 11 +++++++++++ lib/sass/plugin.rb | 3 +-- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 1dbebd82..d88b526c 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -3,6 +3,11 @@ * Table of contents {:toc} +## 3.0.14 (Unreleased) + +* Properly parse paths with drive letters on Windows (e.g. `C:\Foo\Bar.sass`) + in the Sass executable. + ## 3.0.13 [Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.12). diff --git a/lib/haml/exec.rb b/lib/haml/exec.rb index 096a69b0..1b2542de 100644 --- a/lib/haml/exec.rb +++ b/lib/haml/exec.rb @@ -1,6 +1,5 @@ require 'optparse' require 'fileutils' -require 'rbconfig' module Haml # This module handles the various Haml executables (`haml`, `sass`, `sass-convert`, etc). @@ -80,7 +79,7 @@ module Haml @options[:trace] = true end - if RbConfig::CONFIG['host_os'] =~ /mswin|windows/i + if ::Haml::Util.windows? opts.on('--unix-newlines', 'Use Unix-style newlines in written files.') do @options[:unix_newlines] = true end @@ -338,9 +337,9 @@ END # and runs the Sass compiler appropriately. def process_result if !@options[:update] && !@options[:watch] && - @args.first && @args.first.include?(':') + @args.first && colon_path?(@args.first) if @args.size == 1 - @args = @args.first.split(':', 2) + @args = split_colon_path(@args.first) else @options[:update] = true end @@ -389,7 +388,10 @@ END ::Sass::Plugin.options.merge! @options[:for_engine] ::Sass::Plugin.options[:unix_newlines] = @options[:unix_newlines] - if @args[1] && !@args[0].include?(':') + p [colon_path?(@args[0]), split_colon_path(@args[0])] + exit + + if @args[1] && !colon_path?(@args[0]) flag = @options[:update] ? "--update" : "--watch" err = if !File.exist?(@args[1]) @@ -403,7 +405,7 @@ File #{@args[1]} #{err}. MSG end - dirs, files = @args.map {|name| name.split(':', 2)}. + dirs, files = @args.map {|name| split_colon_path(name)}. partition {|i, _| File.directory? i} files.map! {|from, to| [from, to || from.gsub(/\..*?$/, '.css')]} dirs.map! {|from, to| [from, to || from]} @@ -437,6 +439,22 @@ MSG ::Sass::Plugin.watch(files) end + + def colon_path?(path) + !split_colon_path(path)[1].nil? + end + + def split_colon_path(path) + one, two = path.split(':', 2) + if one && two && #::Haml::Util.windows? && + one =~ /\A[A-Za-z]\Z/ && two =~ /\A[\/\\]/ + # If we're on Windows and we were passed a drive letter path, + # don't split on that colon. + one2, two = two.split(':', 2) + one = one + ':' + one2 + end + return one, two + end end # The `haml` executable. diff --git a/lib/haml/util.rb b/lib/haml/util.rb index 98c5308d..00134a11 100644 --- a/lib/haml/util.rb +++ b/lib/haml/util.rb @@ -3,6 +3,8 @@ require 'set' require 'enumerator' require 'stringio' require 'strscan' +require 'rbconfig' + require 'haml/root' require 'haml/util/subset_map' @@ -366,6 +368,15 @@ module Haml return ActionView::SafeBuffer end + ## Cross-OS Compatibility + + # Whether or not this is running on Windows. + # + # @return [Boolean] + def windows? + RbConfig::CONFIG['host_os'] =~ /mswin|windows/i + end + ## Cross-Ruby-Version Compatibility # Whether or not this is running under Ruby 1.8 or lower. diff --git a/lib/sass/plugin.rb b/lib/sass/plugin.rb index 071acc1a..edf4053b 100644 --- a/lib/sass/plugin.rb +++ b/lib/sass/plugin.rb @@ -1,5 +1,4 @@ require 'fileutils' -require 'rbconfig' require 'sass' require 'sass/plugin/configuration' @@ -228,7 +227,7 @@ module Sass # Finally, write the file flag = 'w' - flag = 'wb' if RbConfig::CONFIG['host_os'] =~ /mswin|windows/i && options[:unix_newlines] + flag = 'wb' if Haml::Util.windows? && options[:unix_newlines] File.open(css, flag) {|file| file.print(result)} end