Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9b958b1
Showing
10 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
fs = require "fs" | ||
{print} = require "sys" | ||
{spawn, exec} = require 'child_process' | ||
|
||
build = (callback) -> | ||
coffee = spawn "coffee", ['-c', '-o', 'lib', 'src'] | ||
coffee.stdout.on 'data', (data) -> print data.toString() | ||
coffee.stderr.on 'data', (data) -> print data.toString() | ||
callback?() | ||
|
||
task 'build', "Compile all of the coffescripts into javascripts", -> | ||
coffee = spawn "coffee", ['-c', '-o', 'lib', 'src'] | ||
coffee.stdout.on 'data', (data) -> print data.toString() | ||
coffee.stderr.on 'data', (data) -> print data.toString() | ||
|
||
task 'test', "Run the test suite", -> | ||
build -> | ||
tests = null | ||
tests = spawn "coffee", ["-e", "{reporters} = require 'nodeunit'; reporters.default.run ['.']"], cwd: 'test' | ||
tests.stdout.on 'data', (data) -> print data.toString() | ||
tests.stderr.on 'data', (data) -> print data.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("./lib/jade-connect.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(function() { | ||
var compile, fs, jade, path; | ||
fs = require("fs"); | ||
jade = require("jade"); | ||
path = require("path"); | ||
compile = function(options) { | ||
var ns, src, templates; | ||
src = options.src || "views"; | ||
ns = options.ns || "tpl"; | ||
if (src.charAt(0) === "/") { | ||
src = src.slice(1, src.length); | ||
} | ||
templates = "window." + ns + " = {};"; | ||
fs.readdir(src, function(err, files) { | ||
if (!err) { | ||
return files.forEach(function(file) { | ||
var filename, fn, nm, tpl; | ||
filename = "" + src + "/" + file; | ||
nm = /(.*)\.jade$/.exec(file)[1]; | ||
tpl = fs.readFileSync(filename); | ||
fn = jade.compile(tpl, { | ||
client: true, | ||
compileDebug: false, | ||
filename: filename | ||
}); | ||
return templates += "" + ns + "." + nm + " = " + fn + ";"; | ||
}); | ||
} | ||
}); | ||
return templates; | ||
}; | ||
module.exports = function(options) { | ||
var re, templates, url; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
templates = compile(options); | ||
url = options.url || "templates.js"; | ||
re = new RegExp(".*" + url + "$"); | ||
return function(req, res, next) { | ||
if (re.test(req.url)) { | ||
res.setHeader("Content-Type", "application/javascript"); | ||
return res.end(templates); | ||
} else { | ||
return next(); | ||
} | ||
}; | ||
}; | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(function() { | ||
var fs, jade, path; | ||
fs = require("fs"); | ||
jade = require("jade"); | ||
path = require("path"); | ||
module.exports = function(options) { | ||
var ns, re, src, templates, url; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
src = options.src || "views"; | ||
ns = options.ns || "tpl"; | ||
if (src.charAt(0) === "/") { | ||
src = src.slice(1, src.length); | ||
} | ||
templates = "window." + ns + " = {};"; | ||
fs.readdir(src, function(err, files) { | ||
if (!err) { | ||
return files.forEach(function(file) { | ||
var filename, fn, nm, tpl; | ||
filename = "" + src + "/" + file; | ||
nm = /(.*)\.jade$/.exec(file)[1]; | ||
tpl = fs.readFileSync(filename); | ||
fn = jade.compile(tpl, { | ||
client: true, | ||
compileDebug: false, | ||
filename: filename | ||
}); | ||
return templates += "" + ns + "." + nm + " = " + fn + ";"; | ||
}); | ||
} | ||
}); | ||
url = options.url || "templates.js"; | ||
re = new RegExp(".*" + url + "$"); | ||
return function(req, res, next) { | ||
if (re.test(req.url)) { | ||
res.setHeader("Content-Type", "application/javascript"); | ||
return res.end(templates); | ||
} else { | ||
return next(); | ||
} | ||
}; | ||
}; | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "jade-client-connect", | ||
"description": "Jade Client Connect - A compiler to help use templates on a web client", | ||
"version": "0.0.1", | ||
"author": "Ed Siok <@sioked>", | ||
"main": "./lib/index.js", | ||
"dependencies": { | ||
"uglify-js" : "1.0.7", | ||
"jade" : "0.15.4" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": ">= 1.1.2", | ||
"connect" : "latest", | ||
"nodeunit": "0.5.1", | ||
"request" : "2.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
fs = require "fs" | ||
jade = require "jade" | ||
path = require "path" | ||
|
||
module.exports = (options = {}) -> | ||
# uglify = require "uglify-js" | ||
|
||
src = options.src || "views" | ||
ns = options.ns || "tpl" | ||
src = src.slice 1, src.length if src.charAt(0) is "/" | ||
templates = "window.#{ns} = {};" | ||
fs.readdir src, (err, files) -> | ||
if not err | ||
files.forEach (file) -> | ||
filename = "#{src}/#{file}" | ||
nm = /(.*)\.jade$/.exec(file)[1] | ||
tpl = fs.readFileSync filename | ||
fn = jade.compile tpl, {client: true, compileDebug: false, filename:filename} | ||
templates += "#{ns}.#{nm} = #{fn};" | ||
|
||
url = options.url || "templates.js" | ||
re = new RegExp ".*#{url}$" | ||
|
||
(req, res, next) -> | ||
if re.test req.url | ||
res.setHeader "Content-Type", "application/javascript" | ||
res.end templates | ||
else | ||
next() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
request = require 'request' | ||
|
||
app = require('connect').createServer() | ||
app.use require('../index.js')() | ||
app.listen 1337 | ||
|
||
exports['Basic Test'] = (test) -> | ||
test.expect 1 | ||
test.ok true, "Failed assertion" | ||
test.done() | ||
|
||
exports['Basic doctype test'] = (test) -> | ||
test.expect 2 | ||
request 'http://localhost:1337/js/templates.js', (err, res, body) -> | ||
console.log "Body: #{body}" | ||
test.equal res.headers["content-type"], "application/javascript" | ||
test.ok /DOCTYPE html/.test body | ||
test.done() | ||
|
||
exports['incorrect file name'] = (test) -> | ||
test.expect 1 | ||
request 'http://localhost:1337/js/incorrect.js', (err, res, body) -> | ||
test.equal res.statusCode, "404" | ||
test.done() | ||
|
||
exports["File name incorrect location in Url"] = (test) -> | ||
test.expect 1 | ||
request 'http://localhost:1337/js/templates.js/else', (err, res, body) -> | ||
test.equal res.statusCode, "404" | ||
test.done() | ||
|
||
exports['Test Default NameSpace'] = (test) -> | ||
test.expect 1 | ||
request 'http://localhost:1337/js/templates.js', (err, res, body) -> | ||
test.ok /tpl.doctype\s?=/.test body | ||
test.done() | ||
|
||
exports['Test custom NameSpace'] = (test) -> | ||
test.expect 1 | ||
app.close() | ||
app = require('connect').createServer() | ||
app.use require('../index.js')({ns : "test"}) | ||
app.listen 1338 | ||
request 'http://localhost:1338/js/templates.js', (err, res, body) -> | ||
console.log body | ||
test.ok /test.doctype\s?=/.test body | ||
test.done() | ||
|
||
exports['Test custom view folder'] = (test) -> | ||
test.expect 1 | ||
app.close() | ||
app = require('connect').createServer() | ||
app.use require('../index.js')({src : "views2"}) | ||
app.listen 1338 | ||
request 'http://localhost:1338/js/templates.js', (err, res, body) -> | ||
console.log body | ||
test.ok /tpl.test1\s?=/.test body | ||
test.done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!!! 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
h1 Hello World |