sinatra-coffee 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/coffee.rb +14 -8
- metadata +2 -2
data/lib/sinatra/coffee.rb
CHANGED
@@ -10,16 +10,22 @@ end
|
|
10
10
|
|
11
11
|
|
12
12
|
class CoffeeTemplate < Tilt::Template
|
13
|
+
class << self
|
14
|
+
attr_accessor :coffee_path
|
15
|
+
end
|
16
|
+
|
13
17
|
def initialize_engine
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
unless self.class.coffee_path
|
19
|
+
ENV['PATH'].split(':').each do |p|
|
20
|
+
coffee_path = File.join(p, 'coffee')
|
21
|
+
if File.executable?(coffee_path)
|
22
|
+
self.class.coffee_path = coffee_path
|
23
|
+
break
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
22
|
-
raise StandardError, 'Unable to find "coffee" executable in your PATH' unless
|
28
|
+
raise StandardError, 'Unable to find "coffee" executable in your PATH' unless File.executable?(self.class.coffee_path)
|
23
29
|
end
|
24
30
|
|
25
31
|
def prepare
|
@@ -29,12 +35,12 @@ class CoffeeTemplate < Tilt::Template
|
|
29
35
|
compiled = nil
|
30
36
|
error_message = nil
|
31
37
|
|
32
|
-
Open3.popen3(
|
38
|
+
Open3.popen3(self.class.coffee_path, '-s', '-p', '--no-wrap') do |stdin, stdout, stderr, waitth|
|
33
39
|
stdin.write(data)
|
34
40
|
stdin.close_write
|
35
41
|
compiled = stdout.read
|
36
42
|
error_message = stderr.read
|
37
|
-
raise
|
43
|
+
raise "CoffeeScript compile failed. #{error_message}" unless waitth.value == 0
|
38
44
|
end
|
39
45
|
|
40
46
|
compiled
|