Add support for additonal js and css resources

This commit is contained in:
Andreas Hocevar
2015-04-02 14:04:30 +02:00
parent 0077626c93
commit bc617e8135
2 changed files with 21 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
{{{ resources }}}
{{{ css_resource }}}
<link rel="stylesheet" href="../resources/prism/prism.css" type="text/css">
<script src="../resources/zeroclipboard/ZeroClipboard.min.js"></script>
@@ -59,6 +60,7 @@
&lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/{{ ol_version }}/ol.css" type="text/css"&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/{{ ol_version }}/ol.js"&gt;&lt;/script&gt;
{{ resources }}
{{#if css_inline}}
&lt;style&gt;
{{ css_inline }}

View File

@@ -8,6 +8,8 @@ var pjson = require('../package.json');
var fileRegEx = /([^\/^\.]*)\.html$/;
var cleanupJSRegEx = /.*(goog\.require(.*);|.*renderer: exampleNS\..*,?)[\n]*/g;
var isCssRegEx = /\.css$/;
var isJsRegEx = /\.js$/;
function main(callback) {
@@ -37,6 +39,23 @@ function main(callback) {
'.css">';
file.css_inline = fs.readFileSync(cssFile, 'utf-8');
}
if (file.resources) {
var resources = file.resources.split(',');
var resource;
for (var i = resources.length - 1; i >= 0; --i) {
resource = resources[i];
if (isJsRegEx.test(resource)) {
resources[i] = '<script src="' + resource + '"></script>"';
} else if (isCssRegEx.test(resource)) {
resources[i] = '<link rel="stylesheet" href="' + resource +
'">"';
} else {
callback(new Error('Resource ' + resource +
' is no .js or .css'));
}
file.resources = resources.join('\n');
}
}
}
}
}