2013-06-29 00:56:18 +08:00
|
|
|
require 'guard'
|
|
|
|
require 'guard/guard'
|
2014-03-07 00:47:05 +08:00
|
|
|
require 'handlebars_tasks'
|
2013-06-29 00:56:18 +08:00
|
|
|
|
|
|
|
module Guard
|
|
|
|
class EmberTemplates < Guard
|
|
|
|
|
|
|
|
DEFAULT_OPTIONS = {
|
|
|
|
:hide_success => false,
|
|
|
|
:all_on_start => false
|
|
|
|
}
|
|
|
|
|
|
|
|
def initialize(watchers=[], options={})
|
|
|
|
super([::Guard::Watcher.new(/(app\/coffeescripts\/ember\/.*.hbs)\z/)], {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
run_all if options[:all_on_start]
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_on_change(paths)
|
|
|
|
paths.each do |path|
|
|
|
|
begin
|
|
|
|
UI.info "Compiling Ember template: #{path}"
|
2014-03-07 00:47:05 +08:00
|
|
|
HandlebarsTasks::EmberHbs.compile_file path
|
2013-06-29 00:56:18 +08:00
|
|
|
rescue Exception => e
|
|
|
|
::Guard::Notifier.notify(e.to_s, :title => path, :image => :failed)
|
2013-12-17 06:09:44 +08:00
|
|
|
UI.error "Error compiling: #{path}\n#{e}"
|
2013-06-29 00:56:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Gets called when all files should be regenerated.
|
|
|
|
#
|
|
|
|
# @raise [:task_has_failed] when stop has failed
|
|
|
|
#
|
|
|
|
def run_all
|
|
|
|
UI.info "Compiling all Ember templates"
|
|
|
|
files = Dir.glob("app/coffeescripts/**/*.hbs")
|
|
|
|
files.each do |file|
|
2014-03-07 00:47:05 +08:00
|
|
|
HandlebarsTasks::EmberHbs.compile_file(file)
|
2013-06-29 00:56:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def run_on_deletion(paths)
|
|
|
|
puts "TODO: run_on_deletion not implemented"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|