allow more flexible customization in pug
- Define some blocks in pug to allow replacement.
- Using JSON Editors ajaxBase
diff --git a/default/cve/conf.js b/default/cve/conf.js
index a4c003d..339a59a 100644
--- a/default/cve/conf.js
+++ b/default/cve/conf.js
@@ -1,10 +1,10 @@
var conf = require('../../config/conf');
var express = require('express')
-var router = express.Router()
+var router = express.Router();
const csurf = require('csurf');
var csrfProtection = csurf();
var package = require('../../package.json');
-module.exports= {
+module.exports = {
conf: {
title: 'CVE: Common Vulnerabilities and Exposures',
name: 'CVE',
@@ -662,7 +662,7 @@
"type": "string",
"minLength": 2,
"maxLength": 3999,
- "$ref": "/js/cwe-frequent.json"
+ "$ref": "js/cwe-frequent.json"
}
}
},
@@ -721,7 +721,7 @@
"type": "object",
"properties": {
"cvss": {
- "$ref": "/js/cvss.json"
+ "$ref": "js/cvss.json"
}
}
},
diff --git a/default/cve/render.pug b/default/cve/render.pug
index ce73b27..28dcacf 100644
--- a/default/cve/render.pug
+++ b/default/cve/render.pug
@@ -33,7 +33,7 @@
span.text
+mpara(cve.solution)
-
+block pageDef
mixin page(cve)
- var sourceText = {"INTERNAL":"This issue was found during internal product security testing or research.", "EXTERNAL":"This issue was discovered during an external security research.", "USER":"This issue was seen during production usage.", "UNKNOWN":""};
- var CDM = cve.CVE_data_meta;
diff --git a/public/js/editor.js b/public/js/editor.js
index e6d590c..b2f6987 100644
--- a/public/js/editor.js
+++ b/public/js/editor.js
@@ -834,6 +834,7 @@
input_height: '4em',
template: 'custom',
prompt_before_delete: false,
+ ajaxBase: ajaxBase,
// The schema for the editor
schema: docSchema
// Seed the form with a starting value
@@ -935,13 +936,13 @@
document.getElementById('save2').removeAttribute("style");
}
-function loadJSON(res, id, message) {
+function loadJSON(res, id, message) {
// workaround for JSON Editor issue with clearing arrays
// https://github.com/jdorn/json-editor/issues/617
if(docEditor) {
docEditor.destroy();
}
- docEditor = new JSONEditor(document.getElementById('editor'), docEditorOptions);
+ docEditor = new JSONEditor(document.getElementById('editor'), docEditorOptions);
docEditor.on('ready', function () {
docEditor.root.setValue(res, true);
infoMsg.textContent = message ? message : '';
@@ -974,8 +975,6 @@
});
}
-loadJSON(initJSON);
-
/*docEditor.on('ready', function () {
// Now the api methods will be available
if (initJSON) {
diff --git a/scripts/standalone.js b/scripts/standalone.js
index 798db44..a46c1cc 100644
--- a/scripts/standalone.js
+++ b/scripts/standalone.js
@@ -12,14 +12,17 @@
const pug = require('pug');
const conf = require('../config/conf-standalone');
const optSet = require('../models/set');
-
// Compile the template to a function string
-var cveEdit = pug.compileFile('default/cve/edit.pug', {compileDebug: false});
+
+var editTemplate = fs.existsSync('custom/cve/edit.pug') ? 'custom/cve/edit.pug' : 'default/cve/edit.pug';
+var renderTemplate = fs.existsSync('custom/cve/render.pug') ? 'custom/cve/render.pug' : 'default/cve/render.pug';
+
+var cveEdit = pug.compileFile(editTemplate, {compileDebug: false});
confOpts = {
cve: optSet('cve', ['default'].concat(process.argv.slice(2)))
}
-
-confOpts.cve.conf.uri = '/';
+console.log(confOpts.cve.render);
+confOpts.cve.conf.uri = '.';
var cveProps = confOpts.cve.schema.properties;
delete cveProps.CNA_private;
cveProps.CVE_data_meta.properties.STATE.enum =
@@ -37,7 +40,7 @@
allowAjax: false,
}));
-var pugRender = pug.compileFileClient('default/cve/render.pug', {
+var pugRender = pug.compileFileClient(renderTemplate, {
basedir: 'views',
name: 'pugRender',
compileDebug: false,
diff --git a/views/edit.pug b/views/edit.pug
index ebfed01..f3550e5 100644
--- a/views/edit.pug
+++ b/views/edit.pug
@@ -68,21 +68,23 @@
if !min
div(style="clear:both")
button.gap.btn.save(id="save2",style="visibility:hidden") SAVE
-
- script
- if conf.publicDefectURL
- | var defectURL = "!{conf.publicDefectURL}";
- | var idpath = "#{idpath}";
- | var allowAjax = "#{allowAjax}";
- | var schemaName = "#{schemaName}";
- | var postUrl = "#{postUrl?postUrl:''}";
- | var csrfToken = "#{csrfToken}";
- if doc && doc.body
- | var initJSON=!{JSON.stringify(doc.body).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029').replace(/</g, '\\u003C').replace(/>/g, '\\u003E').replace(/\//g, '\\u002F')};
- else
- | var initJSON = undefined;
- if min
- | var docSchema=!{JSON.stringify(opts && opts.schema ? opts.schema : '{}').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029').replace(/</g, '\\u003C').replace(/>/g, '\\u003E').replace(/\//g, '\\u002F')};
+
+ block initGlobals
+ script
+ if conf.publicDefectURL
+ | var defectURL = "!{conf.publicDefectURL}";
+ | var idpath = "#{idpath}";
+ | var allowAjax = "#{allowAjax}";
+ | var schemaName = "#{schemaName}";
+ | var postUrl = "#{postUrl?postUrl:''}";
+ | var csrfToken = "#{csrfToken}";
+ | var ajaxBase = "#{conf.basedir}";
+ if doc && doc.body
+ | var initJSON=!{JSON.stringify(doc.body).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029').replace(/</g, '\\u003C').replace(/>/g, '\\u003E').replace(/\//g, '\\u002F')};
+ else
+ | var initJSON = undefined;
+ if min
+ | var docSchema=!{JSON.stringify(opts && opts.schema ? opts.schema : '{}').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029').replace(/</g, '\\u003C').replace(/>/g, '\\u003E').replace(/\//g, '\\u002F')};
script(src=conf.basedir + 'js/util.js')
@@ -92,6 +94,10 @@
script(src=conf.ace,integrity=conf.aceHash,crossorigin="anonymous")
script(src=conf.basedir + 'js/' + schemaName + '/render.js')
script(src=conf.basedir + 'js/editor.js')
+
+ block loadEditor
+ script loadJSON(initJSON);
+
if doc && doc.body
script getChanges("#{doc_id}");
diff --git a/views/render.pug b/views/render.pug
index a700ee7..5f6d7ce 100644
--- a/views/render.pug
+++ b/views/render.pug
@@ -62,32 +62,31 @@
if v
= v.toJSON().substr(0,10)
-mixin page(obj)
- if obj !== null
- if typeof obj === 'string'
- if obj.length < 20
- span(class=obj)=obj
- else
- span.wrp=obj
- else if obj instanceof Array
- if obj.length > 0
- ol
- for v, k in obj
- li
- +page(v)
- else if typeof obj === 'object'
- for v, k in obj
- if obj.hasOwnProperty(k)
- .indent
- b.ico(class=k)=k
- | :
- |
- +page(v)
- else
- =obj
-
-
block content
+ block pageDef
+ mixin page(obj)
+ if obj !== null
+ if typeof obj === 'string'
+ if obj.length < 20
+ span(class=obj)=obj
+ else
+ span.wrp=obj
+ else if obj instanceof Array
+ if obj.length > 0
+ ol
+ for v, k in obj
+ li
+ +page(v)
+ else if typeof obj === 'object'
+ for v, k in obj
+ if obj.hasOwnProperty(k)
+ .indent
+ b.ico(class=k)=k
+ | :
+ |
+ +page(v)
+ else
+ =obj
.big=doc_id
if doc
if renderTemplate == 'default'