icon_generator 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/icon_generator.gemspec +1 -1
- data/lib/icon_generator/builder.rb +8 -0
- data/lib/icon_generator/error.rb +4 -0
- data/lib/icon_generator/favicon_builder.rb +6 -0
- data/lib/icon_generator/touch_builder.rb +11 -0
- data/lib/icon_generator/validator.rb +16 -1
- data/lib/icon_generator/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fd55e81501e3d69f09714856de6621e390954b3
|
4
|
+
data.tar.gz: c1d2a7023ad65497252f5bc861c4e8191ad44654
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93256fb28455b40d33c82a130fc0443472eaf1eedc3202465329c57ed51e3819191d55791887949f9e6e7f7e2e06ea55cf0b3ba206dc5dfa7e412017f2a76ac6
|
7
|
+
data.tar.gz: 2a5bd66d56b478f46460491370bb28bea1735dc962beb7f5c188f4df776c147720fc03e12bd19ffd544d61a523f2b2a51086d49b176a28d9858dd76706e87af5
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# IconGenerator
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/icon_generator.png)](http://badge.fury.io/rb/icon_generator)
|
3
4
|
[![Code Climate](https://codeclimate.com/github/adamnbowen/icon_generator.png)](https://codeclimate.com/github/adamnbowen/icon_generator)
|
4
5
|
[![Build Status](https://travis-ci.org/adamnbowen/icon_generator.png)](https://travis-ci.org/adamnbowen/icon_generator)
|
5
6
|
|
data/icon_generator.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.
|
23
|
+
spec.add_runtime_dependency "thor", "0.18.1"
|
24
24
|
|
25
25
|
spec.requirements << 'imagemagick'
|
26
26
|
end
|
@@ -2,12 +2,20 @@ module IconGenerator
|
|
2
2
|
class Builder
|
3
3
|
include IconGenerator::Validator
|
4
4
|
|
5
|
+
# Sets up the source and destination instance variables, and
|
6
|
+
# ensures they validate.
|
7
|
+
#
|
8
|
+
# @param source [String] the source image file
|
9
|
+
# @param destination [String] the output directory
|
5
10
|
def initialize(source, destination)
|
6
11
|
@source = source
|
7
12
|
@destination = destination
|
8
13
|
validate_arguments @source, @destination
|
9
14
|
end
|
10
15
|
|
16
|
+
# Requests a build of the given image type.
|
17
|
+
#
|
18
|
+
# @param type [Symbol] the image type, `:touch` or `:favicon`
|
11
19
|
def build(type)
|
12
20
|
if type == :touch
|
13
21
|
IconGenerator::TouchBuilder.new.build(@source, @destination)
|
data/lib/icon_generator/error.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module IconGenerator
|
2
2
|
class Error < Thor::Error
|
3
|
+
# Colors the given error message red and sends it up to
|
4
|
+
# Thor::Error's initialize method.
|
5
|
+
#
|
6
|
+
# @param message [String] the message for the current Error
|
3
7
|
def initialize(message = "Icon generation failed")
|
4
8
|
super(Thor::Shell::Color.new.set_color message, :red)
|
5
9
|
end
|
@@ -2,6 +2,12 @@ module IconGenerator
|
|
2
2
|
class FaviconBuilder
|
3
3
|
include IconGenerator::Validator
|
4
4
|
|
5
|
+
# Builds a multi-resolution favicon image by first generating
|
6
|
+
# two temporary pngs—a 16x16 and a 32x32, and then shoving them
|
7
|
+
# into a favicon.
|
8
|
+
#
|
9
|
+
# @param source [String] the source image file
|
10
|
+
# @param destination [String] the output directory
|
5
11
|
def build(source, destination)
|
6
12
|
new_image = "#{destination}/favicon.ico"
|
7
13
|
temp_16 = Tempfile.new('16x16')
|
@@ -2,6 +2,7 @@ module IconGenerator
|
|
2
2
|
class TouchBuilder
|
3
3
|
include IconGenerator::Validator
|
4
4
|
|
5
|
+
# Initializes the default image sizes.
|
5
6
|
def initialize
|
6
7
|
@sizes = [
|
7
8
|
'144x144',
|
@@ -11,6 +12,10 @@ module IconGenerator
|
|
11
12
|
]
|
12
13
|
end
|
13
14
|
|
15
|
+
# Builds apple-touch-icons from the given source file.
|
16
|
+
#
|
17
|
+
# @param source [String] the source image file
|
18
|
+
# @param destination [String] the output directory
|
14
19
|
def build(source, destination)
|
15
20
|
@sizes.each do |size|
|
16
21
|
new_image = "#{destination}/apple-touch-icon-#{size}-precomposed.png"
|
@@ -22,6 +27,12 @@ module IconGenerator
|
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
30
|
+
|
31
|
+
# Builds a given size of apple-touch-icon.
|
32
|
+
#
|
33
|
+
# @param source [String] the source image file
|
34
|
+
# @param size [String] the requested image size, in WxH format
|
35
|
+
# @param new_image [String] the output image
|
25
36
|
def build_size(source, size, new_image)
|
26
37
|
%x[convert '#{source}' -resize #{size}! #{new_image}]
|
27
38
|
validate_file_status new_image
|
@@ -1,12 +1,27 @@
|
|
1
1
|
module IconGenerator
|
2
|
+
# Module intended to be used as a convenient mixin.
|
3
|
+
#
|
4
|
+
# @example Including the validator in a class
|
5
|
+
# class Foo
|
6
|
+
# include IconGenerator::Validator
|
7
|
+
# # Now you can use validate_arguments and
|
8
|
+
# # validate_file_status as if they were your very own.
|
9
|
+
# end
|
2
10
|
module Validator
|
11
|
+
# Validates the given source image file and the destination
|
12
|
+
# directory for correctness.
|
13
|
+
#
|
14
|
+
# @param source [String] the source image file
|
15
|
+
# @param destination [String] the output directory
|
3
16
|
def validate_arguments(source, destination)
|
4
17
|
raise IconGenerator::Error, '1st argument must be a valid image' unless source.match /\.gif$|\.jpg$|\.png$/
|
5
18
|
raise IconGenerator::Error, '1st argument must be an existing file' unless File.exists? source
|
6
19
|
raise IconGenerator::Error, '2nd argument must be an existing directory' unless Dir.exists? destination
|
7
20
|
end
|
8
21
|
|
9
|
-
|
22
|
+
# Validates the existence of the given file.
|
23
|
+
#
|
24
|
+
# @param filename [String] the file being tested for existence
|
10
25
|
def validate_file_status(filename)
|
11
26
|
raise IconGenerator::Error unless File.exists? filename
|
12
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icon_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bowen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.18.1
|
48
|
-
type: :
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
@@ -106,3 +106,4 @@ summary: Make apple-touch-icons and favicon.ico files
|
|
106
106
|
test_files:
|
107
107
|
- spec/icon_generator_spec.rb
|
108
108
|
- spec/spec_helper.rb
|
109
|
+
has_rdoc:
|