lego-bigpipe
Advanced tools
Comparing version 0.1.0 to 0.1.1
53
index.js
@@ -12,9 +12,15 @@ 'use strict'; | ||
var pagelet = {}; | ||
var bigpipe = ''; | ||
var quickling = ''; | ||
pagelet.id = data.code; | ||
pagelet.js = data.js || []; | ||
var bigpipe = '<script>lego.onPageletArrive(' + JSON.stringify(pagelet) + ')</script>'; | ||
if (data.js) { | ||
pagelet.js = data.js; | ||
bigpipe = '<script>lego.onPageletArrive(' + JSON.stringify(pagelet) + ')</script>'; | ||
} | ||
if (data.source && data.data) { | ||
pagelet.html = ejs.render(data.source, {locals: data.data}); | ||
} else if (data.source) { | ||
pagelet.html = data.source; | ||
} | ||
@@ -24,4 +30,6 @@ | ||
pagelet.css = data.css || []; | ||
var quickling = 'lego.onPageletArrive(' + JSON.stringify(pagelet) + ');'; | ||
if (data.css) pagelet.css = data.css; | ||
if (pagelet.html || pagelet.js || pagelet.css) { | ||
quickling = 'lego.onPageletArrive(' + JSON.stringify(pagelet) + ');'; | ||
} | ||
@@ -36,2 +44,4 @@ return { | ||
exports.view = function (data, config) { | ||
if (!data.code) data.code = uuid(); | ||
var pre = '<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n'; | ||
@@ -58,16 +68,28 @@ if (data.head) { | ||
}); | ||
} | ||
// combo units' css | ||
if (data.body) { | ||
var comboIds = []; | ||
each(data.body.units, function (unit) { | ||
if (unit.css) comboIds = comboIds.concat(unit.css); | ||
// put units' css in head | ||
if (data.body) { | ||
var comboIds = {}; | ||
each(data.body.units, function (unit) { | ||
each(unit.css, function (c) { | ||
comboIds[c] = 1; | ||
}); | ||
if (comboIds.length) { | ||
}); | ||
comboIds = Object.keys(comboIds); | ||
if (comboIds.length) { | ||
if (config.combo) { | ||
pre += ejs.render(styleLinkTpl, {locals: { | ||
url: genUrl(comboIds, '.css.js', config) | ||
}}); | ||
} else { | ||
each(comboIds, function (id) { | ||
pre += ejs.render(styleLinkTpl, {locals: { | ||
url: genUrl(id, '.css.js', config) | ||
}}); | ||
}); | ||
} | ||
} | ||
} | ||
pre += ' </head>\n<body>\n'; | ||
@@ -133,3 +155,4 @@ | ||
function genUrl(ids, ext, config) { | ||
ids = ids.slice(); | ||
if (type(ids) === 'string') ids = [ids]; | ||
else ids = ids.slice(); | ||
ext = ext || ''; | ||
@@ -143,2 +166,10 @@ each(ids, function (id, i) { | ||
return url; | ||
} | ||
// from jqMobi | ||
function uuid() { | ||
function s4() { | ||
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); | ||
} | ||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); | ||
} |
{ | ||
"name": "lego-bigpipe", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "a bigpipe builder for scrat-lego", | ||
"license": "MIT", | ||
"main": ".", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"author": { | ||
@@ -18,3 +21,7 @@ "name": "Hinc Liu", | ||
"ejs": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^1.21.4", | ||
"should": "^4.0.4" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11743
6
318
2
1