Class: Sprockets::Typescript::Compiler
- Inherits:
-
Object
- Object
- Sprockets::Typescript::Compiler
- Defined in:
- lib/sprockets/typescript/compiler.rb
Defined Under Namespace
Classes: Console, Context, Unit
Constant Summary collapse
- DEFAULT_LIB_PATH =
File.("../../../../bundledjs/lib.d.ts", __FILE__)
Instance Method Summary collapse
- #compile(path, content, context = nil) ⇒ Object
- #eval(*args) ⇒ Object
-
#initialize ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize ⇒ Compiler
Returns a new instance of Compiler.
60 61 62 63 64 65 |
# File 'lib/sprockets/typescript/compiler.rb', line 60 def initialize @ctx = V8::Context.new %w(typescript.patched compiler).each do |filename| @ctx.load(File.("../../../../bundledjs/#{filename}.js", __FILE__)) end end |
Instance Method Details
#compile(path, content, context = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sprockets/typescript/compiler.rb', line 71 def compile(path, content, context = nil) libdts = Unit.new(DEFAULT_LIB_PATH, File.read(DEFAULT_LIB_PATH)) additional_units = [libdts] @ctx["Ruby"] = { "source" => Unit.new(path, content), "additionalUnits" => additional_units, "context" => context.nil? ? nil : Context.new(context), "console" => Console.new } @ctx.eval("Compiler.compile()") end |
#eval(*args) ⇒ Object
67 68 69 |
# File 'lib/sprockets/typescript/compiler.rb', line 67 def eval(*args) @ctx.eval(*args) end |