Class: Dart2Js
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#dart2js_binary ⇒ Object
Returns the value of attribute dart2js_binary.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#in_file ⇒ Object
readonly
Returns the value of attribute in_file.
-
#out_dir ⇒ Object
Returns the value of attribute out_dir.
-
#out_file ⇒ Object
Returns the value of attribute out_file.
-
#pwd ⇒ Object
Returns the value of attribute pwd.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #close ⇒ Object
- #compile(minify = true) ⇒ Object
- #get_js_content ⇒ Object
-
#initialize(file_or_data, options = {}) ⇒ Dart2Js
constructor
A new instance of Dart2Js.
Constructor Details
#initialize(file_or_data, options = {}) ⇒ Dart2Js
Returns a new instance of Dart2Js.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dart2js.rb', line 30 def initialize(file_or_data, = {}) @dart2js_binary = [:dart2js_binary] || self.class.dart2js_binary if [:out_file].is_a?(File) @out_file = [:out_file] elsif [:out_file] @out_file = File.new([:out_file]) end if [:out_dir] @out_dir = [:out_dir] @out_file ||= File.join(@out_dir, uniqe_tmpfile_name) else @out_file ||= Tempfile.open('dart2js_output') end if file_or_data.is_a?(File) @in_file = file_or_data elsif File.exist?(file_or_data) @in_file = File.new(file_or_data) else @data = file_or_data @pwd = [:pwd] end end |
Class Attribute Details
.dart2js_binary ⇒ Object
10 11 12 |
# File 'lib/dart2js.rb', line 10 def dart2js_binary @dart2js_binary ||= (ENV['DART2JS_SOURCE_PATH'] || find_dart2js_in_path || find_dart2js_in_sdk) end |
Instance Attribute Details
#dart2js_binary ⇒ Object
Returns the value of attribute dart2js_binary.
28 29 30 |
# File 'lib/dart2js.rb', line 28 def dart2js_binary @dart2js_binary end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
27 28 29 |
# File 'lib/dart2js.rb', line 27 def data @data end |
#in_file ⇒ Object (readonly)
Returns the value of attribute in_file.
27 28 29 |
# File 'lib/dart2js.rb', line 27 def in_file @in_file end |
#out_dir ⇒ Object
Returns the value of attribute out_dir.
28 29 30 |
# File 'lib/dart2js.rb', line 28 def out_dir @out_dir end |
#out_file ⇒ Object
Returns the value of attribute out_file.
28 29 30 |
# File 'lib/dart2js.rb', line 28 def out_file @out_file end |
#pwd ⇒ Object
Returns the value of attribute pwd.
28 29 30 |
# File 'lib/dart2js.rb', line 28 def pwd @pwd end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
27 28 29 |
# File 'lib/dart2js.rb', line 27 def result @result end |
Instance Method Details
#close ⇒ Object
78 79 80 81 82 |
# File 'lib/dart2js.rb', line 78 def close [@in_file, @out_file].each do |f| f.close! if f.respond_to?(:close!) end end |
#compile(minify = true) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dart2js.rb', line 56 def compile(minify = true) prepare_input prepare_output cmd = [ @dart2js_binary, minify ? ' -m ': nil, %Q{-o"#{output_path}"}, input_path ].join(' ') process = IO.popen(cmd, 'r') @result = process.read process.close return_code = $?.to_i if return_code != 0 raise CompilationException.new(self, cmd) else get_js_content end end |
#get_js_content ⇒ Object
74 75 76 |
# File 'lib/dart2js.rb', line 74 def get_js_content File.read(@out_file) end |