mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] Add better UI for detecting syntax errors with --watch and --update.
This commit is contained in:
parent
b1dddb83a2
commit
2bb029bfcb
1 changed files with 15 additions and 9 deletions
|
@ -304,6 +304,20 @@ END
|
|||
require 'sass/plugin'
|
||||
::Sass::Plugin.options[:unix_newlines] = @options[:unix_newlines]
|
||||
|
||||
if @args[1] && !@args[0].include?(':')
|
||||
flag = @options[:update] ? "--update" : "--watch"
|
||||
err =
|
||||
if !File.exist?(@args[1])
|
||||
"doesn't exist"
|
||||
elsif @args[1] =~ /\.css$/
|
||||
"is a CSS file"
|
||||
end
|
||||
raise <<MSG if err
|
||||
File #{@args[1]} #{err}.
|
||||
Did you mean: sass #{flag} #{@args[0]}:#{@args[1]}
|
||||
MSG
|
||||
end
|
||||
|
||||
dirs, files = @args.map {|name| name.split(':', 2)}.
|
||||
map {|from, to| [from, to || from.gsub(/\..*?$/, '.css')]}.
|
||||
partition {|i, _| File.directory? i}
|
||||
|
@ -320,15 +334,7 @@ END
|
|||
::Sass::Plugin.on_creating_directory {|dirname| puts_action :directory, :green, dirname}
|
||||
::Sass::Plugin.on_deleting_css {|filename| puts_action :delete, :yellow, filename}
|
||||
::Sass::Plugin.on_compilation_error do |error, _, _|
|
||||
unless error.is_a?(::Sass::SyntaxError)
|
||||
if error.is_a?(Errno::ENOENT) && error.message =~ /^No such file or directory - (.*)$/ && $1 == @args[1]
|
||||
flag = @options[:update] ? "--update" : "--watch"
|
||||
error.message << "\n Did you mean: sass #{flag} #{@args[0]}:#{@args[1]}"
|
||||
end
|
||||
|
||||
raise error
|
||||
end
|
||||
|
||||
raise error unless error.is_a?(::Sass::SyntaxError)
|
||||
puts_action :error, :red, "#{error.sass_filename} (Line #{error.sass_line}: #{error.message})"
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue