2013-07-09 22:16:56 -04:00
|
|
|
module Autospec; end
|
2013-11-01 18:57:50 -04:00
|
|
|
|
2013-07-09 22:16:56 -04:00
|
|
|
class Autospec::ReloadCss
|
|
|
|
|
2013-11-01 18:57:50 -04:00
|
|
|
WATCHERS = {}
|
2013-07-09 22:16:56 -04:00
|
|
|
def self.watch(pattern, &blk)
|
2013-11-01 18:57:50 -04:00
|
|
|
WATCHERS[pattern] = blk
|
2013-07-09 22:16:56 -04:00
|
|
|
end
|
|
|
|
|
2013-11-01 18:57:50 -04:00
|
|
|
# css, scss, sass or handlebars
|
2013-07-09 22:16:56 -04:00
|
|
|
watch(/\.css$/)
|
2013-11-01 18:57:50 -04:00
|
|
|
watch(/\.ca?ss\.erb$/)
|
|
|
|
watch(/\.s[ac]ss$/)
|
2013-07-09 22:16:56 -04:00
|
|
|
watch(/\.handlebars$/)
|
|
|
|
|
|
|
|
def self.message_bus
|
|
|
|
MessageBus::Instance.new.tap do |bus|
|
|
|
|
bus.site_id_lookup do
|
2013-11-01 18:57:50 -04:00
|
|
|
# this is going to be dev the majority of the time
|
|
|
|
# if you have multisite configured in dev stuff may be different
|
2013-07-09 22:16:56 -04:00
|
|
|
"default"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.run_on_change(paths)
|
|
|
|
paths.map! do |p|
|
|
|
|
hash = nil
|
2013-11-01 18:57:50 -04:00
|
|
|
fullpath = "#{Rails.root}/#{p}"
|
|
|
|
hash = Digest::MD5.hexdigest(File.read(fullpath)) if File.exists?(fullpath)
|
2013-07-09 22:16:56 -04:00
|
|
|
p = p.sub /\.sass\.erb/, ""
|
|
|
|
p = p.sub /\.sass/, ""
|
|
|
|
p = p.sub /\.scss/, ""
|
|
|
|
p = p.sub /^app\/assets\/stylesheets/, "assets"
|
2013-11-01 18:57:50 -04:00
|
|
|
{ name: p, hash: hash }
|
2013-07-09 22:16:56 -04:00
|
|
|
end
|
|
|
|
message_bus.publish "/file-change", paths
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|