Skip to content

Loading…

Add an option for Throw in the JS File. #14

Merged
merged 1 commit into from

2 participants

@damln

That can be very useful. I don't watch my terminal while doing things in the browser.
This can output the CoffeeScript compilation error message directly in the output JS file.

So, I can have it in my Firebug / Web Inspector JS console :)

@netzpirat netzpirat merged commit 121796e into netzpirat:master
@netzpirat
Owner

That's a very nice idea! Thanks a lot.

@damln

Hehe. You're welcome ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 21, 2012
  1. @damln
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
Something went wrong with that request. Please try again.