mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Properly handle drive-letter paths.
Closes gh-191
This commit is contained in:
parent
d66f088e5f
commit
380c7773b7
4 changed files with 41 additions and 8 deletions
|
@ -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).
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue