Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Commit

Permalink
Colors that has less than 6 digits will be padded with zeroes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoyni committed Apr 4, 2016
1 parent f97bc46 commit 83585e7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
33 changes: 32 additions & 1 deletion backend/tools.js
@@ -1,7 +1,8 @@
var Database = require("./Database");
var Log = require("./Log");
var Utils = require("./Utils");
var bcrypt = require('bcrypt');
var bcrypt = require("bcrypt");
var BuilderUtils = require("../frontend/builders/BuilderUtils");

var tools = {
setpremium: function(email, premium) {
Expand Down Expand Up @@ -41,6 +42,36 @@ var tools = {
process.exit();
})
.catch(Log.error);
},

fixcolors: function() {
function fixColor(color) {
while (color.length < 6) {
color = "0" + color;
}
return color;
}

Database.connect_p(process.env.MONGO_URL)
.then(() => Database.models.Theme.find({}))
.then(themes => Promise.all(themes.map(theme => {
if (theme.styles) {
Object.keys(theme.styles).forEach(styleName => {
var style = theme.styles[styleName];
if (style.color) style.color = fixColor(style.color);
if (style.backgroundColor) style.backgroundColor = fixColor(style.backgroundColor);
if (style.markerColor) style.markerColor = fixColor(style.markerColor);
if (style.effectColor) style.effectColor = fixColor(style.effectColor);
});
BuilderUtils.fillCss(theme.styles);
return theme.save();
}
})))
.then(() => {
Log.info("Done");
process.exit();
})
.catch(Log.error);
}
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/builders/BuilderUtils.js
Expand Up @@ -27,7 +27,7 @@ var BuilderUtils = {
css += "border-bottom: 2px solid #" + item.effectColor + "; ";
}
if (item.effectType === 3) {
css += "border-bottom: 1px solid #" + item.effectColor + "; "; //TODO: this is should be wavy line
css += "border-bottom: 1px solid #" + item.effectColor + "; "; //TODO: this one should be wavy line
}
if (item.effectType === 4) {
css += "border: 1px solid #" + item.effectColor + "; ";
Expand Down
17 changes: 12 additions & 5 deletions frontend/builders/Idea.js
Expand Up @@ -29,6 +29,13 @@ var Idea = {
return Promise.resolve(null);
}

function fixColor(color) {
while (color.length < 6) {
color = "0" + color;
}
return color;
}

return new Promise((resolve, reject) => {
parseString(fileContent, function(err, theme) {
if (err || !theme) {
Expand All @@ -45,7 +52,7 @@ var Idea = {
var colors = scheme.colors && scheme.colors[0];
if (colors && colors.option) {
colors.option.forEach(function(option) {
styles[option.$.name.replace(/\./g, "$")] = { color: option.$.value, simple: true };
styles[option.$.name.replace(/\./g, "$")] = { color: fixColor(option.$.value), simple: true };
});
}

Expand All @@ -65,19 +72,19 @@ var Idea = {
style.italic = (val & 2) !== 0;
break;
case "FOREGROUND":
style.color = val;
style.color = fixColor(val);
break;
case "BACKGROUND":
style.backgroundColor = val;
style.backgroundColor = fixColor(val);
break;
case "ERROR_STRIPE_COLOR":
style.markerColor = val;
style.markerColor = fixColor(val);
break;
case "EFFECT_TYPE":
style.effectType = parseInt(val);
break;
case "EFFECT_COLOR":
style.effectColor = val;
style.effectColor = fixColor(val);
break;
}
});
Expand Down

0 comments on commit 83585e7

Please sign in to comment.