guard-coffeescript 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +26 -8
- data/lib/guard/coffeescript.rb +1 -1
- data/lib/guard/coffeescript/inspector.rb +1 -1
- data/lib/guard/coffeescript/runner.rb +20 -21
- data/lib/guard/coffeescript/templates/Guardfile +1 -1
- data/lib/guard/coffeescript/version.rb +1 -1
- metadata +29 -22
- data/lib/guard/coffeescript/compiler.rb +0 -75
data/README.rdoc
CHANGED
@@ -20,11 +20,29 @@ Add guard definition to your Guardfile by running this command:
|
|
20
20
|
|
21
21
|
guard init coffeescript
|
22
22
|
|
23
|
-
==
|
23
|
+
== CoffeeScript
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
Guard::CoffeeScript uses {Ruby CoffeeScript}[http://github.com/josh/ruby-coffee-script/] to compile the CoffeeScripts.
|
26
|
+
This enables the guard to compile the CoffeeScripts with node.js, JavaScript Core or V8
|
27
|
+
|
28
|
+
=== node.js
|
29
|
+
|
30
|
+
Please refer to the {CoffeeScript documentation}[http://jashkenas.github.com/coffee-script/] for more information about
|
31
|
+
how to install the latest CoffeeScript version on node.js.
|
32
|
+
|
33
|
+
=== JavaScript Core
|
34
|
+
|
35
|
+
JavaScript Core is only available on Mac OS X. To use JavaScript Core you don't have to install anything, because
|
36
|
+
JavaScript Core is packaged with Mac OS X.
|
37
|
+
|
38
|
+
=== V8
|
39
|
+
|
40
|
+
To use CoffeeScript on V8, simple add `therubyracer` to your Gemfile. The Ruby Racer acts as a bridge between Ruby
|
41
|
+
and the V8 engine, that will be automatically installed by the Ruby Racer.
|
42
|
+
|
43
|
+
group :development do
|
44
|
+
gem 'therubyracer'
|
45
|
+
end
|
28
46
|
|
29
47
|
== Usage
|
30
48
|
|
@@ -38,13 +56,13 @@ Please read {guard doc}[http://github.com/guard/guard#readme] for more info abou
|
|
38
56
|
=== Standard ruby gems
|
39
57
|
|
40
58
|
guard 'coffeescript' do
|
41
|
-
watch(
|
59
|
+
watch(%r{coffeescripts/.+\.coffee})
|
42
60
|
end
|
43
61
|
|
44
62
|
=== Rails app
|
45
63
|
|
46
64
|
guard 'coffeescript', :output => 'public/javascripts/compiled' do
|
47
|
-
watch(
|
65
|
+
watch(%r{app/coffeescripts/.+\.coffee})
|
48
66
|
end
|
49
67
|
|
50
68
|
== Options
|
@@ -65,7 +83,7 @@ A file
|
|
65
83
|
|
66
84
|
that has been detected by the watch
|
67
85
|
|
68
|
-
watch(
|
86
|
+
watch(%r{app/coffeescripts/.+\.coffee})
|
69
87
|
|
70
88
|
with an output directory of
|
71
89
|
|
@@ -75,7 +93,7 @@ will be compiled to
|
|
75
93
|
|
76
94
|
public/javascripts/compiled/ui/buttons/toggle_button.js
|
77
95
|
|
78
|
-
This behaviour can be switched off by passing the option
|
96
|
+
This behaviour can be switched off by passing the option `:shallow => true` to the guard, so that all JavaScripts will
|
79
97
|
be compiled directly to the output directory.
|
80
98
|
|
81
99
|
== Development
|
data/lib/guard/coffeescript.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'coffee_script'
|
2
|
+
|
1
3
|
module Guard
|
2
|
-
class
|
4
|
+
class CoffeeScriptGuard
|
3
5
|
module Runner
|
4
6
|
class << self
|
5
7
|
|
@@ -9,8 +11,8 @@ module Guard
|
|
9
11
|
notify_result(changed_files, errors)
|
10
12
|
|
11
13
|
changed_files
|
12
|
-
rescue
|
13
|
-
::Guard::UI.error "
|
14
|
+
rescue CoffeeScript::EngineError => e
|
15
|
+
::Guard::UI.error "CoffeeScript engine error: " + e.message
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
@@ -27,9 +29,14 @@ module Guard
|
|
27
29
|
|
28
30
|
directories.each do |directory, scripts|
|
29
31
|
scripts.each do |file|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
begin
|
33
|
+
content = compile(file, options)
|
34
|
+
changed_files << process_compile_result(content, file, directory)
|
35
|
+
rescue CoffeeScript::CompilationError => e
|
36
|
+
error_message = file + ': ' + e.message
|
37
|
+
errors << error_message
|
38
|
+
::Guard::UI.error(error_message)
|
39
|
+
end
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
@@ -37,23 +44,15 @@ module Guard
|
|
37
44
|
end
|
38
45
|
|
39
46
|
def compile(file, options)
|
40
|
-
|
41
|
-
[content, $?.success?]
|
47
|
+
CoffeeScript.compile(File.read(file), options)
|
42
48
|
end
|
43
49
|
|
44
|
-
def process_compile_result(content, file, directory
|
45
|
-
if
|
46
|
-
|
47
|
-
|
48
|
-
File.open(File.expand_path(filename), 'w') { |f| f.write(content) }
|
50
|
+
def process_compile_result(content, file, directory)
|
51
|
+
FileUtils.mkdir_p(File.expand_path(directory)) if !File.directory?(directory)
|
52
|
+
filename = File.join(directory, File.basename(file.gsub(/coffee$/, 'js')))
|
53
|
+
File.open(File.expand_path(filename), 'w') { |f| f.write(content) }
|
49
54
|
|
50
|
-
|
51
|
-
else
|
52
|
-
errors << file + ': ' + content.split("\n").select { |line| line =~ /^Error:/ }.join("\n")
|
53
|
-
::Guard::UI.error(content)
|
54
|
-
|
55
|
-
nil
|
56
|
-
end
|
55
|
+
filename
|
57
56
|
end
|
58
57
|
|
59
58
|
def detect_nested_directories(watchers, files, options)
|
@@ -63,7 +62,7 @@ module Guard
|
|
63
62
|
|
64
63
|
watchers.product(files).each do |watcher, file|
|
65
64
|
if matches = file.match(watcher.pattern)
|
66
|
-
target = File.join(options[:output], File.dirname(matches[1])).gsub(/\/\.$/, '')
|
65
|
+
target = matches[1] ? File.join(options[:output], File.dirname(matches[1])).gsub(/\/\.$/, '') : options[:output]
|
67
66
|
if directories[target]
|
68
67
|
directories[target] << file
|
69
68
|
else
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-coffeescript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Michael Kessler
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-01-19 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 19
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 2
|
@@ -35,35 +33,33 @@ dependencies:
|
|
35
33
|
type: :runtime
|
36
34
|
version_requirements: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
36
|
+
name: coffee-script
|
39
37
|
prerelease: false
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
41
|
- - ~>
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 19
|
46
43
|
segments:
|
47
|
-
- 1
|
48
|
-
- 0
|
49
44
|
- 2
|
50
|
-
|
51
|
-
|
45
|
+
- 1
|
46
|
+
- 1
|
47
|
+
version: 2.1.1
|
48
|
+
type: :runtime
|
52
49
|
version_requirements: *id002
|
53
50
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
51
|
+
name: bundler
|
55
52
|
prerelease: false
|
56
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
54
|
none: false
|
58
55
|
requirements:
|
59
56
|
- - ~>
|
60
57
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 13
|
62
58
|
segments:
|
63
|
-
- 2
|
64
|
-
- 0
|
65
59
|
- 1
|
66
|
-
|
60
|
+
- 0
|
61
|
+
- 7
|
62
|
+
version: 1.0.7
|
67
63
|
type: :development
|
68
64
|
version_requirements: *id003
|
69
65
|
- !ruby/object:Gem::Dependency
|
@@ -74,14 +70,28 @@ dependencies:
|
|
74
70
|
requirements:
|
75
71
|
- - ~>
|
76
72
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 19
|
78
73
|
segments:
|
79
74
|
- 0
|
80
75
|
- 1
|
81
|
-
-
|
82
|
-
version: 0.1.
|
76
|
+
- 9
|
77
|
+
version: 0.1.9
|
83
78
|
type: :development
|
84
79
|
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 2
|
90
|
+
- 2
|
91
|
+
- 0
|
92
|
+
version: 2.2.0
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
85
95
|
description: Guard::CoffeeScript automatically generates your JavaScripts from your CoffeeScripts
|
86
96
|
email:
|
87
97
|
- michi@netzpiraten.ch
|
@@ -92,7 +102,6 @@ extensions: []
|
|
92
102
|
extra_rdoc_files: []
|
93
103
|
|
94
104
|
files:
|
95
|
-
- lib/guard/coffeescript/compiler.rb
|
96
105
|
- lib/guard/coffeescript/inspector.rb
|
97
106
|
- lib/guard/coffeescript/runner.rb
|
98
107
|
- lib/guard/coffeescript/templates/Guardfile
|
@@ -114,7 +123,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
123
|
requirements:
|
115
124
|
- - ">="
|
116
125
|
- !ruby/object:Gem::Version
|
117
|
-
hash: 3
|
118
126
|
segments:
|
119
127
|
- 0
|
120
128
|
version: "0"
|
@@ -123,7 +131,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
131
|
requirements:
|
124
132
|
- - ">="
|
125
133
|
- !ruby/object:Gem::Version
|
126
|
-
hash: 23
|
127
134
|
segments:
|
128
135
|
- 1
|
129
136
|
- 3
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module Guard
|
2
|
-
class CoffeeScript
|
3
|
-
|
4
|
-
# This has been kindly borrowed from https://github.com/josh/ruby-coffee-script/raw/master/lib/coffee_script.rb
|
5
|
-
# due to namespace conflicts with the guards own CoffeeScript class
|
6
|
-
#
|
7
|
-
# The only change to the original file is to redirect stderr to stdout when executing the compiler,
|
8
|
-
# so that the error messages can easily be parsed and sent to the Growl notifier.
|
9
|
-
#
|
10
|
-
module Compiler
|
11
|
-
class << self
|
12
|
-
def locate_coffee_bin
|
13
|
-
out = `which coffee`
|
14
|
-
if $?.success?
|
15
|
-
out.chomp
|
16
|
-
else
|
17
|
-
raise LoadError, "could not find `coffee` in PATH"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def coffee_bin
|
22
|
-
@@coffee_bin ||= locate_coffee_bin
|
23
|
-
end
|
24
|
-
|
25
|
-
def coffee_bin=(path)
|
26
|
-
@@coffee_bin = path
|
27
|
-
end
|
28
|
-
|
29
|
-
def version
|
30
|
-
`#{coffee_bin} --version`[/(\d|\.)+/]
|
31
|
-
end
|
32
|
-
|
33
|
-
# Compile a script (String or IO) to JavaScript.
|
34
|
-
def compile(script, options = {})
|
35
|
-
args = "-sp"
|
36
|
-
|
37
|
-
if options[:wrap] == false ||
|
38
|
-
options.key?(:bare) ||
|
39
|
-
options.key?(:no_wrap)
|
40
|
-
args += " --#{no_wrap_flag}"
|
41
|
-
end
|
42
|
-
|
43
|
-
execute_coffee(script, args)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Evaluate a script (String or IO) and return the stdout.
|
47
|
-
# Note: the first argument will be process.argv[3], the second
|
48
|
-
# process.argv[4], etc.
|
49
|
-
def evaluate(script, *args)
|
50
|
-
execute_coffee(script, "-s #{args.join(' ')}")
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
def execute_coffee(script, args)
|
55
|
-
command = "#{coffee_bin} #{args} 2>&1"
|
56
|
-
script = script.read if script.respond_to?(:read)
|
57
|
-
|
58
|
-
IO.popen(command, "w+") do |f|
|
59
|
-
f << script
|
60
|
-
f.close_write
|
61
|
-
f.read
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def no_wrap_flag
|
66
|
-
if `#{coffee_bin} --help`.lines.grep(/--no-wrap/).any?
|
67
|
-
'no-wrap'
|
68
|
-
else
|
69
|
-
'bare'
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|