be a bit more forgiving with reloader

This commit is contained in:
Sam 2015-02-27 17:19:30 +11:00
parent f555bbb416
commit b916108927

View file

@ -25,19 +25,22 @@ class Autospec::ReloadCss
def self.run_on_change(paths) def self.run_on_change(paths)
if paths.any? { |p| p =~ /\.(css|s[ac]ss)/ } if paths.any? { |p| p =~ /\.(css|s[ac]ss)/ }
# todo connect to dev instead?
ActiveRecord::Base.establish_connection
s = DiscourseStylesheets.new(:desktop) # TODO: what about mobile? s = DiscourseStylesheets.new(:desktop) # TODO: what about mobile?
s.compile s.compile
s.ensure_digestless_file s.ensure_digestless_file
ActiveRecord::Base.clear_active_connections!
paths << "public" + s.stylesheet_relpath_no_digest paths << "public" + s.stylesheet_relpath_no_digest
end end
paths.map! do |p| paths.map! do |p|
hash = nil hash = nil
fullpath = "#{Rails.root}/#{p}" fullpath = "#{Rails.root}/#{p}"
hash = Digest::MD5.hexdigest(File.read(fullpath)) if File.exists?(fullpath) hash = Digest::MD5.hexdigest(File.read(fullpath)) if File.exists?(fullpath)
p = p.sub /\.sass\.erb/, "" p = p.sub(/\.sass\.erb/, "")
p = p.sub /\.sass/, "" p = p.sub(/\.sass/, "")
p = p.sub /\.scss/, "" p = p.sub(/\.scss/, "")
p = p.sub /^app\/assets\/stylesheets/, "assets" p = p.sub(/^app\/assets\/stylesheets/, "assets")
{ name: p, hash: hash } { name: p, hash: hash }
end end
message_bus.publish "/file-change", paths message_bus.publish "/file-change", paths