AF-BedSheetEfanUser Guide

Overview

afBedSheetEfan is a Fantom library that integrates efan templates with the afBedSheet web framework.

afBedSheetEfan provides a cache of your compiled efan renderers, integrates into afBedSheet's Err 500 page and lets you contribute efan view helpers on an application level.

See efan for Embedded Fantom documentation.

Quick Start

xmas.efan:

<% ctx.times |i| { %>
  Ho!
<% } %>
Merry Christmas!

Fantom code:

@Inject EfanTemplates efan

...

// --> Ho! Ho! Ho! Merry Christmas!
txt := efan.renderFromFile(`xmas.efan`.toFile, 3)

Usage

To use afBedSheetEfan just add it as dependency in your project's build.fan. Example:

depends = ["sys 1.0", "afIoc 1.4+", "afBedSheet 1.0+", "afBedSheetEfan 1.0+", ... ]

...and that's it!

Because afBedSheetEfan defines pod meta-data for afIoc, no more configuration or setup is required.

View Helpers

Efan lets you provide view helpers for common tasks. View helpers are mixins that your efan template can extend, giving your templates access to commonly used methods. Example, for escaping XML:

Contribute View Helpers in your AppModule:

@Contribute { serviceType=EfanViewHelpers# }
static Void contrib(OrderedConfig conf) {
  conf.add(XmlViewHelper#)
}

All templates then have access to methods on XmlViewHelper:

<p>
  Hello <%= x(ctx.name) %>!
</p>

Err Reporting

afEfan automatically hooks into afBedSheet to give detailed reports on efan compilation errors. The reports are added to the default afBedSheet Err500 page.

Efan Compilation Err:
  file:/C:/Projects/Fantom/Efan/test/app/compilationErr.efan : Line 17
    - Unknown variable 'dude'

    12: Five space-worthy orbiters were built; two were destroyed in mission accidents. The Space...
    13: </textarea><br/>
    14:         <input id="submitButton" type="button" value="Submit">
    15:     </form>
    16:
==> 17: <% dude %>
    18: <script type="text/javascript">
    19:     <%# the host domain where the scanner is located %>
    20:
    21:     var plagueHost = "http://fan.home.com:8069";
    22:     console.debug(plagueHost);

Fair Usage Policy!

Efan works by dynamically generating Fantom source code and compiling it into a Fantom type. Because types can not be unloaded, if you were compile 1000s of efan templates, it could be considered a memory leak.

For this reason, templates compiled from files are cached and reused, therefore posing no risk in your typical web application(*). But templates compiled from Strs are not cached and so calls to this method should be made judiciously.

(*) If a template file seen to be modified, the efan template is re-compiled on the fly. This is fine in dev, but be weary of modifying template files in live.

Release Notes

v1.0.0

  • New: Code snippets from afPlastic compilation errs are also displayed in the afBedSheet Err page.
  • New: ctxVarName is now configurable.
  • Chg: Split out from efan.