mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Make theme able to load custom javascript (#1211)
* Make theme able to load custom javascript - Look for the field 'customScript' in editorTheme (settings.js) - Add it to mustach context - Load list on template side (index.mst) * Add unit tests for customScripts * Code review edits : generic behavior for theme.page.[css|scripts] - Use the same way to share css and javascript files from a theme - Allow string instead of array for theme.page.scripts - Remove old customScript field
This commit is contained in:
@@ -57,6 +57,24 @@ function serveFile(app,baseUrl,file) {
|
||||
}
|
||||
}
|
||||
|
||||
function serveFilesFromTheme(themeValue, themeApp, directory) {
|
||||
var result = [];
|
||||
if (themeValue) {
|
||||
var array = themeValue;
|
||||
if (!util.isArray(array)) {
|
||||
array = [array];
|
||||
}
|
||||
|
||||
for (i=0;i<array.length;i++) {
|
||||
url = serveFile(themeApp,directory,array[i]);
|
||||
if (url) {
|
||||
result.push(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: function(runtime) {
|
||||
var settings = runtime.settings;
|
||||
@@ -76,20 +94,15 @@ module.exports = {
|
||||
var themeApp = express();
|
||||
|
||||
if (theme.page) {
|
||||
if (theme.page.css) {
|
||||
var styles = theme.page.css;
|
||||
if (!util.isArray(styles)) {
|
||||
styles = [styles];
|
||||
}
|
||||
themeContext.page.css = [];
|
||||
|
||||
for (i=0;i<styles.length;i++) {
|
||||
url = serveFile(themeApp,"/css/",styles[i]);
|
||||
if (url) {
|
||||
themeContext.page.css.push(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
themeContext.page.css = serveFilesFromTheme(
|
||||
themeContext.page.css,
|
||||
themeApp,
|
||||
"/css/")
|
||||
themeContext.page.scripts = serveFilesFromTheme(
|
||||
themeContext.page.scripts,
|
||||
themeApp,
|
||||
"/scripts/")
|
||||
|
||||
if (theme.page.favicon) {
|
||||
url = serveFile(themeApp,"/favicon/",theme.page.favicon)
|
||||
|
Reference in New Issue
Block a user