#2161 Tales Templating and afBedSheet

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">

<head>
  <meta charset="utf-8">
  <title>afBedSheet & Tales Templating</title>
  <link rel="stylesheet" type="text/css" href='/pub/css/test.css'/>
</head>
<body>
  <!-- HTML -->
  <div talesId="regular"></div>

  <div talesId="outer">
    <div talesId="inner"></div>
  </div>

  <div talesId="overAndOver">
    <span talesId="value"></span>
  </div>

  <div talesId="attrib"></div>
</body>

</html>

and

class StartupPage {

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.

config.addUnordered(afBedSheet::Route(`/startup`, StartupPage#startup))

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 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.

SlimerDude Wed 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:

@Contribute { serviceType=ResultProcessorSource# }
static Void contributeResultProcessorSource(MappedConfig config) {
  config.addMapped(Html#, config.autobuild(TalesHtmlResultProcessor#))
}

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:

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.

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:

  • 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.

After that, tales stuff!

  • Routing
  • Templates
  • JsCompiler

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.

Login or Signup to reply.