Skip to content

Commit

Permalink
Moved jsdebug default styles to an object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joscha Rohmann authored and Kanaye committed Sep 10, 2016
1 parent bc129d7 commit 5dc25a4
Showing 1 changed file with 24 additions and 46 deletions.
70 changes: 24 additions & 46 deletions lib/blocks/jsdebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ blocks.debug = {
}

message
.addSpan('Arguments mismatch:', { background: 'yellow'})
.addSpan('Arguments mismatch:', defaultStyles.info)
.addText(' ');

if (one) {
Expand Down Expand Up @@ -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 ');
Expand All @@ -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);
}
Expand All @@ -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();

Expand Down Expand Up @@ -244,7 +244,7 @@ function addError(message, error, method, paramNames) {
}

message.beginSpan({
'background-color': '#EEE'
'background': '#EEE'
});

message.addText(method.name + '(');
Expand All @@ -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) {
Expand All @@ -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(', ');
}
Expand All @@ -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]);
}
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -828,3 +793,16 @@ var highlightjs = {
color: '#e7635f'
}
};

var defaultStyles = {
warning: {
background: 'orange'
},
error: {
background: 'red',
color: 'white'
},
info: {
background: 'yellow'
}
};

0 comments on commit 5dc25a4

Please sign in to comment.