From 5dc25a49faad5b3a7ce4096f472cf82cca1de4bb Mon Sep 17 00:00:00 2001 From: Joscha Rohmann Date: Mon, 29 Aug 2016 22:00:21 +0200 Subject: [PATCH] Moved jsdebug default styles to an object. --- lib/blocks/jsdebug.js | 70 +++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/lib/blocks/jsdebug.js b/lib/blocks/jsdebug.js index 5e88122..b92cadc 100644 --- a/lib/blocks/jsdebug.js +++ b/lib/blocks/jsdebug.js @@ -52,7 +52,7 @@ blocks.debug = { } message - .addSpan('Arguments mismatch:', { background: 'yellow'}) + .addSpan('Arguments mismatch:', defaultStyles.info) .addText(' '); if (one) { @@ -95,10 +95,10 @@ blocks.debug = { queryNotExists: debugFunc(function (query, element) { var message = blocks.debug.Message(); message.beginSpan({ 'font-weight': 'bold' }); - message.addSpan('Warning:', { background: 'orange', padding: '0 3px' }); + message.addSpan('Warning:', blocks.extend({}, defaultStyles.warning, {padding: '0 3px' })); message.addText(' '); - message.addSpan(query.name, { background: 'red', color: 'white' }); + message.addSpan(query.name, defaultStyles.error); message.addSpan('(' + query.params.join(', ') + ')', { background: '#EEE' }); message.addText(' - data-query '); @@ -122,14 +122,14 @@ blocks.debug = { message.beginCollapsedGroup(); message.beginSpan({ 'font-weight': 'bold' }); - message.addSpan('Critical:', { background: 'red', color: 'white' }); + message.addSpan('Critical:', defaultStyles.error); message.addText(' '); message.beginSpan({ background: '#EEE' }); message.addText(query.name + '('); for (var i = 0; i < params.length; i++) { param = params[i]; if (param == failedParameter) { - message.addSpan(param, { background: 'red', color: 'white' }); + message.addSpan(param, defaultStyles.error); } else { message.addText(param); } @@ -154,9 +154,9 @@ blocks.debug = { var message = new blocks.debug.Message(); message.beginSpan({ 'font-weight': 'bold' }); - message.addSpan('Critical:', { background: 'red', color: 'white' }); + message.addSpan('Critical:', defaultStyles.error); message.addText(' '); - message.addSpan('{{' + expressionText + '}}', { background: 'red', color: 'white' }); + message.addSpan('{{' + expressionText + '}}', defaultStyles.error); message.addText(' - exception thrown while executing expression'); message.endSpan(); @@ -244,7 +244,7 @@ function addError(message, error, method, paramNames) { } message.beginSpan({ - 'background-color': '#EEE' + 'background': '#EEE' }); message.addText(method.name + '('); @@ -258,11 +258,7 @@ function addError(message, error, method, paramNames) { } for (index = error.actual; index < error.expected; index++) { message - .beginSpan({ - 'background-color': 'red', - padding: '0 5px', - color: 'white' - }) + .beginSpan(blocks.extend({}, defaultStyles.error, { padding: '0 5px'})) .addText(paramNames[index] || '?') .endSpan(); if (index != error.expected - 1) { @@ -279,11 +275,7 @@ function addError(message, error, method, paramNames) { message.addText(', '); } for (index = error.expected; index < error.actual; index++) { - message.addSpan(paramNames[index], { - 'background-color': 'red', - 'text-decoration': 'line-through', - color: 'white' - }); + message.addSpan(paramNames[index], blocks.extend({}, defaultStyles.error,{'text-decoration': 'line-through'})); if (index != error.actual - 1) { message.addText(', '); } @@ -295,10 +287,7 @@ function addError(message, error, method, paramNames) { case 'param': for (index = 0; index < paramNames.length; index++) { if (method.params[index] == error.param) { - message.addSpan(paramNames[index], { - 'background-color': 'red', - color: 'white' - }); + message.addSpan(paramNames[index], defaultStyles.error); } else { message.addText(paramNames[index]); } @@ -556,30 +545,6 @@ function addMethodSignature(message, method) { message.newLine(); } -function examples(method) { - var examples = method.examples; - - if (examples) { - console.groupCollapsed('%cUsage examples', 'color: blue;'); - - for (var i = 0; i < examples.length; i++) { - console.log(examples[i].code); - if (i != examples.length - 1) { - console.log('-------------------------------'); - } - } - - console.groupEnd(); - } -} - -function params(method) { - var params = method.params; - for (var i = 0; i < params.length; i++) { - console.log(' ' + method.params[i].name + ': ' + method.params[i].description); - } -} - function hasArgumentsParam(method) { var params = method.params; for (var i = 0; i < params.length; i++) { @@ -828,3 +793,16 @@ var highlightjs = { color: '#e7635f' } }; + +var defaultStyles = { + warning: { + background: 'orange' + }, + error: { + background: 'red', + color: 'white' + }, + info: { + background: 'yellow' + } +}; \ No newline at end of file