coffee-script-pure 0.0.1
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/lib/coffee-script-pure.rb +46 -0
- data/lib/coffee-script.tsz +0 -0
- metadata +58 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require "twostroke"
|
2
|
+
require "zlib"
|
3
|
+
|
4
|
+
module CoffeeScriptPure
|
5
|
+
class EngineError < StandardError; end
|
6
|
+
class CompilationError < StandardError; end
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
twostroke_vm.global_scope.get_var "CoffeeScript"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.twostroke_vm
|
13
|
+
unless defined? @@twostroke_vm
|
14
|
+
# twostroke is dog slow at parsing/compiling,
|
15
|
+
# so here's some bytecode I prepared earlier!
|
16
|
+
path = File.expand_path "../coffee-script.tsz", __FILE__
|
17
|
+
bytecode = Marshal.load Zlib.inflate File.read path
|
18
|
+
|
19
|
+
@@twostroke_vm = Twostroke::Runtime::VM.new bytecode
|
20
|
+
Twostroke::Runtime::Lib.setup_environment @@twostroke_vm
|
21
|
+
@@twostroke_vm.execute
|
22
|
+
end
|
23
|
+
@@twostroke_vm
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.version
|
27
|
+
@@version ||= instance.get("VERSION").string
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.compile(src, opts = {})
|
31
|
+
src = src.read if src.respond_to? :read
|
32
|
+
js_src = Twostroke::Runtime::Types::String.new src
|
33
|
+
js_opts = Twostroke::Runtime::Types::Object.new
|
34
|
+
if opts[:bare] or opts[:no_wrap]
|
35
|
+
js_opts.put "bare", Twostroke::Runtime::Types::Boolean.true
|
36
|
+
end
|
37
|
+
ex = catch :exception do
|
38
|
+
retn = instance.get("compile").call(nil, instance, [js_src, js_opts])
|
39
|
+
return retn.string
|
40
|
+
end
|
41
|
+
# if we're here, an exception was thrown javascript-side
|
42
|
+
to_str = ex.get("toString").call(nil, ex, [])
|
43
|
+
mesg = Twostroke::Runtime::Types.to_string(to_str).string
|
44
|
+
raise CompilationError, mesg
|
45
|
+
end
|
46
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coffee-script-pure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Charlie Somerville
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2010-01-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: twostroke
|
16
|
+
requirement: &2153257360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153257360
|
25
|
+
description: coffee-script pure uses the Twostroke Javascript interpreter to run the
|
26
|
+
CoffeeScript compiler inside Ruby
|
27
|
+
email: charlie@charliesomerville.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- lib/coffee-script-pure.rb
|
33
|
+
- lib/coffee-script.tsz
|
34
|
+
homepage: https://github.com/charliesome/coffee-script-pure
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
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
|
+
version: 1.9.2
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.10
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: A CoffeeScript compiler is pure Ruby
|
58
|
+
test_files: []
|