lego-bigpipe
Advanced tools
Comparing version 0.1.7 to 0.1.8-1
40
index.js
@@ -6,3 +6,3 @@ 'use strict'; | ||
meta: ' <meta name="<%= name %>" content="<%= content %>">\n', | ||
styleLink: ' <link rel="stylesheet" type="text/css" href="<%= url %>">\n', | ||
styleLink: ' <link rel="stylesheet" href="<%= url %>">\n', | ||
style: ' <style><%- content %></style>\n', | ||
@@ -87,23 +87,29 @@ scriptLink: ' <script src="<%= url %>"></script>\n', | ||
each(data.body.units, function (unit) { | ||
each(unit.css, function (m) {ids[m + '.css'] = 1;}); | ||
each(unit.css, function (m) {ids[m + '.css.js'] = 1;}); | ||
if (data.mode === 'inline') each(unit.js, function (m) {ids[m + '.js'] = 1;}); | ||
}); | ||
ids = Object.keys(ids); | ||
// inline mode: put all mods' content in head | ||
// inline mode: put mods' content in head | ||
if (data.mode === 'inline') { | ||
each(ids, function (id) { | ||
pre += tpl.script({ | ||
content: data.mods[id] | ||
}); | ||
}); | ||
// combo mode: put all mods' css combo in head | ||
} else if (config.combo && ids.length) { | ||
var mods = data.mods || {}; | ||
for (var i = 0; i < ids.length; i++) { | ||
var id = ids[i]; | ||
if (mods[id]) { | ||
pre += tpl.script({content: mods[id]}); | ||
ids.splice(i--, 1); | ||
} | ||
} | ||
} | ||
// combo mode: put mods' url of css combo in head | ||
if (config.combo && ids.length) { | ||
pre += tpl.scriptLink({ | ||
url: genUrl(ids, '.js', config) | ||
url: genUrl(ids, config) | ||
}); | ||
// put all mods' css in head | ||
// put mods' url of css in head | ||
} else { | ||
each(ids, function (id) { | ||
pre += tpl.scriptLink({ | ||
url: genUrl(id, '.js', config) | ||
url: genUrl(id, config) | ||
}); | ||
@@ -114,3 +120,3 @@ }); | ||
pre += ' </head>\n<body>\n'; | ||
pre += '</head>\n<body>\n'; | ||
@@ -172,9 +178,5 @@ var post = ''; | ||
function genUrl(ids, ext, config) { | ||
function genUrl(ids, config) { | ||
if (type(ids) === 'string') ids = [ids]; | ||
else ids = ids.slice(); | ||
ext = ext || ''; | ||
each(ids, function (id, i) { | ||
ids[i] = id + ext; | ||
}); | ||
@@ -181,0 +183,0 @@ var url = ids.length > 1 && config.comboPattern || config.urlPattern; |
{ | ||
"name": "lego-bigpipe", | ||
"version": "0.1.7", | ||
"version": "0.1.8-1", | ||
"description": "a bigpipe builder for scrat-lego", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
22
test.js
@@ -78,3 +78,3 @@ // (╯°□°)╯︵oƃǝ˥ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <meta name="HandheldFriendly" content="true">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <meta name="HandheldFriendly" content="true">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">\n</head>\n<body>\n'); | ||
}); | ||
@@ -89,3 +89,3 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <title>Hello</title>\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <title>Hello</title>\n</head>\n<body>\n'); | ||
}); | ||
@@ -104,3 +104,3 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <link rel="stylesheet" type="text/css" href="a.css">\n <style>html { display: none; }</style>\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <link rel="stylesheet" href="a.css">\n <style>html { display: none; }</style>\n</head>\n<body>\n'); | ||
}); | ||
@@ -119,3 +119,3 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script src="a.js"></script>\n <script>console.log(\'Hello\');</script>\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script src="a.js"></script>\n <script>console.log(\'Hello\');</script>\n</head>\n<body>\n'); | ||
}); | ||
@@ -134,3 +134,3 @@ | ||
}); | ||
v.should.have.property('post', ' <link rel="stylesheet" type="text/css" href="a.css">\n <style>html { display: none; }</style>\n</body>\n</html>'); | ||
v.should.have.property('post', ' <link rel="stylesheet" href="a.css">\n <style>html { display: none; }</style>\n</body>\n</html>'); | ||
}); | ||
@@ -169,3 +169,3 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script src="/u/u1/u11.css.js"></script>\n <script src="/u/u1/u12.css.js"></script>\n <script src="/u/u2/u21.css.js"></script>\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script src="/u/u1/u11.css.js"></script>\n <script src="/u/u1/u12.css.js"></script>\n <script src="/u/u2/u21.css.js"></script>\n</head>\n<body>\n'); | ||
}); | ||
@@ -190,3 +190,3 @@ | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script src="/c/u/u1/u11.css.js;u/u1/u12.css.js;u/u2/u21.css.js"></script>\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script src="/c/u/u1/u11.css.js;u/u1/u12.css.js;u/u2/u21.css.js"></script>\n</head>\n<body>\n'); | ||
}); | ||
@@ -210,6 +210,6 @@ | ||
mods: { | ||
'u/u1/u11.css': 'lego.defineCSS("u/u1/u11.css.js", "html { display: none; }");', | ||
'u/u1/u12.css': 'lego.defineCSS("u/u1/u12.css.js", "html { display: block; }");', | ||
'u/u1/u11.css.js': 'lego.defineCSS("u/u1/u11.css.js", "html { display: none; }");', | ||
'u/u1/u12.css.js': 'lego.defineCSS("u/u1/u12.css.js", "html { display: block; }");', | ||
'u/u1/u11.js': 'lego.define("u/u1/u11.js", "console.log(\"Hello\");");', | ||
'u/u2/u21.css': 'lego.defineCSS("u/u2/u21.css.js", "body { display: none; }");' | ||
'u/u2/u21.css.js': 'lego.defineCSS("u/u2/u21.css.js", "body { display: none; }");' | ||
} | ||
@@ -221,4 +221,4 @@ }, { | ||
}); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script>lego.defineCSS("u/u1/u11.css.js", "html { display: none; }");</script>\n <script>lego.defineCSS("u/u1/u12.css.js", "html { display: block; }");</script>\n <script>lego.define("u/u1/u11.js", "console.log("Hello");");</script>\n <script>lego.defineCSS("u/u2/u21.css.js", "body { display: none; }");</script>\n </head>\n<body>\n'); | ||
v.should.have.property('pre', '<!DOCTYPE html>\n<!--STATUS OK-->\n<html>\n<head>\n <meta charset="utf-8">\n <script>lego.defineCSS("u/u1/u11.css.js", "html { display: none; }");</script>\n <script>lego.defineCSS("u/u1/u12.css.js", "html { display: block; }");</script>\n <script>lego.define("u/u1/u11.js", "console.log("Hello");");</script>\n <script>lego.defineCSS("u/u2/u21.css.js", "body { display: none; }");</script>\n</head>\n<body>\n'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13733