ruby-dart2js 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +7 -0
- data/lib/dart2js.rb +69 -0
- data/lib/dart2js_exceptions.rb +12 -0
- data/test/test_dart2js.rb +30 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eec1f47b544a4e5f161403bd8507f8e9bbcc20e7
|
4
|
+
data.tar.gz: 8f908f6aafb56934d506b8ad871e48a9eac19619
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da2bc26526cc1a77680f4b0f833a417183768f7c3e4a4fc96bff5ec6e34a8aa21ed9014c62380985608dfc27934e0e711fa3d70b527fcd7aad721de2ddedb8c2
|
7
|
+
data.tar.gz: bfbeea171db0acd7cc48c68ef7de2030a1c9ed70608e7a77cea837aa03a472a5d4a572c1eea368eca71a8d67ed18c708b0f746fe2b4f72df8aa21854176f50c0
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/dart2js.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'dart2js_exceptions'
|
3
|
+
|
4
|
+
class Dart2Js < Sprockets::Processor
|
5
|
+
class << self
|
6
|
+
attr_writer :dart2js_binary
|
7
|
+
|
8
|
+
def dart2js_binary
|
9
|
+
@dart2js_binary ||= (ENV['DART2JS_SOURCE_PATH'] || find_dart2js_in_path || find_dart2js_in_sdk)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def find_dart2js_in_path
|
14
|
+
system('dart2js -h') ? 'dart2js' : false
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_dart2js_in_sdk
|
18
|
+
if root = ENV['DART_SDK_HOME']
|
19
|
+
file = File.join(root, 'bin', 'dart2js')
|
20
|
+
file if File.exist?(file)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :data, :input_file, :result
|
26
|
+
attr_accessor :out_file, :out_dir, :dart2js_binary
|
27
|
+
|
28
|
+
def initialize(file_or_data, options = {})
|
29
|
+
@dart2js_binary = options[:dart2js_binary] || self.class.dart2js_binary
|
30
|
+
@out_dir = options[:out_dir] if options[:out_dir]
|
31
|
+
@out_file = options[:out_file] || File.join((@out_dir || Dir::tmpdir), "dart2js_#{self.object_id}_#{Time.now.usec}.js")
|
32
|
+
if file_or_data.respond_to?(:path)
|
33
|
+
if File.exists?(file_or_data)
|
34
|
+
@input_file = file_or_data
|
35
|
+
else
|
36
|
+
throw 'File not found!'
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@data = file_or_data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def compile
|
44
|
+
cmd = [ @dart2js_binary,
|
45
|
+
%Q{-o"#{out_file}"},
|
46
|
+
in_file = prepare_input.path ].join(' ')
|
47
|
+
process = IO.popen(cmd, 'r')
|
48
|
+
@result = process.read
|
49
|
+
process.close
|
50
|
+
return_code = $?.to_i
|
51
|
+
return_code == 0 ? true : Dart2JsExceptions::CompilationException.new(cmd, in_file, @result)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_js_content
|
55
|
+
File.read(@out_file)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def prepare_input
|
60
|
+
if data
|
61
|
+
tmp_file = Tempfile.open(%w(dart2js_tmpread .dart))
|
62
|
+
tmp_file.write data
|
63
|
+
tmp_file.flush
|
64
|
+
tmp_file
|
65
|
+
else
|
66
|
+
@input_file
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Dart2JsExceptions
|
2
|
+
class CompilationException < RuntimeError
|
3
|
+
attr_reader :cmd, :in_file, :result
|
4
|
+
|
5
|
+
def initialize cmd, in_file, result
|
6
|
+
super("dart2js failed to compile '#{in_file}'")
|
7
|
+
@result = result;
|
8
|
+
@cmd = cmd;
|
9
|
+
@in_file = in_file;
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'dart2js'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
class TestDartJs < Test::Unit::TestCase
|
6
|
+
def test_module
|
7
|
+
assert_kind_of Module, Dart2js
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_compile
|
11
|
+
Tempfile.open(%w(test .dart)) do |f|
|
12
|
+
f.write <<-EOS
|
13
|
+
main() {
|
14
|
+
print('Hello, Dart!');
|
15
|
+
}
|
16
|
+
EOS
|
17
|
+
f.flush
|
18
|
+
of_path = File.join(Dir.tmpdir, 'dart_js_testrun.dart.js')
|
19
|
+
dfile1 = Dart2js.new(f, { :out_file => of_path })
|
20
|
+
dfile1.compile
|
21
|
+
assert File.exists?(of_path)
|
22
|
+
dfile2 = Dart2js.new(f)
|
23
|
+
dfile2.compile
|
24
|
+
assert File.exists?(dfile2.out_file)
|
25
|
+
dfile3 = Dart2js.new("main() { print('Hello, Dart!'); }")
|
26
|
+
dfile3.compile
|
27
|
+
assert File.exists?(dfile3.out_file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-dart2js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcel Sackermann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email:
|
15
|
+
- marcel@m0gg.org
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- MIT-LICENSE
|
21
|
+
- Rakefile
|
22
|
+
- lib/dart2js.rb
|
23
|
+
- lib/dart2js_exceptions.rb
|
24
|
+
- test/test_dart2js.rb
|
25
|
+
homepage: https://github.com/m0gg/ruby-dart2js
|
26
|
+
licenses: []
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.2.2
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Provides dart2js compiling for compatibility.
|
48
|
+
test_files:
|
49
|
+
- test/test_dart2js.rb
|