Mjt: a Javascript Webapp Library

Template-Driven Web Applications in Javascript

Mjt is a Javascript application framework that can run entirely in a web browser. It has three main components:

mjt.Template is a full-featured and extremely fast HTML/XML templating system. Server-side web frameworks rely heavily on templating engines: mjt.Template is similarly useful in the browser.

mjt.Task is a powerful asynchronous framework for JS. Asynchronous operations described using mjt.Task are easily composed and chained.

Mjt.freebase is an interface to the Freebase web service using mjt.Task.

mjt.App is a simple in-browser web framework for building single-page applications.

Mjt has been used (in combination with jQuery and CodeMirror) to build a complex in-browser Javascript development environment, the Freebase App Editor. Mjt.Template also provides server-side templating for the hosted Freebase Apps service.

If you can get your data from a JSON-aware web service, creating a Mjt application is the quickest way to get that data displayed in a browser with complete control of the HTML formatting. You can run the application from your local filesystem or share it on any web server as static files. No server-side support is necessary - all the work can take place in the browser using Javascript.

Mjt is particularly useful with JSONP services that return JSON values and accept a callback= parameter. Most modern JSON web services support this feature, and with these services you can use Mjt to build "mash-ups" that incorporate data from services on multiple hosts.

Examples

Many of the Mjt examples are now Acre examples for ease of hosting, but there are several browser-side examples.

The examples primarily use Freebase data sources but there are examples using Yahoo image search and the Google feed API as well.

For a step-by-step introduction to the Mjt template language, as well as an example of Mjt in action, start with the intro tour.

New in Mjt 0.9

Usage

Here's a very simple mjt page. If you visit it at examples-minimal you should see that the $mjt.VERSION string has been substituted:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<script type="text/javascript" src="http://mjtemplate.org/dist/mjt-0.6/mjt.js"></script>
<title>a minimal mjt example</title>
</head>
<body onload="mjt.run()" style="display:none">
    running mjt version $mjt.VERSION
</body></html>

Download

Mjt is hosted on Google code at http://code.google.com/p/mjt.

You can copy mjt.js to your own web server or include a minimized version from http://freebaselibs.com/static/mjt/mjt-0.9.2/mjt.min.js. This includes the parts of Mjt necessary for building Freebase applications: some files are not included.

This version is also available at http://freebaselibs.com/static/mjt/mjt-0.9.2/mjt.js which loads files from http://freebaselibs.com/static/mjt/mjt-0.9.2/src

Older versions can be found at http://freebaselibs.com/static/mjt.

Support

Mailing list TBA. For now, subscribe to developers@freebase.com or watch blog.freebase.com

License

Mjt is distributed under a two-clause BSD open source license:

Copyright (c) 2007-2009, Metaweb Technologies, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY METAWEB TECHNOLOGIES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL METAWEB TECHNOLOGIES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.