BedSheet efanUser Guide
Overview
BedSheet Efan
is a Fantom library that integrates efan templates with the BedSheet web framework.
BedSheet Efan
uses IoC, therefore to use the EfanTemplates service you must @Inject
it into your own service / class.
BedSheet Efan
provides a cache of your compiled efan templates, integrates into BedSheet's Err 500 page and lets you contribute efan view helpers on an application level.
See efan for Embedded Fantom documentation.
ALIEN-AID: Replace
BedSheetEfan
with efanXtra to create managed libraries of reusable Embedded Fantom (efan) components!
Install
Install BedSheet efan
with the Fantom Repository Manager ( fanr ):
C:\> fanr install -r http://repo.status302.com/fanr/ afBedSheetEfan
To use in a Fantom project, add a dependency to build.fan
:
depends = ["sys 1.0", ..., "afBedSheetEfan 1.0+"]
Documentation
Full API & fandocs are available on the Status302 repository.
Quick Start
xmas.efan:
<% ctx.times |i| { %> Ho! <% } %> Merry Christmas!
IndexPage.fan:
using afIoc::Inject using afBedSheet::Text using afBedSheetEfan::EfanTemplates class IndexPage { @Inject private EfanTemplates? efan Text render() { template := efan.renderFromFile(`res/index.efan`.toFile, 3) // --> Ho! Ho! Ho! Merry Christmas! return Text.fromPlain(template) } }
Usage
To use BedSheetEfan
just add it as dependency in your project's build.fan
. Example:
depends = ["sys 1.0", ... "afBedSheetEfan 1.0+" ]
...and that's it!
Because BedSheetEfan
defines pod meta-data for IoC, 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(Configuration 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 and runtime 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.18
- Chg: Updated to IoC 2.0.0.
v1.0.16
- Chg: Updated to IoC 1.7.6 and IoC Config 1.0.14.
v1.0.14
- Chg: Updated to IoC 1.7.2 and BedSheet 1.3.12.
v1.0.12
- Chg: Updated to use efan 1.4.0.
v1.0.10
- Chg: Updated to IoC 1.6.0, BedSheet 1.3.6 and Concurrent 1.0.0.
v1.0.8
- Chg: Updated to IoC 1.5.2, Ioc Config 1.0.2, and BedSheet 1.3.0.
v1.0.6
- Chg: Updated to use efan 1.3.
v1.0.4
- New: The class name of efan template instances is now configurable.
- Chg: Updated to use IoC Config.
- Chg: Updated to use efan 1.2.
- Bug: Err msgs could produce an Err if a template file was a pod resource.
v1.0.2
- Chg: Updated to use Plastic
- Chg: Updated Errs to extend
afPlastic::SrcCodeErr
- Chg: Removed Err Page printing as BedSheet now does generic
SrcCodeErr
. - Bug:
EfanCompiler
was not built with contributed config values.
v1.0.0
- New: Code snippets from afPlastic compilation errs are also displayed in the BedSheet Err page.
- New: ctxVarName is now configurable.
- Chg: Split out from efan.