jade-client-connect
Advanced tools
Comparing version
(function() { | ||
var fs, jade, path; | ||
var compile, fs, jade, opts, path, source, templates, watch; | ||
fs = require("fs"); | ||
jade = require("jade"); | ||
path = require("path"); | ||
module.exports = function(options) { | ||
var ns, re, src, templates, url; | ||
watch = require("watch"); | ||
templates = ""; | ||
source = ""; | ||
opts = {}; | ||
compile = function(src, options) { | ||
var ns; | ||
if (src == null) { | ||
src = source; | ||
} | ||
if (options == null) { | ||
options = {}; | ||
options = opts; | ||
} | ||
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) { | ||
if (err) { | ||
return console.log(err); | ||
} else { | ||
return files.forEach(function(file) { | ||
@@ -33,4 +38,20 @@ var filename, fn, nm, tpl; | ||
}); | ||
return templates; | ||
}; | ||
module.exports = function(src, options) { | ||
var re, url; | ||
if (options == null) { | ||
options = {}; | ||
} | ||
if (!src) { | ||
throw new Error("Source directory not included"); | ||
} | ||
templates = compile(src, options); | ||
source = src; | ||
opts = options; | ||
url = options.url || "templates.js"; | ||
re = new RegExp(".*" + url + "$"); | ||
watch.watchTree(src, function() { | ||
return compile(); | ||
}); | ||
return function(req, res, next) { | ||
@@ -37,0 +58,0 @@ if (re.test(req.url)) { |
{ | ||
"name": "jade-client-connect", | ||
"description": "Jade Client Connect - A compiler to help use templates on a web client", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Ed Siok <@sioked>", | ||
"main": "./lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url" : "http://github.com/sioked/jade-client-connect.git" | ||
}, | ||
"dependencies": { | ||
"uglify-js" : "1.0.7", | ||
"jade" : "0.15.4" | ||
"jade" : "0.15.4", | ||
"watch" : "0.3.2" | ||
}, | ||
@@ -15,4 +19,5 @@ "devDependencies": { | ||
"nodeunit": "0.5.1", | ||
"request" : "2.1.1" | ||
"request" : "2.1.1", | ||
"rimraf" : "latest" | ||
} | ||
} |
@@ -15,3 +15,3 @@ #Jade Client Connect | ||
app = require('connect').createServer(); | ||
app.use(require('./jade-client-connect/')()); | ||
app.use(require('./jade-client-connect/')(__dirname + "/views")); | ||
``` | ||
@@ -30,10 +30,8 @@ | ||
var options = { | ||
src : 'views', | ||
ns : 'tpl' | ||
} | ||
app.use(require('./jade-client-connect/')(options)); | ||
app.use(require('./jade-client-connect/')(__dirname+"/views", options)); | ||
``` | ||
The src option is the folder that contains all of the jade templates. | ||
This should be relative to your currently running application. Each of | ||
The src option is the folder that contains all of the jade templates. Each of | ||
the files inside this directory will be compiled as a javascript jade | ||
@@ -40,0 +38,0 @@ template in the ns client namespace. By default the namespace is tpl so |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
9388
18.12%115
22.34%2
-33.33%5
25%45
-4.26%+ Added
+ Added
- Removed
- Removed