Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/compiler/plugins/jade.js

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"stylus": "0.49.*",
"nib": "1.0.*",
"handlebars": "2.0.0-alpha.1",
"jade": "1.8.*",
"velocityjs": "0.4.x",
"tiny-lr": "0.0.7",
"gaze": "0.5.1",
Expand Down
26 changes: 26 additions & 0 deletions src/compiler/plugins/jade.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syspath = require 'path'
jade = require 'jade'


exports.contentType = 'javascript'

exports.process = (txt, path, module, cb)->
try
# console.log arguments
name = syspath.basename path, '.jade'
txt = jade.compileClient txt,
name: ' '
filename: path
doctype: 'html'

builded = """
if (typeof window.QTMPL === "undefined") window.QTMPL = {};
window.QTMPL["#{name}"] = #{txt};
if (typeof module !== "undefined") module.exports = window.QTMPL["#{name}"];
"""

cb null, builded
catch e
cb e


8 changes: 6 additions & 2 deletions testcase/modular/case/fekit.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

"scripts/page-a.js" ,
{ "path" : "scripts/page-b.js" , "parents" : [ "scripts/page-a.js" ] } ,
{ "path" : "scripts/page-c.js" , "no_version" : true }
]
{ "path" : "scripts/page-c.js" , "no_version" : true },
"scripts/page-d.js"
],
"dependencies": {
"jade-web": "1.0.1"
}
}
15 changes: 15 additions & 0 deletions testcase/modular/case/fekit_modules/jade-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Jade Template Engine
====================

Jade Template Engine Web Browser runtime

## Jade 模板引擎

<http://jade-lang.com/>


## fekit

<https://github.com/rinh/fekit>

<https://github.com/netwjx/fekit>
12 changes: 12 additions & 0 deletions testcase/modular/case/fekit_modules/jade-web/fekit.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compiler": "component",
"name": "jade-web",
"version": "1.0.1",
"author" : "shawn.cao",
"email" : "shawn.cao@qunar.com",
"description" : "Jade Template Engine Web Browser runtime",
"repository":"https://github.com/netwjx/jade-web.git",
"dependencies": {},
"alias": {},
"export": []
}
1 change: 1 addition & 0 deletions testcase/modular/case/fekit_modules/jade-web/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this.jade = require('./runtime.js');
238 changes: 238 additions & 0 deletions testcase/modular/case/fekit_modules/jade-web/src/runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jade=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';

/**
* Merge two attribute objects giving precedence
* to values in object `b`. Classes are special-cased
* allowing for arrays and merging/joining appropriately
* resulting in a string.
*
* @param {Object} a
* @param {Object} b
* @return {Object} a
* @api private
*/

exports.merge = function merge(a, b) {
if (arguments.length === 1) {
var attrs = a[0];
for (var i = 1; i < a.length; i++) {
attrs = merge(attrs, a[i]);
}
return attrs;
}
var ac = a['class'];
var bc = b['class'];

if (ac || bc) {
ac = ac || [];
bc = bc || [];
if (!Array.isArray(ac)) ac = [ac];
if (!Array.isArray(bc)) bc = [bc];
a['class'] = ac.concat(bc).filter(nulls);
}

for (var key in b) {
if (key != 'class') {
a[key] = b[key];
}
}

return a;
};

/**
* Filter null `val`s.
*
* @param {*} val
* @return {Boolean}
* @api private
*/

function nulls(val) {
return val != null && val !== '';
}

/**
* join array as classes.
*
* @param {*} val
* @return {String}
*/
exports.joinClasses = joinClasses;
function joinClasses(val) {
return (Array.isArray(val) ? val.map(joinClasses) :
(val && typeof val === 'object') ? Object.keys(val).filter(function (key) { return val[key]; }) :
[val]).filter(nulls).join(' ');
}

/**
* Render the given classes.
*
* @param {Array} classes
* @param {Array.<Boolean>} escaped
* @return {String}
*/
exports.cls = function cls(classes, escaped) {
var buf = [];
for (var i = 0; i < classes.length; i++) {
if (escaped && escaped[i]) {
buf.push(exports.escape(joinClasses([classes[i]])));
} else {
buf.push(joinClasses(classes[i]));
}
}
var text = joinClasses(buf);
if (text.length) {
return ' class="' + text + '"';
} else {
return '';
}
};


exports.style = function (val) {
if (val && typeof val === 'object') {
return Object.keys(val).map(function (style) {
return style + ':' + val[style];
}).join(';');
} else {
return val;
}
};
/**
* Render the given attribute.
*
* @param {String} key
* @param {String} val
* @param {Boolean} escaped
* @param {Boolean} terse
* @return {String}
*/
exports.attr = function attr(key, val, escaped, terse) {
if (key === 'style') {
val = exports.style(val);
}
if ('boolean' == typeof val || null == val) {
if (val) {
return ' ' + (terse ? key : key + '="' + key + '"');
} else {
return '';
}
} else if (0 == key.indexOf('data') && 'string' != typeof val) {
if (JSON.stringify(val).indexOf('&') !== -1) {
console.warn('Since Jade 2.0.0, ampersands (`&`) in data attributes ' +
'will be escaped to `&amp;`');
};
if (val && typeof val.toISOString === 'function') {
console.warn('Jade will eliminate the double quotes around dates in ' +
'ISO form after 2.0.0');
}
return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, '&apos;') + "'";
} else if (escaped) {
if (val && typeof val.toISOString === 'function') {
console.warn('Jade will stringify dates in ISO form after 2.0.0');
}
return ' ' + key + '="' + exports.escape(val) + '"';
} else {
if (val && typeof val.toISOString === 'function') {
console.warn('Jade will stringify dates in ISO form after 2.0.0');
}
return ' ' + key + '="' + val + '"';
}
};

/**
* Render the given attributes object.
*
* @param {Object} obj
* @param {Object} escaped
* @return {String}
*/
exports.attrs = function attrs(obj, terse){
var buf = [];

var keys = Object.keys(obj);

if (keys.length) {
for (var i = 0; i < keys.length; ++i) {
var key = keys[i]
, val = obj[key];

if ('class' == key) {
if (val = joinClasses(val)) {
buf.push(' ' + key + '="' + val + '"');
}
} else {
buf.push(exports.attr(key, val, false, terse));
}
}
}

return buf.join('');
};

/**
* Escape the given string of `html`.
*
* @param {String} html
* @return {String}
* @api private
*/

exports.escape = function escape(html){
var result = String(html)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
if (result === '' + html) return html;
else return result;
};

/**
* Re-throw the given `err` in context to the
* the jade in `filename` at the given `lineno`.
*
* @param {Error} err
* @param {String} filename
* @param {String} lineno
* @api private
*/

exports.rethrow = function rethrow(err, filename, lineno, str){
if (!(err instanceof Error)) throw err;
if ((typeof window != 'undefined' || !filename) && !str) {
err.message += ' on line ' + lineno;
throw err;
}
try {
str = str
} catch (ex) {
rethrow(err, null, lineno)
}
var context = 3
, lines = str.split('\n')
, start = Math.max(lineno - context, 0)
, end = Math.min(lines.length, lineno + context);

// Error context
var context = lines.slice(start, end).map(function(line, i){
var curr = i + start + 1;
return (curr == lineno ? ' > ' : ' ')
+ curr
+ '| '
+ line;
}).join('\n');

// Alter exception message
err.path = filename;
err.message = (filename || 'Jade') + ':' + lineno
+ '\n' + context + '\n\n' + err.message;
throw err;
};

},{"fs":2}],2:[function(require,module,exports){

},{}]},{},[1])(1)
});
8 changes: 8 additions & 0 deletions testcase/modular/case/src/scripts/page-d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require("jade-web")

var d = require("./pageD.jade");

console.info(d({
pageTitle: "hello world",
youAreUsingJade: false
}));
20 changes: 20 additions & 0 deletions testcase/modular/case/src/scripts/pageD.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
doctype html
html(lang="en")
head
title= pageTitle
script(type='text/javascript').
if (foo) {
bar(1 + 5)
}
body
h1 Jade - node template engine
#container.col
if youAreUsingJade
p You are amazing
else
p Get on it!
p.
Jade is a terse and simple
templating language with a
strong focus on performance
and powerful features.