Monday, January 3, 2011

jspp

jspp: JavaScript Pre-Processor
A simple way to build web applications with embedded server side JavaScript. In a few minutes you can build dynamic backend logic in to any page (html, css, etc) using node.js, jQuery and server side DOM with php-like embedded code.
Basic usage
First thing you'll want to do is run the jspp server against your working directory. Any changes you make in the working directory are automatically picked up by the server and refreshed. No need to start and stop during development or even in production.

Now create an index.html and fill it with content.
You can embed server side processing in <?jspp style tags or in script tags with a content type of "application/jspp". Script style tags are only available in html documents and don't work for jspp.init definitions.
When you're in an html file you get most of the normal browser environments. window, document, and other objects are available. You also have a jQuery object at $ that you can use to manipulate any part of the page.
Inside a jspp block this refers to the current DOM node.
console.log is also available for debug logging in the server.
Every block has an end function that must be called to end that blocks processing of the page, future versions of node.js may allow us access to the event system that will allow us to remove this requirement.
There are many other jspp objects that are scoped to the resource and the page: resource, request, response, page, setHeader, and require.
The require function allows you to import any node.js modules you would like. Relative module imports, like require('./module'), are scoped to the directory the file is in.

http://www.jspp.io/

No comments: