Comparing version 0.0.1 to 0.0.2
@@ -5,3 +5,3 @@ var connect = require('connect') | ||
var dbCall = function(viewCallback) { | ||
var getPosts = function(viewCallback) { | ||
setTimeout(function() { | ||
@@ -17,5 +17,6 @@ viewCallback(null, [ | ||
var server = connect.createServer() | ||
.use(ajs()) | ||
.use(ajs({dir: './views'})) | ||
.use(connect.static('./public')) | ||
.use(function(req, res) { | ||
res.render('index', {title: "Hello World!", dbCall: dbCall}); | ||
res.render('index', {title: "Hello World!", getPosts: getPosts}); | ||
}); | ||
@@ -22,0 +23,0 @@ |
@@ -24,2 +24,3 @@ // AJS 0.0.1 | ||
this._outFunc = "__ajs.out"; | ||
this._escFunc = "__ajs.esc"; | ||
this._cbFunc = "__ajs.cb"; | ||
@@ -39,10 +40,9 @@ this._endFunc = "__ajs.end"; | ||
Compiler.prototype.compile = function() { | ||
var lexer = new Lexer(this.source, {includeComments: false}) | ||
, ast = new Parser(lexer).parse(); | ||
var lexer = new Lexer(this.source, {includeComments: false}); | ||
this.tree = ast; | ||
this.line = 0; | ||
this.tree = new Parser(lexer).parse(); | ||
this.lineCount = lexer._line; | ||
if(this._onlyTree) return this.tree; | ||
this.compiled = "(function(__ajs, __context) {\n" + | ||
@@ -83,2 +83,6 @@ "var include = __ajs.inc\n" + | ||
proto[Node.EMBED] = function(statements) { | ||
return this._format([this._outFunc + "(" + this._escFunc + "(" + cleanEmbed(this._blockStatements(statements).join('')) + "))"]); | ||
} | ||
proto[Node.EMBED_RAW] = function(statements) { | ||
return this._format([this._outFunc + "(" + cleanEmbed(this._blockStatements(statements).join('')) + ")"]); | ||
@@ -85,0 +89,0 @@ } |
@@ -153,3 +153,3 @@ // AJS 0.0.1 | ||
this._inEmbed = true; | ||
if(ch == '=') return this._token(Token.EMBED, this._next()); | ||
if(ch == '=' || ch == '-') return this._token(Token.EMBED, this._next()); | ||
else return this.nextToken(); | ||
@@ -156,0 +156,0 @@ } else if(tag == this._embedChar + '>') { |
@@ -220,2 +220,4 @@ // AJS 0.0.1 | ||
return this._node(Node.EMBED, [this._statement()]); | ||
case "-": | ||
return this._node(Node.EMBED_RAW, [this._statement()]); | ||
default: this._unexpected(); | ||
@@ -671,2 +673,3 @@ } | ||
, 'embed' | ||
, 'embed_raw' | ||
, 'expression_list' | ||
@@ -673,0 +676,0 @@ , 'for' |
@@ -189,2 +189,3 @@ // AJS 0.0.1 | ||
, flush: this._flush.bind(this) | ||
, esc: escape | ||
} | ||
@@ -207,4 +208,2 @@ | ||
runCtx.clearTimeout = clearTimeout; | ||
runCtx.setInterval = setInterval; | ||
runCtx.clearInterval = clearInterval; | ||
@@ -214,2 +213,10 @@ return runCtx; | ||
function escape(expr) { | ||
return String(expr) | ||
.replace(/&(?!\w+;)/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"'); | ||
} | ||
function extend(target, source) { | ||
@@ -216,0 +223,0 @@ var props = Object.getOwnPropertyNames(source); |
{ "name" : "ajs" | ||
, "description" : "Experimental asyncronous templating in Node" | ||
, "keywords" : ["ajs", "ejs", "template", "view", "asyncronous"] | ||
, "version" : "0.0.1" | ||
, "version" : "0.0.2" | ||
, "author" : "Evan Owen <kainosnoema@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "main" : "index" |
112
Readme.md
@@ -5,10 +5,74 @@ | ||
AJS is an experimental asyncronous templating language for [Node](http://nodejs.org). | ||
It's currently a work in progress, but Connect middleware is already functional. | ||
Currently a work in progress, but Connect middleware is functional. | ||
## Annotated Source | ||
## Installation | ||
http://kainosnoema.github.com/ajs | ||
```` bash | ||
$ npm install ajs | ||
```` | ||
## Example | ||
## Usage | ||
AJS is [Connect](http://github.com/senchalabs/connect) middleware: | ||
```` javascript | ||
var connect = require('connect') | ||
, mysql = new (require('mysql').Client) | ||
, ajs = require('ajs'); | ||
mysql.user = 'dbuser'; | ||
mysql.password = 'passwd'; | ||
mysql.connect(); | ||
mysql.useDatabase('blog'); | ||
var getPosts = function(viewCallback) { | ||
mysql.query("select * from posts", viewCallback); | ||
} | ||
var server = connect.createServer() | ||
.use(ajs({dir: './views'})) | ||
.use(function(req, res) { | ||
res.render('index', {title: "Blog Home", getPosts: getPosts}); | ||
}); | ||
```` | ||
views/index.ajs: | ||
```` erb | ||
<html> | ||
<head> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<h1><%= title %></h1> | ||
<div id="posts"> | ||
<% getPosts(function(err, posts) { | ||
if(posts) { | ||
posts.forEach(function(post) { %> | ||
<div class="post"> | ||
<h3><a href="#"><%= post.title %></a></h3> | ||
<%- post.body %> | ||
</div> | ||
<%}); | ||
} else { %> | ||
An error occured while trying to load the posts. | ||
<% } | ||
}) %> | ||
</div> | ||
</body> | ||
</html> | ||
```` | ||
For lower-level access, simply require the template file, bind to its `data`, `error` and `end` events, and call `.render(<context>)`, passing it an optional context object: | ||
```` javascript | ||
var template = require('views/index'); | ||
template.on('data', function(data) { | ||
console.log(data); | ||
}) | ||
template.render({title: 'Hello World!'}); | ||
```` | ||
## Syntax | ||
index.ajs: | ||
@@ -47,3 +111,3 @@ | ||
<!-- native array callback functions are exempt from the | ||
<!-- some native syncronous callbacks are exempt from the | ||
nested callback restriction. --> | ||
@@ -85,40 +149,6 @@ | ||
## Usage | ||
## Annotated Source | ||
AJS is [Connect](http://github.com/senchalabs/connect) middleware: | ||
http://kainosnoema.github.com/ajs | ||
```` javascript | ||
var connect = require('connect') | ||
, ajs = require('../../lib/ajs'); | ||
var server = connect.createServer() | ||
.use(ajs({dir: './views'})) | ||
.use(function(req, res) { | ||
res.render('index', {title: "Hello World!"}); | ||
}); | ||
```` | ||
views/index.ajs: | ||
```` erb | ||
<html> | ||
<head> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<h1><%= title %></h1> | ||
</body> | ||
</html> | ||
```` | ||
For lower-level access to AJS, simply require the template file, bind to its `data`, `error` and `end` events, and call `.render(<context>)`, passing it an optional context object: | ||
```` javascript | ||
var template = require('views/index'); | ||
template.on('data', function(data) { | ||
console.log(data); | ||
}) | ||
template.render({title: 'Hello World!'}); | ||
```` | ||
## Authors | ||
@@ -125,0 +155,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92115
25
2444
178