Plastic is a support library that aids Fantom-Factory in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.
Plastic is a library for dynamically generating and compiling Fantom code.
Plastic is the cornerstone of IoC proxied services and Embedded Fantom (efan) templates.
Install Plastic
with the Fantom Pod Manager ( FPM ):
C:\> fpm install afPlastic
Or install Plastic
with fanr:
C:\> fanr install -r http://eggbox.fantomfactory.org/fanr/ afPlastic
To use in a Fantom project, add a dependency to build.fan
:
depends = ["sys 1.0", ..., "afPlastic 1.1"]
Full API & fandocs are available on the Eggbox - the Fantom Pod Repository.
model := PlasticClassModel("MyClass", true)
model.addMethod(Str#, "greet", "Str name", """ "Hello \${name}!" """)
model.toFantomCode // -->
// const class MyClass {
// new make(|This|? f := null) {
// f?.call(this)
// }
//
// sys::Str greet(Str name) {
// "Hello ${name}!"
// }
// }
myType := PlasticCompiler().compileModel(model)
myType.make->greet("Mum")
// --> Hello Mum!