Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

update runtime #1

Open
wants to merge 4 commits into from

3 participants

@retrofox

No description provided.

@TooTallNate

tests are failing it seems

@retrofox

yep. I just copied the code from visionmeadia/page lib/runtime.js to here.

@pateketrueke

:+1:

I did the same and everythings works nice!

This PR is required due new Jade features, just merge it.

@pateketrueke pateketrueke referenced this pull request in bjoerge/jade-runtime
Open

Update runtime? #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2014
  1. @retrofox

    core: update

    retrofox authored
  2. @retrofox

    pkg: bump 1.3.0

    retrofox authored
  3. @retrofox

    Release 1.0.3

    retrofox authored
  4. @retrofox

    Release 1.3.0

    retrofox authored
This page is out of date. Refresh to see the latest.
Showing with 114 additions and 67 deletions.
  1. +6 −0 History.md
  2. +106 −65 index.js
  3. +2 −2 package.json
View
6 History.md
@@ -0,0 +1,6 @@
+
+1.3.0 / 2014-03-03
+==================
+
+ * pkg: bump 1.3.0
+ * core: update
View
171 index.js
@@ -1,4 +1,4 @@
-'use strict'
+'use strict';
/**
* Merge two attribute objects giving precedence
@@ -13,25 +13,32 @@
*/
exports.merge = function merge(a, b) {
- var ac = a['class']
- var bc = b['class']
+ 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)
+ 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]
+ a[key] = b[key];
}
}
- return a
-}
+ return a;
+};
/**
* Filter null `val`s.
@@ -42,7 +49,7 @@ exports.merge = function merge(a, b) {
*/
function nulls(val) {
- return val != null && val !== ''
+ return val != null && val !== '';
}
/**
@@ -50,61 +57,89 @@ function nulls(val) {
*
* @param {*} val
* @return {String}
- * @api private
*/
-
+exports.joinClasses = joinClasses;
function joinClasses(val) {
- return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(' ') : val
+ return Array.isArray(val) ? val.map(joinClasses).filter(nulls).join(' ') : val;
}
/**
+ * 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 '';
+ }
+};
+
+/**
+ * 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 ('boolean' == typeof val || null == val) {
+ if (val) {
+ return ' ' + (terse ? key : key + '="' + key + '"');
+ } else {
+ return '';
+ }
+ } else if (0 == key.indexOf('data') && 'string' != typeof val) {
+ return ' ' + key + "='" + JSON.stringify(val).replace(/'/g, '&apos;') + "'";
+ } else if (escaped) {
+ return ' ' + key + '="' + exports.escape(val) + '"';
+ } else {
+ return ' ' + key + '="' + val + '"';
+ }
+};
+
+/**
* Render the given attributes object.
*
* @param {Object} obj
* @param {Object} escaped
* @return {String}
- * @api private
*/
+exports.attrs = function attrs(obj, terse){
+ var buf = [];
-exports.attrs = function attrs(obj, escaped){
- var buf = []
- var terse = obj.terse
-
- delete obj.terse;
- var keys = Object.keys(obj)
+ var keys = Object.keys(obj);
if (keys.length) {
- buf.push('')
- for (var i = 0; i < keys.length; i++) {
+ for (var i = 0; i < keys.length; ++i) {
var key = keys[i]
- var val = obj[key]
+ , val = obj[key];
- if ('boolean' == typeof val || null == val) {
- if (val) {
- if (terse) buf.push(key)
- else buf.push(key + '="' + key + '"')
- }
- } else if (0 == key.indexOf('data') && 'string' != typeof val) {
- buf.push(key + "='" + JSON.stringify(val) + "'")
- } else if ('class' == key) {
- if (escaped && escaped[key]){
- if (val = exports.escape(joinClasses(val))) {
- buf.push(key + '="' + val + '"')
- }
- } else {
- if (val = joinClasses(val)) {
- buf.push(key + '="' + val + '"')
- }
+ if ('class' == key) {
+ if (val = joinClasses(val)) {
+ buf.push(' ' + key + '="' + val + '"');
}
- } else if (escaped && escaped[key]) {
- buf.push(key + '="' + exports.escape(val) + '"')
} else {
- buf.push(key + '="' + val + '"')
+ buf.push(exports.attr(key, val, false, terse));
}
}
}
- return buf.join(' ');
+ return buf.join('');
};
/**
@@ -116,11 +151,13 @@ exports.attrs = function attrs(obj, escaped){
*/
exports.escape = function escape(html){
- return String(html)
+ var result = String(html)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
- .replace(/"/g, '&quot;')
+ .replace(/"/g, '&quot;');
+ if (result === '' + html) return html;
+ else return result;
};
/**
@@ -130,34 +167,38 @@ exports.escape = function escape(html){
* @param {Error} err
* @param {String} filename
* @param {String} lineno
- * @param {String} source
* @api private
*/
-exports.rethrow = function rethrow(err, filename, lineno, source){
- if (!(err instanceof Error)) throw err
- if ((typeof window != 'undefined' || !filename) && !source) {
- err.message += ' on line ' + lineno
- throw err
+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 {
- source = source || require('fs').readFileSync(filename, 'utf8')
+ str = str || require('fs').readFileSync(filename, 'utf8')
} catch (ex) {
rethrow(err, null, lineno)
}
var context = 3
- var lines = source.split('\n')
- var start = Math.max(lineno - context, 0)
- var end = Math.min(lines.length, lineno + context)
+ , 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')
+ 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
-}
+ err.path = filename;
+ err.message = (filename || 'Jade') + ':' + lineno
+ + '\n' + context + '\n\n' + err.message;
+ throw err;
+};
+
View
4 package.json
@@ -1,6 +1,6 @@
{
"name": "runtime-jade",
- "version": "1.0.0",
+ "version": "1.3.0",
"description": "Just the runtime part of jade",
"keywords": [],
"dependencies": {},
@@ -17,4 +17,4 @@
},
"author": "ForbesLindesay",
"license": "MIT"
-}
+}
Something went wrong with that request. Please try again.