icon_generator 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +9 -0
- data/bin/icon_generator +6 -0
- data/icon_generator.gemspec +26 -0
- data/lib/icon_generator.rb +10 -0
- data/lib/icon_generator/builder.rb +19 -0
- data/lib/icon_generator/error.rb +7 -0
- data/lib/icon_generator/favicon_builder.rb +16 -0
- data/lib/icon_generator/thor.rb +13 -0
- data/lib/icon_generator/touch_builder.rb +31 -0
- data/lib/icon_generator/validator.rb +14 -0
- data/lib/icon_generator/version.rb +3 -0
- data/spec/icon_generator_spec.rb +75 -0
- data/spec/spec_helper.rb +7 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6046805bbad4ef704dfaa1b770c534ad0fc59dc6
|
4
|
+
data.tar.gz: 495f5934ef66bed4fe63ed0e936258c5acc8d407
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b1403b1fb6ab043c66792415eb4d48421ff66816928c777fce14eca6e4da013240aa9d41958aed4e6d78d8ffae5e7ae48eeec8dc11b5a10908c9aa6c98dca1d
|
7
|
+
data.tar.gz: aed27c04824785c4c49b8271ec2188a0510af00bbd3d4ad846017a3ac81ffc644dc9fbef449422e6c9710dfa825f9c458b794821bace223a9b821ebf4896bf47
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adam Bowen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# IconGenerator
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/adamnbowen/icon_generator)
|
4
|
+
[](https://travis-ci.org/adamnbowen/icon_generator)
|
5
|
+
|
6
|
+
Generates Apple Touch Icons or a multiresolution (32x32 and 16x16)
|
7
|
+
favicon given a square image.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem install icon_generator
|
12
|
+
|
13
|
+
## Dependencies
|
14
|
+
|
15
|
+
* Ruby 1.9.3 and up
|
16
|
+
* ImageMagick
|
17
|
+
* [Thor](http://whatisthor.com/)
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ icon_generator touch my/source/file.png my/output/directory
|
22
|
+
|
23
|
+
## Testing
|
24
|
+
|
25
|
+
$ rake test
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/icon_generator
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'icon_generator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "icon_generator"
|
8
|
+
spec.version = IconGenerator::VERSION
|
9
|
+
spec.authors = ["Adam Bowen"]
|
10
|
+
spec.email = ["adambowen@group360.com"]
|
11
|
+
spec.description = %q{Generates Apple Touch Icons or a favicon given a square image.}
|
12
|
+
spec.summary = %q{Make apple-touch-icons and favicon.ico files}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = ["icon_generator"]
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "thor", "0.18.1"
|
24
|
+
|
25
|
+
spec.requirements << 'imagemagick'
|
26
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "icon_generator/version"
|
2
|
+
require "icon_generator/error"
|
3
|
+
require "icon_generator/validator"
|
4
|
+
require "icon_generator/builder"
|
5
|
+
require "icon_generator/favicon_builder"
|
6
|
+
require "icon_generator/touch_builder"
|
7
|
+
require "icon_generator/thor"
|
8
|
+
|
9
|
+
module IconGenerator
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module IconGenerator
|
2
|
+
class Builder
|
3
|
+
include IconGenerator::Validator
|
4
|
+
|
5
|
+
def initialize(source, destination)
|
6
|
+
@source = source
|
7
|
+
@destination = destination
|
8
|
+
validate_arguments @source, @destination
|
9
|
+
end
|
10
|
+
|
11
|
+
def build(type)
|
12
|
+
if type == :touch
|
13
|
+
IconGenerator::TouchBuilder.new.build(@source, @destination)
|
14
|
+
elsif type == :favicon
|
15
|
+
IconGenerator::FaviconBuilder.new.build(@source, @destination)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IconGenerator
|
2
|
+
class FaviconBuilder
|
3
|
+
include IconGenerator::Validator
|
4
|
+
|
5
|
+
def build(source, destination)
|
6
|
+
new_image = "#{destination}/favicon.ico"
|
7
|
+
temp_16 = Tempfile.new('16x16')
|
8
|
+
temp_32 = Tempfile.new('32x32')
|
9
|
+
%x[convert '#{source}' -resize 16x16 -alpha on #{temp_16.path}]
|
10
|
+
%x[convert '#{source}' -resize 32x32 -alpha on #{temp_32.path}]
|
11
|
+
%x[convert #{temp_16.path} #{temp_32.path} #{new_image}]
|
12
|
+
validate_file_status new_image
|
13
|
+
puts Thor::Shell::Color.new.set_color("Built #{new_image}", :green)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module IconGenerator
|
2
|
+
class Thor < Thor
|
3
|
+
desc 'touch', 'Generate apple-touch-icons'
|
4
|
+
def touch(source, destination)
|
5
|
+
IconGenerator::Builder.new(source, destination).build(:touch)
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'favicon', 'Generate favicon'
|
9
|
+
def favicon(source, destination)
|
10
|
+
IconGenerator::Builder.new(source, destination).build(:favicon)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module IconGenerator
|
2
|
+
class TouchBuilder
|
3
|
+
include IconGenerator::Validator
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@sizes = [
|
7
|
+
'144x144',
|
8
|
+
'114x114',
|
9
|
+
'72x72',
|
10
|
+
'57x57',
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def build(source, destination)
|
15
|
+
@sizes.each do |size|
|
16
|
+
new_image = "#{destination}/apple-touch-icon-#{size}-precomposed.png"
|
17
|
+
build_size(source, size, new_image)
|
18
|
+
if size == '57x57'
|
19
|
+
build_size(source, '57x57', "#{destination}/apple-touch-icon-precomposed.png")
|
20
|
+
build_size(source, '57x57', "#{destination}/apple-touch-icon.png")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_size(source, size, new_image)
|
26
|
+
%x[convert '#{source}' -resize #{size}! #{new_image}]
|
27
|
+
validate_file_status new_image
|
28
|
+
puts Thor::Shell::Color.new.set_color("Built #{new_image}", :green)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module IconGenerator
|
2
|
+
module Validator
|
3
|
+
def validate_arguments(source, destination)
|
4
|
+
raise IconGenerator::Error, '1st argument must be a valid image' unless source.match /\.gif$|\.jpg$|\.png$/
|
5
|
+
raise IconGenerator::Error, '1st argument must be an existing file' unless File.exists? source
|
6
|
+
raise IconGenerator::Error, '2nd argument must be an existing directory' unless Dir.exists? destination
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def validate_file_status(filename)
|
11
|
+
raise IconGenerator::Error unless File.exists? filename
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IconGenerator do
|
4
|
+
let (:tmp) { Dir.tmpdir }
|
5
|
+
|
6
|
+
it "requires the source file to exist" do
|
7
|
+
fake_file = -> { IconGenerator::Builder.new('missing.png', tmp) }
|
8
|
+
raised_error = fake_file.must_raise IconGenerator::Error
|
9
|
+
raised_error.to_s.must_match '1st argument must be an existing file'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "requires the source file to have a supported extension" do
|
13
|
+
html = -> { IconGenerator::Builder.new('index.html', tmp) }
|
14
|
+
raised_error = html.must_raise IconGenerator::Error
|
15
|
+
raised_error.to_s.must_match '1st argument must be a valid image'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "requires the output directory to exist" do
|
19
|
+
tempfile = Tempfile.new ['test', '.png']
|
20
|
+
%x[convert -size 1x1 canvas:khaki #{tempfile.path}]
|
21
|
+
missing = -> { IconGenerator::Builder.new(tempfile.path, 'missing') }
|
22
|
+
raised_error = missing.must_raise IconGenerator::Error
|
23
|
+
raised_error.to_s.must_match '2nd argument must be an existing directory'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "creates a favicon when requested" do
|
27
|
+
tempfile = Tempfile.new ['test', '.png']
|
28
|
+
%x[convert -size 1x1 canvas:khaki #{tempfile.path}]
|
29
|
+
builder = IconGenerator::Builder.new(tempfile.path, tmp)
|
30
|
+
stdout = capture_io { builder.build(:favicon) }.to_s
|
31
|
+
File.exists?("#{tmp}/favicon.ico").must_be :==, true
|
32
|
+
stdout.must_include "Built #{tmp}/favicon.ico"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates apple-touch-icons when requested" do
|
36
|
+
tempfile = Tempfile.new ['test', '.png']
|
37
|
+
%x[convert -size 1x1 canvas:khaki #{tempfile.path}]
|
38
|
+
builder = IconGenerator::Builder.new(tempfile.path, tmp)
|
39
|
+
stdout = capture_io { builder.build(:touch) }.to_s
|
40
|
+
|
41
|
+
files = [
|
42
|
+
"#{tmp}/apple-touch-icon.png",
|
43
|
+
"#{tmp}/apple-touch-icon-precomposed.png",
|
44
|
+
"#{tmp}/apple-touch-icon-144x144-precomposed.png",
|
45
|
+
"#{tmp}/apple-touch-icon-114x114-precomposed.png",
|
46
|
+
"#{tmp}/apple-touch-icon-72x72-precomposed.png",
|
47
|
+
"#{tmp}/apple-touch-icon-57x57-precomposed.png",
|
48
|
+
]
|
49
|
+
|
50
|
+
files.each do |file|
|
51
|
+
File.exists?(file).must_be :==, true
|
52
|
+
stdout.must_include "Built #{file}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "works with jpgs as a source file" do
|
57
|
+
tempfile = Tempfile.new ['test', '.jpg']
|
58
|
+
%x[convert -size 1x1 canvas:khaki #{tempfile.path}]
|
59
|
+
builder = IconGenerator::Builder.new(tempfile.path, tmp)
|
60
|
+
stdout_favicon = capture_io { builder.build(:favicon) }.to_s
|
61
|
+
stdout_favicon.must_include "Built #{tmp}/favicon.ico"
|
62
|
+
stdout_touch = capture_io { builder.build(:touch) }.to_s
|
63
|
+
stdout_touch.must_include "Built #{tmp}/apple-touch-icon.png"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "works with gifs as a source file" do
|
67
|
+
tempfile = Tempfile.new ['test', '.gif']
|
68
|
+
%x[convert -size 1x1 canvas:khaki #{tempfile.path}]
|
69
|
+
builder = IconGenerator::Builder.new(tempfile.path, tmp)
|
70
|
+
stdout_favicon = capture_io { builder.build(:favicon) }.to_s
|
71
|
+
stdout_favicon.must_include "Built #{tmp}/favicon.ico"
|
72
|
+
stdout_touch = capture_io { builder.build(:touch) }.to_s
|
73
|
+
stdout_touch.must_include "Built #{tmp}/apple-touch-icon.png"
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icon_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Bowen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.18.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.18.1
|
55
|
+
description: Generates Apple Touch Icons or a favicon given a square image.
|
56
|
+
email:
|
57
|
+
- adambowen@group360.com
|
58
|
+
executables:
|
59
|
+
- icon_generator
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/icon_generator
|
70
|
+
- icon_generator.gemspec
|
71
|
+
- lib/icon_generator.rb
|
72
|
+
- lib/icon_generator/builder.rb
|
73
|
+
- lib/icon_generator/error.rb
|
74
|
+
- lib/icon_generator/favicon_builder.rb
|
75
|
+
- lib/icon_generator/thor.rb
|
76
|
+
- lib/icon_generator/touch_builder.rb
|
77
|
+
- lib/icon_generator/validator.rb
|
78
|
+
- lib/icon_generator/version.rb
|
79
|
+
- spec/icon_generator_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements:
|
100
|
+
- imagemagick
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.0.3
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Make apple-touch-icons and favicon.ico files
|
106
|
+
test_files:
|
107
|
+
- spec/icon_generator_spec.rb
|
108
|
+
- spec/spec_helper.rb
|