Permalink
Browse files

add an option for direct output in JS

  • Loading branch information...
1 parent 6a9df78 commit 458a10b2e549ceec9f9f5e26d733f94874048290 @damln damln committed Apr 21, 2012
Showing with 14 additions and 1 deletion.
  1. +5 −1 README.md
  2. +1 −0 lib/guard/coffeescript.rb
  3. +8 −0 lib/guard/coffeescript/runner.rb
View
6 README.md
@@ -162,7 +162,7 @@ There following options can be passed to Guard::CoffeeScript:
```ruby
:input => 'coffeescripts' # Relative path to the input directory.
- # A suffix `/(.+\.coffee)` will be added to this option.
+ # A suffix /(.+\.coffee) will be added to this option.
# default: nil
:output => 'javascripts' # Relative path to the output directory.
@@ -183,6 +183,10 @@ There following options can be passed to Guard::CoffeeScript:
:all_on_start => true # Regenerate all files on startup
# default: false
+
+:error_to_js => true # Print the Coffeescript error message directly in the
+ # JavaScript file
+ # default: false
```
### Output short notation
View
1 lib/guard/coffeescript.rb
@@ -18,6 +18,7 @@ class CoffeeScript < Guard
:shallow => false,
:hide_success => false,
:noop => false,
+ :error_to_js => false,
:all_on_start => false
}
View
8 lib/guard/coffeescript/runner.rb
@@ -60,6 +60,14 @@ def compile_files(files, watchers, options)
changed_files << write_javascript_file(content, file, directory, options)
rescue => e
error_message = file + ': ' + e.message.to_s
+
+ if options[:error_to_js]
+ js_error_message = %q(#{error_message})
+ js_error_message = "var message = \"#{error_message} \";"
+ js_error_message += "throw message;"
+ changed_files << write_javascript_file(js_error_message, file, directory, options)
+ end
+
errors << error_message
Formatter.error(error_message)
end

0 comments on commit 458a10b

Please sign in to comment.