#1943 Newbie Js Question

SlimerDude Mon 9 Jul 2012

In the Js Example it seems URIs such as fan://gfx/gfx.js are resolved to a compiled JS file.

So I have a project / pod called wotever and I've added the @Js annotation to most of the classes. My question, how do I generate fan://wotever/wotever.js, or compile my pod to Js?

andy Mon 9 Jul 2012

The JavaScript file will be generated automatically when any types are marked with @Js: docLang::JavaScript

SlimerDude Mon 9 Jul 2012

Cheers Andy, I had a pod name mixup but docLang::JavaScript helped a lot.

For those interested, here's my simple browser page:

using util
using web
using webmod
using wisp

class GundamJs : AbstractMain {

  @Opt { help = "http port" }
  Int port := 8080

  override Int run() {
    wisp := WispService {
      it.port = this.port
      it.root = JsDemoMod()
    }
    return runServices([wisp])
  }
}


const class JsDemoMod : WebMod {

  override Void onGet() {
    name := req.modRel.path.first
    if (name == null)
      onIndex
    else if (name == "pod")
      onPodFile
    else
      res.sendErr(404)
  }

  Void onIndex() {
    res.headers["Content-Type"] = "text/html; charset=utf-8"
    out := res.out
    out.docType
    out.html
    out.head
      out.title.w("Wotever").titleEnd
      out.includeJs(`/pod/sys/sys.js`)
      out.includeJs(`/pod/concurrent/concurrent.js`)
      out.includeJs(`/pod/gfx/gfx.js`)
      out.includeJs(`/pod/fwt/fwt.js`)
      out.includeJs(`/pod/wotever/wotever.js`)
      WebUtil.jsMain(out, "wotever::Main")
    out.headEnd    
    out.htmlEnd
  }

  Void onPodFile() {
    // serve up pod resources
    File file := ("fan://" + req.uri[1..-1]).toUri.get
    if (!file.exists) { res.sendErr(404); return }
    FileWeblet(file).onService
  }
}

Login or Signup to reply.