Permalink
Browse files

Added support for external templates system

  • Loading branch information...
1 parent 0d875aa commit 5abc03457e1bdc3e36f9392b913cf6130c33141d @sdrdis sdrdis committed Jan 4, 2013
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/guard/templates.rb
View
@@ -58,15 +58,15 @@ def run_on_change(paths)
dir = Pathname.new(target[:path]).dirname.to_s
FileUtils.mkdir_p(dir) if !File.exist?(dir)
File.open(target[:path], 'w') do |f|
- f.write("#{@options[:namespace]}['#{target[:name]}'] = #{compile(contents, target[:type])}")
+ f.write("#{@options[:namespace]}['#{target[:name]}'] = #{compile(contents, target)}")
end
end
end
end
end
if @single_file_mode
File.open(@options[:output], 'w') do |f|
- js = templates.map{|target,content| "#{target[:name].dump}: #{compile(content, target[:type])}" }.join(",\n")
+ js = templates.map{|target,content| "#{target[:name].dump}: #{compile(content, target)}" }.join(",\n")
f.write "#{@options[:namespace]}.templates = {#{js}}"
end
end
@@ -103,11 +103,17 @@ def get_target(path, watcher)
end
end
- def compile(str, type)
+ def compile(str, target)
+ type = target[:type]
if Compilers.methods.include?("compile_#{type}")
Compilers.send("compile_#{type}", str)
else
- str.dump
+ begin
+ require "guard/templates/#{type}/compiler"
+ return Templates.const_get(type.capitalize)::Compiler.compile(str, target)
+ rescue LoadError
+ return str.dump
+ end
end
end

0 comments on commit 5abc034

Please sign in to comment.