Skip to content

Commit

Permalink
Just use browserify to compile client side
Browse files Browse the repository at this point in the history
Also adds UMD support and removes reliance on MAKE file
  • Loading branch information
ForbesLindesay committed May 7, 2013
1 parent 00053c0 commit 72043cd
Show file tree
Hide file tree
Showing 13 changed files with 3,293 additions and 3,149 deletions.
6,155 changes: 3,220 additions & 2,935 deletions jade.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions jade.min.js

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions lib/compiler.js
Expand Up @@ -16,28 +16,6 @@ var nodes = require('./nodes')
, utils = require('./utils')
, parseJSExpression = require('character-parser').parseMax

// if browser
//
// if (!Object.keys) {
// Object.keys = function(obj){
// var arr = [];
// for (var key in obj) {
// if (obj.hasOwnProperty(key)) {
// arr.push(key);
// }
// }
// return arr;
// }
// }
//
// if (!String.prototype.trimLeft) {
// String.prototype.trimLeft = function(){
// return this.replace(/^\s+/, '');
// }
// }
//
// end


/**
* Initialize `Compiler` with the given `node`.
Expand Down
18 changes: 18 additions & 0 deletions lib/filters-client.js
@@ -0,0 +1,18 @@
/*!
* Jade - filters
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/

module.exports = filter;
function filter(name, str, options) {
if (typeof filter[name] === 'function') {
var res = filter[name](str, options);
} else {
throw new Error('unknown filter ":' + name + '"');
}
return res;
}
filter.exists = function (name, str, options) {
return typeof filter[name] === 'function';
};
2 changes: 0 additions & 2 deletions lib/jade.js
Expand Up @@ -12,9 +12,7 @@ var Parser = require('./parser')
, Lexer = require('./lexer')
, Compiler = require('./compiler')
, runtime = require('./runtime')
// if node
, fs = require('fs');
// end

/**
* Library version.
Expand Down
15 changes: 13 additions & 2 deletions package.json
Expand Up @@ -24,7 +24,8 @@
"uubench": "*",
"should": "*",
"less": "*",
"uglify-js": "*"
"uglify-js": "*",
"browserify": "~2.13.2"
},
"component": {
"scripts": {
Expand All @@ -33,6 +34,16 @@
},
"scripts": {
"test": "mocha -R spec",
"prepublish": "npm prune"
"prepublish": "npm prune",
"build": "npm run compile && npm run minify",
"compile": "npm run compile-full && npm run compile-runtime",
"compile-full": "browserify ./lib/jade.js --standalone jade -x ./node_modules/transformers > jade.js",
"compile-runtime": "browserify ./lib/runtime.js --standalone jade > runtime.js",
"minify": "npm run minify-full && npm run minify-runtime",
"minify-full": "uglifyjs < jade.js > jade.min.js",
"minify-runtime": "uglifyjs < runtime.js > runtime.min.js"
},
"browser": {
"./lib/filters.js": "./lib/filters-client.js"
}
}
13 changes: 9 additions & 4 deletions runtime.js
@@ -1,5 +1,6 @@
(function(e){if("function"==typeof bootstrap)bootstrap("jade",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeJade=e}else"undefined"!=typeof window?window.jade=e():global.jade=e()})(function(){var define,ses,bootstrap,module,exports;
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){

jade = (function(exports){
/*!
* Jade - runtime
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
Expand Down Expand Up @@ -133,7 +134,7 @@ exports.attrs = function attrs(obj, escaped){

exports.escape = function escape(html){
return String(html)
.replace(/&(?!(\w+|\#\d+);)/g, '&amp;')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
Expand All @@ -151,6 +152,7 @@ exports.escape = function escape(html){

exports.rethrow = function rethrow(err, filename, lineno){
if (!filename) throw err;
if (typeof window != 'undefined') throw err;

var context = 3
, str = require('fs').readFileSync(filename, 'utf8')
Expand All @@ -174,6 +176,9 @@ exports.rethrow = function rethrow(err, filename, lineno){
throw err;
};

return exports;
},{"fs":2}],2:[function(require,module,exports){
// nothing to see here... no file methods for the browser

})({});
},{}]},{},[1])(1)
});
;
2 changes: 1 addition & 1 deletion runtime.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

175 changes: 0 additions & 175 deletions support/compile.js

This file was deleted.

4 changes: 0 additions & 4 deletions support/foot.js

This file was deleted.

2 changes: 0 additions & 2 deletions support/head.js

This file was deleted.

10 changes: 10 additions & 0 deletions test/browser/index.html
@@ -0,0 +1,10 @@
<!DOCTYPE html><html><head></head><body><textarea id="input" placeholder="write jade here" style="width: 100%; min-height: 400px;">p
author
!= name</textarea><pre style="background: #ECECEC;width: 100%; min-height: 400px;"><code id="output"></code></pre><script src="../../jade.js"></script><script>var input = document.getElementById('input');
var output = document.getElementById('output');
setInterval(function () {
jade.render(input.value, {name: 'Forbes Lindesay', pretty: true}, function (err, res) {
if (err) throw err;
output.textContent = res;
})
}, 500)</script></body></html>
20 changes: 20 additions & 0 deletions test/browser/index.jade
@@ -0,0 +1,20 @@
!!! 5
html
head
body
textarea#input(placeholder='write jade here', style='width: 100%; min-height: 400px;').
p
author
!= name
pre(style='background: #ECECEC;width: 100%; min-height: 400px;')
code#output
script(src='../../jade.js')
script
var input = document.getElementById('input');
var output = document.getElementById('output');
setInterval(function () {
jade.render(input.value, {name: 'Forbes Lindesay', pretty: true}, function (err, res) {
if (err) throw err;
output.textContent = res;
})
}, 500)

2 comments on commit 72043cd

@domenic
Copy link
Contributor

@domenic domenic commented on 72043cd Jun 7, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@ForbesLindesay
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad you approve 😄. I think we may change to just using UMD directly for the runtime lib since it's dependency free.

Please sign in to comment.