forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjstcss.rb
32 lines (25 loc) · 904 Bytes
/
jstcss.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'guard'
require 'guard/guard'
require 'fileutils'
# The only thing this guard does is make sure to touch the
# handlebars file if you edit something in app/stylesheets.
# doing so will trigger the handlebars guard to regenerate the
# .handlebars file with the new css injected into
module Guard
class JSTCSS < Guard
def initialize(watchers = [], options = {})
watchers = [] if !watchers
if options[:input]
watchers << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options[:input]) }/(.+\.s[ca]ss)\z})
end
super(watchers, options)
end
def run_on_change(paths)
paths.each { |p| touch_handlebars_file(p) }
end
def touch_handlebars_file(sass_path)
hbs_path = sass_path.sub('stylesheets', 'views').sub(/\.([^\.]*)\z/, '.handlebars')
FileUtils.touch(hbs_path) if File.exist?(hbs_path)
end
end
end