Skip to content

Commit

Permalink
Merge pull request #8 from ro-ka/feature/firefox-os
Browse files Browse the repository at this point in the history
Firefox OS and Firefox for Android and Windows
  • Loading branch information
gleero committed Nov 26, 2013
2 parents 974dbe2 + 1caeb44 commit 2cec0b5
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 7 deletions.
12 changes: 9 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ module.exports = function(grunt) {
trueColor: true,
HTMLPrefix: "/images/icons/",
windowsTile: false,
precomposed: false
precomposed: false,
firefox: true,
firefoxManifest: 'test/out/manifest.webapp'
},
src: 'test/test.png',
dest: 'test/out'
Expand All @@ -57,6 +59,10 @@ module.exports = function(grunt) {
php: {
src: 'test/index.html',
dest: 'test/out/test.php'
},
manifest: {
src: 'test/manifest.webapp',
dest: 'test/out/manifest.webapp'
}
},

Expand All @@ -78,9 +84,9 @@ module.exports = function(grunt) {
// Default options
grunt.registerTask('stage1', ['clean', 'copy', 'favicons:stage1', 'nodeunit:stage1']);
grunt.registerTask('stage2', ['clean', 'copy', 'favicons:stage2', 'nodeunit:stage2']);
grunt.registerTask('stage3', ['clean', 'copy:php', 'favicons:stage3', 'nodeunit:stage3']);
grunt.registerTask('stage3', ['clean', 'copy:php', 'copy:manifest', 'favicons:stage3', 'nodeunit:stage3']);

grunt.registerTask('test', ['jshint', 'stage1', 'stage2', 'stage3', 'clean']);
grunt.registerTask('default', ['test']);

};
};
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Generates all known types and sizes icons from PNG image. Uses ImageMagick.
- `apple-touch-icon-152x152.png` (152x152) — iPad retina iOS 7;
- `windows-tile-144x144.png` (144x144) — Windows 8 tile;
- `coast-icon-228x228.png` (228x228) - Coast browser.
- `firefox-icon-16x16.png` (16x16) - Firefox on Android / Windows.
- `firefox-icon-30x30.png` (30x30) - Firefox OS.
- `firefox-icon-32x32.png` (32x32) - Firefox on Android / Windows.
- `firefox-icon-48x48.png` (48x48) - Firefox on Android / Windows.
- `firefox-icon-60x60.png` (60x60) - Firefox OS.
- `firefox-icon-64x64.png` (64x64) - Firefox on Android / Windows.
- `firefox-icon-128x128.png` (128x128) - Firefox on Android / Windows.
- `firefox-icon-256x256.png` (256x256) - Firefox on Android / Windows.

Adds changes to `html` file.

Expand Down Expand Up @@ -132,6 +140,18 @@ Values: `auto|none|#COLOR`

Background color for Windows 8 tile. If option set to `auto` color is selected automatically. `none` leaves transparency.

#### options.firefox
Type: `Boolean`
Default value: `false`

Add icons for [Firefox OS](http://www.mozilla.org/de/firefox/os/) and Firefox on Android and Windows.

#### options.firefoxManifest
Type: `String`
Default value: `''`

Path to [Firefox manifest](https://developer.mozilla.org/en-US/Apps/Developing/Manifest) you want to add links to icons.

### Low resolution

If you reduce the image to 16x16, it will blured. To avoid this, you can put near source image the prefixes. For example: source image called `logo.png`. If you put nearly `logo.16x16.png` then it will be used.
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grunt-favicons",
"description": "Generate favicon.ico and icons for iOS, Android and Windows 8",
"description": "Generate favicon.ico and icons for iOS, Android, Windows 8 and Firefox (OS)",
"version": "0.3.2",
"homepage": "https://github.com/gleero/grunt-favicons",
"author": {
Expand Down Expand Up @@ -53,6 +53,8 @@
"jpg",
"ios",
"android",
"wp8"
"wp8",
"firefox",
"firefox os"
]
}
38 changes: 36 additions & 2 deletions tasks/favicons.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function(grunt) {
};

// Tasks
grunt.registerMultiTask('favicons', 'Generate favicon.ico and icons for iOS, Android and WP8', function() {
grunt.registerMultiTask('favicons', 'Generate favicon.ico and icons for iOS, Android, WP8 and Firefox (OS)', function() {

var target = this.target;

Expand All @@ -61,7 +61,9 @@ module.exports = function(grunt) {
windowsTile: true,
coast: false,
tileBlackWhite: true,
tileColor: "auto" // none, auto, #color
tileColor: "auto", // none, auto, #color
firefox: false,
firefoxManifest: ""
});

// Append all icons to HTML as meta tags (needs cheerio)
Expand Down Expand Up @@ -195,6 +197,38 @@ module.exports = function(grunt) {
grunt.log.ok();
}

// Firefox
if (options.firefox) {
var updateFirefoxManifest = (options.firefoxManifest !== undefined && options.firefoxManifest !== ''),
contentFirefox;

if (updateFirefoxManifest) {
var contentsFirefox = (grunt.file.exists(options.firefoxManifest)) ? grunt.file.read(options.firefoxManifest) : '{}';
contentFirefox = JSON.parse(contentsFirefox);
contentFirefox.icons = {};
}

['16', '30', '32', '48', '60', '64', '128', '256'].forEach(function(size) {
var dimensions = size + 'x' + size;
grunt.log.write('firefox-icon-' + dimensions + '.png... ');
convert(combine(source, f.dest, dimensions, "firefox-icon-" + dimensions + ".png", []));

if (updateFirefoxManifest) {
contentFirefox.icons[size] = options.HTMLPrefix + 'firefox-icon' + dimensions + '.png';
}

grunt.log.ok();
});

if (updateFirefoxManifest) {
grunt.log.write('Updating Firefox manifest... ');

fs.writeFileSync(options.firefoxManifest, JSON.stringify(contentFirefox, null, 2));
}

grunt.log.ok();
}

////// Windows 8 Tile

if (options.windowsTile) {
Expand Down
13 changes: 13 additions & 0 deletions test/manifest.webapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "My App",
"description": "My App describes itself.",
"launch_path": "/",
"icons": {
"128": "/img/icon-128.png"
},
"developer": {
"name": "Your name or organization",
"url": "http://your-homepage-here.org"
},
"default_locale": "en"
}
144 changes: 144 additions & 0 deletions test/test_stage2.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,150 @@ exports.favicons = {
test.done();
},

// firefox-icon-16x16.png exists
fx16Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-16x16.png");
test.ok(exists, 'firefox-icon-16x16.png is not exists.');
test.done();
},

// firefox-icon-16x16.png dimensions
fx16Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-16x16.png");
var pass = dimensions.width === 16 && dimensions.height === 16;
test.ok(pass, 'firefox-icon-16x16.png is not 16x16.');
test.done();
},

// firefox-icon-30x30.png exists
fx30Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-30x30.png");
test.ok(exists, 'firefox-icon-30x30.png is not exists.');
test.done();
},

// firefox-icon-30x30.png dimensions
fx30Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-30x30.png");
var pass = dimensions.width === 30 && dimensions.height === 30;
test.ok(pass, 'firefox-icon-30x30.png is not 30x30.');
test.done();
},

// firefox-icon-32x32.png exists
fx32Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-32x32.png");
test.ok(exists, 'firefox-icon-32x32.png is not exists.');
test.done();
},

// firefox-icon-32x32.png dimensions
fx32Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-32x32.png");
var pass = dimensions.width === 32 && dimensions.height === 32;
test.ok(pass, 'firefox-icon-32x32.png is not 32x32.');
test.done();
},

// firefox-icon-48x48.png exists
fx48Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-48x48.png");
test.ok(exists, 'firefox-icon-48x48.png is not exists.');
test.done();
},

// firefox-icon-48x48.png dimensions
fx48Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-48x48.png");
var pass = dimensions.width === 48 && dimensions.height === 48;
test.ok(pass, 'firefox-icon-48x48.png is not 48x48.');
test.done();
},

// firefox-icon-60x60.png exists
fx60Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-60x60.png");
test.ok(exists, 'firefox-icon-60x60.png is not exists.');
test.done();
},

// firefox-icon-60x60.png dimensions
fx60Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-60x60.png");
var pass = dimensions.width === 60 && dimensions.height === 60;
test.ok(pass, 'firefox-icon-60x60.png is not 60x60.');
test.done();
},

// firefox-icon-64x64.png exists
fx64Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-64x64.png");
test.ok(exists, 'firefox-icon-64x64.png is not exists.');
test.done();
},

// firefox-icon-64x64.png dimensions
fx64Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-64x64.png");
var pass = dimensions.width === 64 && dimensions.height === 64;
test.ok(pass, 'firefox-icon-64x64.png is not 64x64.');
test.done();
},

// firefox-icon-128x128.png exists
fx128Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-128x128.png");
test.ok(exists, 'firefox-icon-128x128.png is not exists.');
test.done();
},

// firefox-icon-128x128.png dimensions
fx128Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-128x128.png");
var pass = dimensions.width === 128 && dimensions.height === 128;
test.ok(pass, 'firefox-icon-128x128.png is not 128x128.');
test.done();
},

// firefox-icon-256x256.png exists
fx256Exists: function(test) {
test.expect(1);
var exists = fs.existsSync(path + "/firefox-icon-256x256.png");
test.ok(exists, 'firefox-icon-256x256.png is not exists.');
test.done();
},

// firefox-icon-256x256.png dimensions
fx256Dim: function(test) {
test.expect(1);
var dimensions = sizeOf(path + "/firefox-icon-256x256.png");
var pass = dimensions.width === 256 && dimensions.height === 256;
test.ok(pass, 'firefox-icon-256x256.png is not 256x256.');
test.done();
},

// firefox manifest test hashsum
manifestsum: function(test) {
test.expect(1);
var original = crypto.createHash('sha1').update(grunt.file.read(path + '/manifest.webapp')).digest('hex');
test.ok(original === '3d66ae4293edb4efba5dd85869d23f8260c30c67', 'firefox manifest hashsum not valid');
test.done();
},

// html test hashsum
htmlsum: function(test) {
test.expect(1);
Expand Down

0 comments on commit 2cec0b5

Please sign in to comment.