From db196ee12615f6651a13fee14880eda8d721aa49 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 10 Jul 2013 12:16:56 +1000 Subject: [PATCH] rake autospec should handle css file watching and reloading, guard is a bit pear shape at the moment --- lib/autospec/reload_css.rb | 40 ++++++++++++++++++++++++++++++++++++++ lib/autospec/runner.rb | 8 ++++++++ 2 files changed, 48 insertions(+) create mode 100644 lib/autospec/reload_css.rb diff --git a/lib/autospec/reload_css.rb b/lib/autospec/reload_css.rb new file mode 100644 index 00000000000..ab4d9f74dc3 --- /dev/null +++ b/lib/autospec/reload_css.rb @@ -0,0 +1,40 @@ +module Autospec; end +class Autospec::ReloadCss + + MATCHERS = {} + def self.watch(pattern, &blk) + MATCHERS[pattern] = blk + end + + watch(/tmp\/refresh_browser/) + watch(/\.css$/) + watch(/\.css\.erb$/) + watch(/\.sass$/) + watch(/\.scss$/) + watch(/\.sass\.erb$/) + watch(/\.handlebars$/) + + def self.message_bus + MessageBus::Instance.new.tap do |bus| + bus.site_id_lookup do + # this is going to be dev the majority of the time, if you have multisite configured in dev stuff may be different + "default" + end + end + end + + def self.run_on_change(paths) + paths.map! do |p| + hash = nil + fullpath = Rails.root.to_s + "/" + p + hash = Digest::MD5.hexdigest(File.read(fullpath)) if File.exists? fullpath + p = p.sub /\.sass\.erb/, "" + p = p.sub /\.sass/, "" + p = p.sub /\.scss/, "" + p = p.sub /^app\/assets\/stylesheets/, "assets" + {name: p, hash: hash} + end + message_bus.publish "/file-change", paths + end + +end diff --git a/lib/autospec/runner.rb b/lib/autospec/runner.rb index b7bb86da790..c0a35044e8f 100644 --- a/lib/autospec/runner.rb +++ b/lib/autospec/runner.rb @@ -1,6 +1,7 @@ require "drb/drb" require "thread" require "fileutils" +require "autospec/reload_css" module Autospec; end @@ -183,6 +184,13 @@ class Autospec::Runner end end end + Autospec::ReloadCss::MATCHERS.each do |k,v| + matches = [] + if k.match(file) + matches << file + end + Autospec::ReloadCss.run_on_change(matches) if matches.present? + end end queue_specs(specs) if hit rescue => e