Skip to content

Commit

Permalink
Merge pull request #148 from TrigenSoftware/dev
Browse files Browse the repository at this point in the history
Some fixes, some mods
  • Loading branch information
Hayden Bleasel authored Aug 22, 2016
2 parents edbb2f8 + 324d337 commit 0f063be
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 97 deletions.
1 change: 1 addition & 0 deletions config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"version": "1.0",
"logging": false,
"online": false,
"preferOnline": false,
"pipeHTML": false,
"icons": {
"android": true,
Expand Down
6 changes: 6 additions & 0 deletions config/platform-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"offset": {
"platforms": ["appleIcon", "firefox", "coast"],
"defaultTo": 0
}
}
9 changes: 5 additions & 4 deletions config/rfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"desktop_browser": {},
"ios": {
"picture_aspect": "background_and_margin",
"margin": "4",
"margin": "0",
"background_color": "#FFFFFF",
"startup_image": {
"background_color": "#FFFFFF"
Expand All @@ -25,7 +25,8 @@
"firefox_app": {
"picture_aspect": "circle",
"keep_picture_in_circle": "true",
"circle_inner_margin": "5",
"circle_inner_margin": "0",
"margin": "0",
"background_color": "#FFFFFF",
"manifest": {
"app_name": "Favicons",
Expand All @@ -35,7 +36,7 @@
}
},
"android_chrome": {
"picture_aspect": "shadow",
"picture_aspect": "no_change",
"manifest": {
"name": "Favicons",
"display": "standalone",
Expand All @@ -46,7 +47,7 @@
"coast": {
"picture_aspect": "background_and_margin",
"background_color": "#FFFFFF",
"margin": "12%"
"margin": "0"
},
"yandex_browser": {
"background_color": "#FFFFFF",
Expand Down
52 changes: 30 additions & 22 deletions es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = require('underscore'),
µ = helpers(options),
background = µ.General.background(options.background);

function createFavicon(sourceset, properties, name, callback) {
function createFavicon(sourceset, properties, name, platformOptions, callback) {
if (path.extname(name) === '.ico') {
async.map(properties.sizes, function (sizeProperties, cb) {
var newProperties = clone(properties);
Expand All @@ -35,35 +35,37 @@ var _ = require('underscore'),

var tempName = 'favicon-temp-' + newProperties.width + 'x' + newProperties.height + '.png';

createFavicon(sourceset, newProperties, tempName, cb);
createFavicon(sourceset, newProperties, tempName, platformOptions, cb);
}, function (error, results) {
var files = [];
if (error) {
return callback(error);
}

results.forEach(function (icoImage) {
files.push(icoImage.contents);
var files = results.map(function (icoImage) {
return icoImage.contents;
});

toIco(files).then(function (buffer) {
callback(error, { name: name, contents: buffer });
});
return callback(null, { name: name, contents: buffer });
}).catch(callback);
});
} else {
(function () {
var minimum = Math.min(properties.width, properties.height),
icon = _.min(sourceset, function (ico) {
return ico.size >= minimum;
});
var maximum = Math.max(properties.width, properties.height),
offset = Math.round(maximum / 100 * platformOptions.offset) || 0;

async.waterfall([function (cb) {
return µ.Images.read(icon.file, cb);
return µ.Images.nearest(sourceset, properties, offset, cb);
}, function (nearest, cb) {
return µ.Images.read(nearest.file, cb);
}, function (buffer, cb) {
return µ.Images.resize(buffer, minimum, cb);
return µ.Images.resize(buffer, properties, offset, cb);
}, function (resizedBuffer, cb) {
return µ.Images.create(properties, background, function (error, canvas) {
return cb(error, resizedBuffer, canvas);
});
}, function (resizedBuffer, canvas, cb) {
return µ.Images.composite(canvas, resizedBuffer, properties, minimum, cb);
return µ.Images.composite(canvas, resizedBuffer, properties, offset, maximum, cb);
}, function (composite, cb) {
µ.Images.getBuffer(composite, cb);
}], function (error, buffer) {
Expand Down Expand Up @@ -97,21 +99,21 @@ var _ = require('underscore'),
});
}

function createFavicons(sourceset, platform, callback) {
function createFavicons(sourceset, platform, platformOptions, callback) {
var images = [];

async.forEachOf(config.icons[platform], function (properties, name, cb) {
return createFavicon(sourceset, properties, name, function (error, image) {
return createFavicon(sourceset, properties, name, platformOptions, function (error, image) {
return cb(images.push(image) && error);
});
}, function (error) {
return callback(error, images);
});
}

function createPlatform(sourceset, platform, callback) {
function createPlatform(sourceset, platform, platformOptions, callback) {
async.parallel([function (cb) {
return createFavicons(sourceset, platform, cb);
return createFavicons(sourceset, platform, platformOptions, cb);
}, function (cb) {
return createFiles(platform, cb);
}, function (cb) {
Expand All @@ -125,8 +127,10 @@ var _ = require('underscore'),
var response = { images: [], files: [], html: [] };

async.forEachOf(options.icons, function (enabled, platform, cb) {
var platformOptions = µ.General.preparePlatformOptions(platform, enabled);

if (enabled) {
createPlatform(sourceset, platform, function (error, images, files, html) {
createPlatform(sourceset, platform, platformOptions, function (error, images, files, html) {
response.images = response.images.concat(images);
response.files = response.files.concat(files);
response.html = response.html.concat(html);
Expand All @@ -141,7 +145,7 @@ var _ = require('underscore'),
}

function unpack(pack, callback) {
var response = { images: [], files: [], html: pack.html.split(',') };
var response = { images: [], files: [], html: pack.html.split('\n') };

async.each(pack.files, function (url, cb) {
return µ.RFG.fetch(url, function (error, box) {
Expand All @@ -160,12 +164,16 @@ var _ = require('underscore'),
}, function (pack, cb) {
return unpack(pack, cb);
}], function (error, results) {
return callback(error, results);
if (error && options.preferOnline) {
createOffline(sourceset, callback);
} else {
callback(error, results);
}
});
}

function create(sourceset, callback) {
options.online ? createOnline(sourceset, callback) : createOffline(sourceset, callback);
options.online || options.preferOnline ? createOnline(sourceset, callback) : createOffline(sourceset, callback);
}

async.waterfall([function (callback) {
Expand Down
Loading

0 comments on commit 0f063be

Please sign in to comment.