Class: Typescript::Monkey::Transpiler
- Inherits:
-
Object
- Object
- Typescript::Monkey::Transpiler
- Defined in:
- lib/typescript/monkey/transpiler.rb
Overview
The Transpiler class.
A class that implements an interface to a dynamic runtime Typescript to javascript transpiler.
The scripts that are returned by this class are dependent upon Typescript Services to be available.
Class Method Summary collapse
-
.dyrt_js ⇒ String
(also: runner_js)
Returns content for dynamic runtime transpiler.
-
.dyrt_js_path ⇒ Pathname
Returns path to dynamic runtime transpiler.
-
.dyrt_once_js ⇒ String
Returns content for dynamic runtime transpiler.
-
.dyrt_once_js_path ⇒ Pathname
Returns path to dynamic runtime transpiler.
-
.dyrt_ts ⇒ String
(also: runner_ts)
Returns content for dynamic runtime transpiler (pre-transpiled version).
-
.dyrt_ts_path ⇒ Pathname
Returns path to dynamic runtime transpiler (pre-transpiled version).
-
.gem_assets_path ⇒ Pathname
Returns assets directory for this gem.
-
.gem_javascripts_path ⇒ Pathname
Returns javascripts directory for this gem.
-
.gem_lib_path ⇒ Pathname
Returns lib directory for this gem.
-
.gem_path_for(directory) ⇒ Pathname
Returns path for gem directory.
-
.gem_root_path ⇒ Pathname
Returns top directory for this gem.
-
.gem_typescripts_path ⇒ Pathname
Returns typescripts directory for this gem.
Class Method Details
.dyrt_js ⇒ String Also known as: runner_js
Returns content for dynamic runtime transpiler
The transpiler can be included with web content to transform embedded Typescript wrapped in <script type=“text/typescript”></script> tags.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/typescript/monkey/transpiler.rb', line 44 def self.dyrt_js transpiler_js = "" transpiler_js_path = self.dyrt_js_path() unless transpiler_js_path.nil? transpiler_js = transpiler_js_path.read() end transpiler_js end |
.dyrt_js_path ⇒ Pathname
Returns path to dynamic runtime transpiler
The transpiler can be included with web content to transform embedded Typescript wrapped in <script type=“text/typescript”></script> tags.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/typescript/monkey/transpiler.rb', line 24 def self.dyrt_js_path transpiler_js_path = gem_javascripts_path() if transpiler_js_path transpiler_js_path = transpiler_js_path.join("dyrt.js") unless transpiler_js_path.file? && transpiler_js_path.readable? transpiler_js_path = nil end end transpiler_js_path end |
.dyrt_once_js ⇒ String
Returns content for dynamic runtime transpiler
The transpiler can be included with web content to transform embedded Typescript wrapped in <script type=“text/typescript”></script> tags.
The “once” compilers include an immediately invoked function expression (IIFE) that triggers transpile exactly once. Add this script to the bottom of the body in an HTML page; ideally, this should run last. The script does not, and probably should not, be run after DOM ready; however the Typescript objects in your page can wait for DOM ready.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/typescript/monkey/transpiler.rb', line 94 def self.dyrt_once_js transpiler_js = "" transpiler_js_path = self.dyrt_once_js_path() unless transpiler_js_path.nil? transpiler_js = transpiler_js_path.read() end transpiler_js end |
.dyrt_once_js_path ⇒ Pathname
Returns path to dynamic runtime transpiler
The transpiler can be included with web content to transform embedded Typescript wrapped in <script type=“text/typescript”></script> tags.
The “once” compilers include an immediately invoked function expression (IIFE) that triggers transpile exactly once. Add this script to the bottom of the body in an HTML page; ideally, this should run last. The script does not, and probably should not, be run after DOM ready; however the Typescript objects in your page can wait for DOM ready.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/typescript/monkey/transpiler.rb', line 68 def self.dyrt_once_js_path transpiler_js_path = gem_javascripts_path() if transpiler_js_path transpiler_js_path = transpiler_js_path.join("dyrt_once.js") unless transpiler_js_path.file? && transpiler_js_path.readable? transpiler_js_path = nil end end transpiler_js_path end |
.dyrt_ts ⇒ String Also known as: runner_ts
Returns content for dynamic runtime transpiler (pre-transpiled version)
The transpiler can be included with web content to transform embedded Typescript wrapped in <script type=“text/typescript”></script> tags.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/typescript/monkey/transpiler.rb', line 132 def self.dyrt_ts transpiler_ts = "" transpiler_ts_path = self.dyrt_ts_path() unless transpiler_ts_path.nil? transpiler_ts = transpiler_ts_path.read() end transpiler_ts end |
.dyrt_ts_path ⇒ Pathname
Returns path to dynamic runtime transpiler (pre-transpiled version)
The transpiler can be included with web content to transform embedded Typescript wrapped in <script type=“text/typescript”></script> tags.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/typescript/monkey/transpiler.rb', line 112 def self.dyrt_ts_path transpiler_ts_path = gem_typescripts_path() if transpiler_ts_path transpiler_ts_path = transpiler_ts_path.join("transpiler.ts") unless transpiler_ts_path.file? && transpiler_ts_path.readable? transpiler_ts_path = nil end end transpiler_ts_path end |
.gem_assets_path ⇒ Pathname
Returns assets directory for this gem
230 231 232 |
# File 'lib/typescript/monkey/transpiler.rb', line 230 def gem_assets_path gem_path_for("assets") end |
.gem_javascripts_path ⇒ Pathname
Returns javascripts directory for this gem
240 241 242 |
# File 'lib/typescript/monkey/transpiler.rb', line 240 def gem_javascripts_path gem_path_for("javascripts") end |
.gem_lib_path ⇒ Pathname
Returns lib directory for this gem
220 221 222 |
# File 'lib/typescript/monkey/transpiler.rb', line 220 def gem_lib_path gem_path_for("lib") end |
.gem_path_for(directory) ⇒ Pathname
Returns path for gem directory
The directory is the gem directory to resolve. Must be a value of:
+ root - gem root directory
+ lib - gem lib directory
+ assets - gem lib/assets directory
+ javascripts - gem lib/assets/javascripts directory
+ typescripts - gem lib/assets/typescripts directory
Results are memoized.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/typescript/monkey/transpiler.rb', line 170 def gem_path_for(directory) if directory.empty? || directory.nil? raise ArgumentError, "directory parameter required but not supplied" end if !["root", "lib", "assets", "javascripts", "typescripts"].include?(directory) raise ArgumentError, "invalid directory specified: #{directory}" end directory_sym = directory.downcase.to_sym @gem_paths ||= {} return @gem_paths[directory_sym] if @gem_paths.has_key?(directory_sym) # resolve gem root (top directory of this gem) gem_root = Pathname.new(File.("../../../../", __FILE__)) # process shortcuts case directory_sym when :lib gem_path = gem_root.join("lib") when :assets gem_path = gem_root.join("lib/assets") when :javascripts gem_path = gem_root.join("lib/assets/javascripts") when :typescripts gem_path = gem_root.join("lib/assets/typescripts") when :root gem_path = gem_root else gem_path = Pathname.new("") end @gem_paths[directory_sym] = ((gem_path.directory?) ? gem_path : nil) end |
.gem_root_path ⇒ Pathname
Returns top directory for this gem
210 211 212 |
# File 'lib/typescript/monkey/transpiler.rb', line 210 def gem_root_path gem_path_for("root") end |
.gem_typescripts_path ⇒ Pathname
Returns typescripts directory for this gem
250 251 252 |
# File 'lib/typescript/monkey/transpiler.rb', line 250 def gem_typescripts_path gem_path_for("typescripts") end |