TextResult startup()
{
// Tales bit starts here
html := Html("fan://xanLocalServer/template/startup.html")
html.tag("regular").text("I am a regular tag")
html.tag("inner").text("..and I am a nested tag")
Str[] vals := ["one", "two", "three"]
html.tag("overAndOver").repeating
vals.each{
row := html.tag("overAndOver").addRow
row.tag("value").text("Repeating $it times")
}
someText := "My color was dynamically changed"
html.tag("attrib").text(someText).addCss("color", "red")
// Now serve it via afBedSheet in the usual way
return TextResult.fromHtml(html.apply)
}
}
Because this returns dynamically modified content I have had to route to a page handler and return a TextResult rather than mapping to a FileHandler for the html. I have also had to apply some disambiguation in the routing with the introduction of Tales e.g.
It'd be nice to have all the page handlers simply returning tales::Html - just need to make a TalesHtmlResultProcessor (based on TextResultProcessor) and contribute it to ResultProcessorSource.
I can post one later when I'm back on the code base. (It'll also force me to think about pipelining the ResultProcessor return value which has been on my TODO list.)
Cheers, Steve.
SlimerDudeWed 3 Jul 2013
Hi, the below should work. With afBedSheet 0.0.6 it should become a one-line method:
using afIoc::Inject
using afBedSheet
using tales::Html
const class TalesHtmlResultProcessor : ResultProcessor {
@Inject
private const Response res
new make(|This|in) { in(this) }
override Void process(Obj result) {
html := (Html) html
text := TextResult.fromHtml(html.apply)
res.headers["Content-Type"] = text.mimeType.toStr
res.out.printLine(text.text).close
}
}
Oh, and you'll need to register it with ResultProcessorSource:
using afBedSheet
using tales::Html
const class TalesHtmlResponseProcessor : ResponseProcessor {
override Obj process(Obj result) {
html := (Html) html
return TextResponse.fromHtml(html.apply)
}
}
// in AppModule
@Contribute { serviceType=ResultProcessors# }
static Void contributeResultProcessors(MappedConfig conf) {
conf[Html#] = TalesHtmlResponseProcessor()
}
Note that when you upgrade, you'll have to add some **s to your Route URIs to match method arguments. (The whole routing section has been re-worked.) Oh, and TextResult has been renamed to TextResponse.
Bob147Thu 11 Jul 2013
Thanks Steve,
I will pick this up later today, I have been busy with other things for the past few days. Do you have any sort of roadmap for afBedSheet development?
Regards Bob
SlimerDudeThu 11 Jul 2013
Hi Bob,
It's loosely in the todo.txt (which changes on every check in!) but briefly, core things I'd like to see for a v1 release:
enhance the Err handling
create a HttpSession service
create a log filter
create a welcome page
add Draft routing
more docs!!!
And things I'm still debating over:
how to easily send a redirect (Uri vs HttpStatusResponse)?
HTTP1.0 vs HTTP1.1 (301, 302 vs 303, 307, 308)
how to add custom pages for HTTP response codes (e.g. 404 & 500) while still keeping the existing Err handling functionality.
Bob147 Wed 3 Jul 2013
Hi Steve,
I now have this combination working with one of the Tales templating examples using the following:-
<!DOCTYPE html> <html lang="en">
</html>
and
class StartupPage {
}
Because this returns dynamically modified content I have had to route to a page handler and return a TextResult rather than mapping to a FileHandler for the html. I have also had to apply some disambiguation in the routing with the introduction of Tales e.g.
Regards Bob
SlimerDude Wed 3 Jul 2013
Hi Bob,
Thanks, that looks cool!
It'd be nice to have all the page handlers simply returning
tales::Html
- just need to make aTalesHtmlResultProcessor
(based onTextResultProcessor
) and contribute it toResultProcessorSource
.I can post one later when I'm back on the code base. (It'll also force me to think about pipelining the
ResultProcessor
return value which has been on my TODO list.)Cheers, Steve.
SlimerDude Wed 3 Jul 2013
Hi, the below should work. With afBedSheet 0.0.6 it should become a one-line method:
Oh, and you'll need to register it with
ResultProcessorSource
:SlimerDude Sat 6 Jul 2013
Hi Bob,
Just to say afBedSheet-0.0.6 is now public (along with afIoc-1.3.8) which means the above becomes:
Note that when you upgrade, you'll have to add some
**
s to your Route URIs to match method arguments. (The whole routing section has been re-worked.) Oh, andTextResult
has been renamed toTextResponse
.Bob147 Thu 11 Jul 2013
Thanks Steve,
I will pick this up later today, I have been busy with other things for the past few days. Do you have any sort of roadmap for afBedSheet development?
Regards Bob
SlimerDude Thu 11 Jul 2013
Hi Bob,
It's loosely in the todo.txt (which changes on every check in!) but briefly, core things I'd like to see for a v1 release:
And things I'm still debating over:
After that, tales stuff!
SlimerDude Sun 14 Jul 2013
Just to say that afBedSheet-0.0.8 is now public.
I see 0.0.8 as a Release Candidate, making sure there are no glaring omissions or dangerous bugs before I bump the version up to a meaty 1.0.