sinatra-coffee 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/coffee.rb +44 -0
- metadata +64 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Sinatra::Templates
|
5
|
+
def coffee(template, options={}, locals={})
|
6
|
+
options[:layout] = false
|
7
|
+
render :coffee, template, options, locals
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class CoffeeTemplate < Tilt::Template
|
13
|
+
def initialize_engine
|
14
|
+
ENV['PATH'].split(':').each do |p|
|
15
|
+
coffee_path = File.join(p, 'coffee')
|
16
|
+
if File.executable?(coffee_path)
|
17
|
+
@@coffee_path = coffee_path
|
18
|
+
break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
raise StandardError, 'Unable to find "coffee" executable in your PATH' unless @@coffee_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepare
|
26
|
+
end
|
27
|
+
|
28
|
+
def evaluate(scope, locals, &block)
|
29
|
+
compiled = nil
|
30
|
+
error_message = nil
|
31
|
+
|
32
|
+
Open3.popen3(@@coffee_path, '-s', '-p') do |stdin, stdout, stderr, waitth|
|
33
|
+
stdin.write(data)
|
34
|
+
stdin.close_write
|
35
|
+
compiled = stdout.read
|
36
|
+
error_message = stderr.read
|
37
|
+
raise RuntimeError, "CoffeeScript compile failed. #{error_message}" unless waitth.value == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
compiled
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
Tilt.register 'coffee', CoffeeTemplate
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-coffee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dan Farino
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-07 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: dan@gyroscopetechnologies.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/sinatra/coffee.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage:
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Adds CoffeeScript rendering support to Sinatra
|
63
|
+
test_files: []
|
64
|
+
|