The yesod-routes-typescript package

[Tags: library, mit]

parse the Yesod routes data structure and generate routes that can be used in typescript


[Skip to ReadMe]

Properties

Version0.3.0.0
Change logNone available
Dependenciesattoparsec, base (<5), classy-prelude (>=0.7), system-fileio, text, yesod-core (>=1.2 && <2.0), yesod-routes (>=1.2 && <2.0) [details]
LicenseMIT
AuthorMax Cantor
Maintainermax@docmunch.com
CategoryWeb
Home pagehttps://github.com/docmunch/yesod-routes-typescript
UploadedWed Apr 16 22:59:04 UTC 2014 by GregWeber
Downloads175 total (9 in last 30 days)
Votes
0 []
StatusDocs available [build log]
Successful builds reported [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for yesod-routes-typescript-0.3.0.0

yesod-routes-typescript

parse the Yesod routes data structure and generate routes that can be used in typescript

The routing structure is generated by:

mkYesodDispatch "App" resourcesApp

You can generate routes at startup inside the makeApplication function

when development $
    genTypeScriptRoutes resourcesApp "assets/ts/paths-gen.ts"

This generates typescript code:

class PATHS_TYPE_paths {
  public contacts: PATHS_TYPE_paths_contacts;
  public admin: PATHS_TYPE_paths_admin;

  constructor(){
    this.contacts = new PATHS_TYPE_paths_contacts();
    this.admin = new PATHS_TYPE_paths_admin();
  }
}

class PATHS_TYPE_paths_contacts {
  public get():string { return '/api/v1/contacts/get'; }
}

class PATHS_TYPE_paths_admin {
  public adminDocs: PATHS_TYPE_paths_admin_adminDocs;

  constructor(){
    this.adminDocs = new PATHS_TYPE_paths_admin_adminDocs();
  }
}

class PATHS_TYPE_paths_admin_adminDocs {
  public get():string { return '/api/v1/admin/docs/get'; }
}


var PATHS:PATHS_TYPE_paths = new PATHS_TYPE_paths();

In your typescript code you can now do:

PATHS.admin.adminDocs.get()

Please note that the Haskell code was hastily translated from javascript code and is pretty horrible. There are bugs and edge cases to be addressed, but this works ok for us.