Class: Dart2Js
- Inherits:
-
Object
- Object
- Dart2Js
- Defined in:
- lib/dart2js.rb
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.
-
#input_file ⇒ Object
readonly
Returns the value of attribute input_file.
-
#out_dir ⇒ Object
Returns the value of attribute out_dir.
-
#out_file ⇒ Object
Returns the value of attribute out_file.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dart2js.rb', line 28 def initialize(file_or_data, = {}) @dart2js_binary = [:dart2js_binary] || self.class.dart2js_binary @out_dir = [:out_dir] if [:out_dir] @out_file = [:out_file] || File.join((@out_dir || Dir::tmpdir), "dart2js_#{self.object_id}_#{Time.now.usec}.js") if file_or_data.respond_to?(:path) if File.exists?(file_or_data) @input_file = file_or_data else throw 'File not found!' end else @data = file_or_data end end |
Class Attribute Details
.dart2js_binary ⇒ Object
8 9 10 |
# File 'lib/dart2js.rb', line 8 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.
26 27 28 |
# File 'lib/dart2js.rb', line 26 def dart2js_binary @dart2js_binary end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
25 26 27 |
# File 'lib/dart2js.rb', line 25 def data @data end |
#input_file ⇒ Object (readonly)
Returns the value of attribute input_file.
25 26 27 |
# File 'lib/dart2js.rb', line 25 def input_file @input_file end |
#out_dir ⇒ Object
Returns the value of attribute out_dir.
26 27 28 |
# File 'lib/dart2js.rb', line 26 def out_dir @out_dir end |
#out_file ⇒ Object
Returns the value of attribute out_file.
26 27 28 |
# File 'lib/dart2js.rb', line 26 def out_file @out_file end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
25 26 27 |
# File 'lib/dart2js.rb', line 25 def result @result end |
Instance Method Details
#compile(minify = true) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dart2js.rb', line 43 def compile minify=true cmd = [ @dart2js_binary, minify ? ' -m ' : '', %Q{-o"#{out_file}"}, in_file = prepare_input.path ].join(' ') process = IO.popen(cmd, 'r') @result = process.read process.close return_code = $?.to_i return_code == 0 ? true : Dart2JsExceptions::CompilationException.new(cmd, in_file, @result) end |
#get_js_content ⇒ Object
55 56 57 |
# File 'lib/dart2js.rb', line 55 def get_js_content File.read(@out_file) end |