Class: Guard::CoffeeScript

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/coffeescript.rb,
lib/guard/coffeescript/runner.rb,
lib/guard/coffeescript/formatter.rb,
lib/guard/coffeescript/inspector.rb

Overview

The CoffeeScript guard that gets notifications about the following Guard events: ‘start`, `stop`, `reload`, `run_all` and `run_on_change`.

Defined Under Namespace

Modules: Formatter, Inspector, Runner

Constant Summary collapse

DEFAULT_OPTIONS =
{
    :bare         => false,
    :shallow      => false,
    :hide_success => false,
    :noop         => false,
    :error_to_js  => false,
    :all_on_start => false,
    :source_map   => false
}

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ CoffeeScript

Initialize Guard::CoffeeScript.

Parameters:

  • watchers (Array<Guard::Watcher>) (defaults to: [])

    the watchers in the Guard block

  • options (Hash) (defaults to: {})

    the options for the Guard

Options Hash (options):

  • :input (String)

    the input directory

  • :output (String)

    the output directory

  • :bare (Boolean)

    do not wrap the output in a top level function

  • :shallow (Boolean)

    do not create nested directories

  • :hide_success (Boolean)

    hide success message notification

  • :all_on_start (Boolean)

    generate all JavaScripts files on start

  • :noop (Boolean)

    do not generate an output file

  • :source_map (Boolean)

    generate the source map files



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/guard/coffeescript.rb', line 39

def initialize(watchers = [], options = {})
  watchers = [] if !watchers
  defaults = DEFAULT_OPTIONS.clone

  if options[:input]
    defaults.merge!({ :output => options[:input] })
    watchers << ::Guard::Watcher.new(%r{^#{ options[:input] }/(.+\.(?:coffee|coffee\.md|litcoffee))$})
  end

  super(watchers, defaults.merge(options))
end

Instance Method Details

#run_allObject

Gets called when all files should be regenerated.

Raises:

  • (:task_has_failed)

    when stop has failed



63
64
65
# File 'lib/guard/coffeescript.rb', line 63

def run_all
  run_on_modifications(Watcher.match_files(self, Dir.glob('**{,/*/**}/*.{coffee,coffee.md,litcoffee}')))
end

#run_on_modifications(paths) ⇒ Object

Gets called when watched paths and files have changes.

Parameters:

  • paths (Array<String>)

    the changed paths and files

Raises:

  • (:task_has_failed)

    when stop has failed



72
73
74
75
76
# File 'lib/guard/coffeescript.rb', line 72

def run_on_modifications(paths)
  changed_files, success = Runner.run(Inspector.clean(paths), watchers, options)

  throw :task_has_failed unless success
end

#run_on_removals(paths) ⇒ Object

Called on file(s) deletions that the Guard watches.

Parameters:

  • paths (Array<String>)

    the deleted files or paths

Raises:

  • (:task_has_failed)

    when run_on_change has failed



83
84
85
# File 'lib/guard/coffeescript.rb', line 83

def run_on_removals(paths)
  Runner.remove(Inspector.clean(paths, :missing_ok => true), watchers, options)
end

#startObject

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when stop has failed



55
56
57
# File 'lib/guard/coffeescript.rb', line 55

def start
  run_all if options[:all_on_start]
end