Skip to content

Commit

Permalink
add an option for direct output in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Le Nouaille committed Apr 21, 2012
1 parent 6a9df78 commit 458a10b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -162,7 +162,7 @@ There following options can be passed to Guard::CoffeeScript:


```ruby ```ruby
:input => 'coffeescripts' # Relative path to the input directory. :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 # default: nil


:output => 'javascripts' # Relative path to the output directory. :output => 'javascripts' # Relative path to the output directory.
Expand All @@ -183,6 +183,10 @@ There following options can be passed to Guard::CoffeeScript:


:all_on_start => true # Regenerate all files on startup :all_on_start => true # Regenerate all files on startup
# default: false # default: false

:error_to_js => true # Print the Coffeescript error message directly in the
# JavaScript file
# default: false
``` ```


### Output short notation ### Output short notation
Expand Down
1 change: 1 addition & 0 deletions lib/guard/coffeescript.rb
Expand Up @@ -18,6 +18,7 @@ class CoffeeScript < Guard
:shallow => false, :shallow => false,
:hide_success => false, :hide_success => false,
:noop => false, :noop => false,
:error_to_js => false,
:all_on_start => false :all_on_start => false
} }


Expand Down
8 changes: 8 additions & 0 deletions lib/guard/coffeescript/runner.rb
Expand Up @@ -60,6 +60,14 @@ def compile_files(files, watchers, options)
changed_files << write_javascript_file(content, file, directory, options) changed_files << write_javascript_file(content, file, directory, options)
rescue => e rescue => e
error_message = file + ': ' + e.message.to_s 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 errors << error_message
Formatter.error(error_message) Formatter.error(error_message)
end end
Expand Down

0 comments on commit 458a10b

Please sign in to comment.