Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A Shakespearean module for TypeScript, introducing type-safe,
compile-time variable and url interpolation. It is exactly the same as
Text.Julius, except that the template is first compiled to Javascript with
the system tool tsc
.
To use this module, tsc
must be installed on your system.
If you interpolate variables,
the template is first wrapped with a function containing javascript variables representing shakespeare variables,
then compiled with tsc
,
and then the value of the variables are applied to the function.
This means that in production the template can be compiled
once at compile time and there will be no dependency in your production
system on tsc
.
Your code:
var b = 1 console.log(#{a} + b)
Final Result:
;(function(shakespeare_var_a){ var b = 1; console.log(shakespeare_var_a + b); })(#{a});
Important Warnings! This integration is not ideal.
Due to the function wrapper, all type declarations must be in separate .d.ts files. However, if you don't interpolate variables, no function wrapper will be created, and you can make type declarations in the same file.
This does not work cross-platform!
Unfortunately tsc does not support stdin and stdout. So a hack of writing to temporary files using the mktemp command is used. This works on my version of Linux, but not for windows unless perhaps you install a mktemp utility, which I have not tested. Please vote up this bug: http://typescript.codeplex.com/workitem/600
Making this work on Windows would not be very difficult, it will just require a new package with a dependency on a package like temporary.
Further reading:
- Shakespearean templates: https://www.yesodweb.com/book/shakespearean-templates
- TypeScript: https://www.typescriptlang.org/
Synopsis
- tsc :: QuasiQuoter
- tscJSX :: QuasiQuoter
- typeScriptFile :: FilePath -> Q Exp
- typeScriptJSXFile :: FilePath -> Q Exp
- typeScriptFileReload :: FilePath -> Q Exp
- typeScriptJSXFileReload :: FilePath -> Q Exp
Functions
Template-Reading Functions
These QuasiQuoter and Template Haskell methods return values of
type
. See the Yesod book for details.JavascriptUrl
url
tsc :: QuasiQuoter Source #
Read inline, quasiquoted TypeScript
tscJSX :: QuasiQuoter Source #
Read inline, quasiquoted TypeScript with jsx
typeScriptFile :: FilePath -> Q Exp Source #
Read in a TypeScript template file. This function reads the file once, at compile time.
typeScriptJSXFile :: FilePath -> Q Exp Source #
Read in a TypeScript template file with jsx. This function reads the file once, at compile time.