coffee_compiler 0.9.4

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.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
@@ -0,0 +1,3 @@
1
+ [submodule "lib/coffee-script"]
2
+ path = lib/coffee-script
3
+ url = https://github.com/jashkenas/coffee-script.git
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in coffee_compiler.gemspec
4
+ gemspec
@@ -0,0 +1,29 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coffee_compiler (0.9.4)
5
+ therubyracer (~> 0.7.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.2)
11
+ rspec (2.1.0)
12
+ rspec-core (~> 2.1.0)
13
+ rspec-expectations (~> 2.1.0)
14
+ rspec-mocks (~> 2.1.0)
15
+ rspec-core (2.1.0)
16
+ rspec-expectations (2.1.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.1.0)
19
+ therubyracer (0.7.5)
20
+ yard (0.6.2)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ coffee_compiler!
27
+ rspec (~> 2.0)
28
+ therubyracer (~> 0.7.0)
29
+ yard
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+ require 'rubygems'
4
+ require 'rspec/core/rake_task'
5
+ require 'yard'
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ desc "Run all examples"
10
+ RSpec::Core::RakeTask.new('spec')
11
+
12
+ YARD::Rake::YardocTask.new do |t|
13
+ t.files = ['lib/**/*.rb', 'README.rdoc']
14
+ #t.options = ['--any', '--extra', '--opts'] # optional
15
+ end
16
+
17
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "coffee_compiler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "coffee_compiler"
7
+ s.version = CoffeeCompiler::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jonas Nicklas", "Edithouse Elabs AB"]
10
+ s.email = ["jonas.nicklas@gmail.com"]
11
+ s.homepage = "http://github.com/jnicklas/coffee_compiler"
12
+ s.summary = %q{compile coffee script from ruby}
13
+ s.description = %q{compile coffee script from ruby}
14
+
15
+ s.rubyforge_project = "coffee_compiler"
16
+
17
+ s.add_runtime_dependency "therubyracer", "~> 0.7.0"
18
+ s.add_development_dependency "rspec", "~> 2.0"
19
+ s.add_development_dependency "yard"
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'v8'
2
+
3
+ class CoffeeCompiler
4
+ class SyntaxError < StandardError; end
5
+
6
+ attr_reader :code
7
+
8
+ def initialize(code)
9
+ @code = code
10
+ end
11
+
12
+ def compile
13
+ context['CoffeeScript'].compile(code)
14
+ rescue V8::JSError => e
15
+ raise CoffeeCompiler::SyntaxError, e.message
16
+ end
17
+
18
+ def eval
19
+ context.eval(compile)
20
+ end
21
+
22
+ def context
23
+ V8::Context.new do |context|
24
+ context.load(File.expand_path('coffee-script/extras/coffee-script.js', File.dirname(__FILE__)))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ class CoffeeCompiler
2
+ VERSION = "0.9.4"
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe CoffeeCompiler do
4
+ let :compiler do
5
+ CoffeeCompiler.new("triple = ((x) -> x * 3); return triple(6)")
6
+ end
7
+
8
+ let :invalid_compiler do
9
+ CoffeeCompiler.new("foo ( Bar -> '")
10
+ end
11
+
12
+ describe '#compile' do
13
+ it "compiles the coffeescript code" do
14
+ result = compiler.compile
15
+ result.should include('function')
16
+ V8::Context.new.eval(result).should == 18
17
+ end
18
+
19
+ it "raises an error when the code is invalid" do
20
+ expect { invalid_compiler.compile }.to raise_error(CoffeeCompiler::SyntaxError)
21
+ end
22
+ end
23
+
24
+ describe '#eval' do
25
+ it "evals the coffeescript code" do
26
+ compiler.eval.should == 18
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ require 'coffee_compiler'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coffee_compiler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 4
9
+ version: 0.9.4
10
+ platform: ruby
11
+ authors:
12
+ - Jonas Nicklas
13
+ - Edithouse Elabs AB
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-19 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: therubyracer
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ - 7
32
+ - 0
33
+ version: 0.7.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 2
46
+ - 0
47
+ version: "2.0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: yard
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: compile coffee script from ruby
64
+ email:
65
+ - jonas.nicklas@gmail.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - .gitmodules
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - Rakefile
78
+ - coffee_compiler.gemspec
79
+ - lib/coffee_compiler.rb
80
+ - lib/coffee_compiler/version.rb
81
+ - spec/coffee_compiler_spec.rb
82
+ - spec/spec_helper.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/jnicklas/coffee_compiler
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project: coffee_compiler
111
+ rubygems_version: 1.3.7
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: compile coffee script from ruby
115
+ test_files:
116
+ - spec/coffee_compiler_spec.rb
117
+ - spec/spec_helper.rb