class Haml::Exec::Sass
def watch_or_update
def watch_or_update require 'sass' require 'sass/plugin' ::Sass::Plugin.options.merge! @options[:for_engine] ::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 {@args[1]} #{err}. you mean: sass #{flag} #{@args[0]}:#{@args[1]} end dirs, files = @args.map {|name| name.split(':', 2)}. partition {|i, _| File.directory? i} files.map! {|from, to| [from, to || from.gsub(/\..*?$/, '.css')]} dirs.map! {|from, to| [from, to || from]} ::Sass::Plugin.options[:template_location] = dirs ::Sass::Plugin.on_updating_stylesheet do |_, css| if File.exists? css puts_action :overwrite, :yellow, css else puts_action :create, :green, css end 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, _, _| raise error unless error.is_a?(::Sass::SyntaxError) puts_action :error, :red, "#{error.sass_filename} (Line #{error.sass_line}: #{error.message})" end if @options[:update] ::Sass::Plugin.update_stylesheets(files) return end puts ">>> Sass is watching for changes. Press Ctrl-C to stop." ::Sass::Plugin.on_template_modified {|template| puts ">>> Change detected to: #{template}"} ::Sass::Plugin.on_template_created {|template| puts ">>> New template detected: #{template}"} ::Sass::Plugin.on_template_deleted {|template| puts ">>> Deleted template detected: #{template}"} ::Sass::Plugin.watch(files) end