favicon_maker 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5060beb595085399132ea1b324f4746153e142a1
4
- data.tar.gz: b1037564b82ab94cad83b1616c0fab17c7c95390
3
+ metadata.gz: 0b0f7f9177f94233cb3f9ce947c6c0f406a0d0bf
4
+ data.tar.gz: 43f23170c8ad6ebea1d2152faf444edadc5af74d
5
5
  SHA512:
6
- metadata.gz: 5dc5392d5193014f9e8a307ddaf17154d5dcfdd43f2a9b38606655e81bc34dd3badfffafd75d5964e3d853d64ebae2d9d86dc5cf976a0bfc93cf818480fe579a
7
- data.tar.gz: c3fedf492456d8f9c8c3a945835610469118a95de51e441c70f65c4d515628463ae334218812e76436af469357a05d1898f4a86773723ea39d60c4b9df6abd4d
6
+ metadata.gz: 983cf479778d797d678fab44f353aea49e3b5cd8c62ae8b95a7714f0eda18dffdb7a6bdd9a6fdea5e30092e154f9a735b6a4922e7121aeade2fea0cfa21743d0
7
+ data.tar.gz: 1de929387d739d9a16a42eb8dd143443228f6110910e4613ac0ae5bf0fa3e88907d3ef9b7f770e24c2e32e8aad629687533c07070c20da02b1b149c6de11b88b
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
4
+ - 2.1.0
5
5
  script: "bundle exec rspec spec"
data/Guardfile CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  guard 'rspec', :version => 2 do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- # watch(%r{^lib/(.+)\.rb$}) { |m| ["spec/lib/#{m[1]}_spec.rb", "spec/favicon_maker_spec.rb"] }
7
6
  watch(%r{^lib/favicon_maker/(.+)\.rb$}) { |m| ["spec/lib/#{m[1]}_spec.rb", "spec/favicon_maker_spec.rb"] }
8
7
  watch('spec/spec_helper.rb') { "spec" }
9
8
  end
@@ -0,0 +1,111 @@
1
+ ## DEPRECATED - FaviconMaker v0.x
2
+ ### Integration
3
+ #### Middleman
4
+ In order to integrate the FaviconMaker effortless into your [Middleman](https://github.com/tdreyno/middleman) project use the following gem: [middleman-favicon-maker](https://github.com/follmann/middleman-favicon-maker) till version v3.4
5
+
6
+ #### Capistrano
7
+ 1. Edit your Capfile and add the following line
8
+ ``` ruby
9
+ require "favicon_maker"
10
+ ```
11
+ 2. Add the following snippet to your deploy.rb
12
+
13
+ ``` ruby
14
+ namespace :favicon do
15
+ task :create_versions do
16
+ options = {
17
+ :root_dir => release_path,
18
+ :input_dir => File.join("app", "assets", "public"),
19
+ :output_dir => "public"
20
+ }
21
+ FaviconMaker::Generator.create_versions(options) do |filepath|
22
+ puts "Created favicon: #{filepath}"
23
+ end
24
+ end
25
+ end
26
+
27
+ after "deploy:update_code", "favicon:create_versions"
28
+ ```
29
+
30
+ **Note: This snippet is untested but should work**
31
+
32
+ ### v0.x Usage
33
+ #### Simple
34
+
35
+ ``` ruby
36
+ require "rubygems"
37
+ require "favicon_maker"
38
+
39
+ FaviconMaker::Generator.create_versions
40
+ ```
41
+ Uses the following defaults:
42
+ ``` ruby
43
+ options = {
44
+ :versions => [
45
+ :apple_152,
46
+ :apple_144,
47
+ :apple_120,
48
+ :apple_114,
49
+ :apple_76,
50
+ :apple_72,
51
+ :apple_60,
52
+ :apple_57,
53
+ :apple,
54
+ :fav_196,
55
+ :fav_160,
56
+ :fav_96,
57
+ :fav_32,
58
+ :fav_16,
59
+ :fav_png,
60
+ :fav_ico,
61
+ :mstile_144
62
+ ],
63
+ :custom_versions => {},
64
+ :root_dir => File.dirname(__FILE__),
65
+ :input_dir => "favicons",
66
+ :base_image => "favicon_base.png",
67
+ :output_dir => "favicons_output",
68
+ :copy => false
69
+ }
70
+ ```
71
+ #### Advanced
72
+ (untested attempted Rails integration, using all available options. Could be used in a Rake task or Capistrano recipe)
73
+ ``` ruby
74
+ options = {
75
+ :versions => [
76
+ :apple_152,
77
+ :apple_144,
78
+ :apple_120,
79
+ :apple_114,
80
+ :apple_76,
81
+ :apple_72,
82
+ :apple_60,
83
+ :apple_57,
84
+ :apple,
85
+ :fav_196,
86
+ :fav_160,
87
+ :fav_96,
88
+ :fav_32,
89
+ :fav_16,
90
+ :fav_png,
91
+ :fav_ico,
92
+ :mstile_144
93
+ ],
94
+ :custom_versions => {
95
+ :apple_extreme_retina => {
96
+ :filename => "apple-touch-icon-228x228-precomposed.png",
97
+ :dimensions => "228x228",
98
+ :format => "png"
99
+ }
100
+ },
101
+ :root_dir => Rails.root,
102
+ :input_dir => File.join("app", "assets", "public"),
103
+ :base_image => "favicon.png",
104
+ :output_dir => "public",
105
+ :copy => true
106
+ }
107
+
108
+ FaviconMaker::Generator.create_versions(options) do |filepath|
109
+ puts "Created favicon: #{filepath}"
110
+ end
111
+ ```
data/README.md CHANGED
@@ -4,9 +4,7 @@ FaviconMaker [![Build Status](https://secure.travis-ci.org/follmann/favicon_make
4
4
 
5
5
  Tired of creating a gazillion different favicons to satisfy all kinds of devices and resolutions in different file formats?
6
6
 
7
- I know I was, so I created FaviconMaker to ease the tedious process of creating multiple versions of your favicon.
8
-
9
- The basic idea is to have a template image file as source for all the different sizes and or formats (png/ico). From v1.x on it is possible to use multiple template files
7
+ I know I was, so I created FaviconMaker to ease the tedious process of creating multiple versions of your favicon. The basic idea is to have a template image file as source for all the different sizes and or formats (png/ico). From v1.x on it is possible to use multiple template files.
10
8
 
11
9
  ## Installation
12
10
  Using Bundler
@@ -16,12 +14,12 @@ gem "favicon_maker"
16
14
  ```
17
15
  ## Using the DSL
18
16
  ### Definition
19
- * ```setup``` takes the directory config
20
- * ```from``` defines the template to be used
21
- * ```icon``` needs at least a filename. Usually the size and the file format are encoded in that name e.g. ```apple-touch-icon-152x152-precomposed.png```, if that is the case FaviconMaker tries to extract that information. It takes an options hash as the second argument where ```size: "16x16"``` and ```format: :ico``` can be specified. Only .ico and .png are supported. The options passed take precedence over information extracted from the filename.
22
- * ```each_icon``` is called for every generated file with the fully qualified output filepath
17
+ * `setup` takes the directory config
18
+ * `from` defines the template to be used
19
+ * `icon` needs at least a filename. Usually the size and the file format are encoded in that name e.g. `apple-touch-icon-152x152-precomposed.png`, if that is the case FaviconMaker tries to extract that information. It takes an options hash as the second argument where `size` e.g. "16x16" and `format` e.g. :ico can be specified. Only .ico and .png are supported. The options passed take precedence over information extracted from the filename.
20
+ * `each_icon` is called for every generated file with the fully qualified output filepath
23
21
 
24
- ### Complete example:
22
+ ### Complete example
25
23
  ``` ruby
26
24
  FaviconMaker.generate do
27
25
 
@@ -73,117 +71,16 @@ In order to integrate the FaviconMaker effortless into your [Middleman](https://
73
71
  ## Template Image Guideline
74
72
  Choose the version with the biggest dimension as your base image. Currently the size 152x152 for newer iOS devices marks the upper limit. So just create a PNG with 24 or 32 Bit color depth and 152x152 document size. Downscaling of images always works better than upscaling. Use more than one template file to improve lower resolutions.
75
73
 
76
- ## DEPRECATED - FaviconMaker v0.x
77
- ### Integration
78
- #### Middleman
79
- In order to integrate the FaviconMaker effortless into your [Middleman](https://github.com/tdreyno/middleman) project use the following gem: [middleman-favicon-maker](https://github.com/follmann/middleman-favicon-maker) till version v3.4
80
-
81
- #### Capistrano
82
- 1. Edit your Capfile and add the following line
83
- ``` ruby
84
- require "favicon_maker"
85
- ```
86
- 2. Add the following snippet to your deploy.rb
87
-
88
- ``` ruby
89
- namespace :favicon do
90
- task :create_versions do
91
- options = {
92
- :root_dir => release_path,
93
- :input_dir => File.join("app", "assets", "public"),
94
- :output_dir => "public"
95
- }
96
- FaviconMaker::Generator.create_versions(options) do |filepath|
97
- puts "Created favicon: #{filepath}"
98
- end
99
- end
100
- end
101
-
102
- after "deploy:update_code", "favicon:create_versions"
103
- ```
74
+ ## Contributing
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
104
80
 
105
- **Note: This snippet is untested but should work**
81
+ ## FaviconMaker v0.x - DEPRECATED
82
+ [Old instructions for versions till v0.3](OLD_INSTRUCTIONS.md)
106
83
 
107
- ### v0.x Usage
108
- #### Simple
109
-
110
- ``` ruby
111
- require "rubygems"
112
- require "favicon_maker"
113
-
114
- FaviconMaker::Generator.create_versions
115
- ```
116
- Uses the following defaults:
117
- ``` ruby
118
- options = {
119
- :versions => [
120
- :apple_152,
121
- :apple_144,
122
- :apple_120,
123
- :apple_114,
124
- :apple_76,
125
- :apple_72,
126
- :apple_60,
127
- :apple_57,
128
- :apple,
129
- :fav_196,
130
- :fav_160,
131
- :fav_96,
132
- :fav_32,
133
- :fav_16,
134
- :fav_png,
135
- :fav_ico,
136
- :mstile_144
137
- ],
138
- :custom_versions => {},
139
- :root_dir => File.dirname(__FILE__),
140
- :input_dir => "favicons",
141
- :base_image => "favicon_base.png",
142
- :output_dir => "favicons_output",
143
- :copy => false
144
- }
145
- ```
146
- #### Advanced
147
- (untested attempted Rails integration, using all available options. Could be used in a Rake task or Capistrano recipe)
148
- ``` ruby
149
- options = {
150
- :versions => [
151
- :apple_152,
152
- :apple_144,
153
- :apple_120,
154
- :apple_114,
155
- :apple_76,
156
- :apple_72,
157
- :apple_60,
158
- :apple_57,
159
- :apple,
160
- :fav_196,
161
- :fav_160,
162
- :fav_96,
163
- :fav_32,
164
- :fav_16,
165
- :fav_png,
166
- :fav_ico,
167
- :mstile_144
168
- ],
169
- :custom_versions => {
170
- :apple_extreme_retina => {
171
- :filename => "apple-touch-icon-228x228-precomposed.png",
172
- :dimensions => "228x228",
173
- :format => "png"
174
- }
175
- },
176
- :root_dir => Rails.root,
177
- :input_dir => File.join("app", "assets", "public"),
178
- :base_image => "favicon.png",
179
- :output_dir => "public",
180
- :copy => true
181
- }
182
-
183
- FaviconMaker::Generator.create_versions(options) do |filepath|
184
- puts "Created favicon: #{filepath}"
185
- end
186
- ```
187
84
  ## Copyright
188
85
 
189
86
  © 2011-2014 Andreas Follmann. See LICENSE for details.
@@ -41,6 +41,8 @@ module FaviconMaker
41
41
  size = options[:size] || extract_size(output_filename)
42
42
  output_file_path = File.join(output_path, output_filename)
43
43
 
44
+ validate_input(format, size)
45
+
44
46
  generate_file(template_file_path, output_file_path, size, format)
45
47
 
46
48
  finished_block.call(output_file_path, template_file_path) if finished_block
@@ -48,6 +50,18 @@ module FaviconMaker
48
50
 
49
51
  private
50
52
 
53
+ def validate_input(format, size)
54
+ unless InputValidator.valid_format?(format)
55
+ raise ArgumentError, "FaviconMaker: Unknown icon format."
56
+ end
57
+
58
+ format_multi_res = InputValidator.format_multi_resolution?(format)
59
+
60
+ unless InputValidator.valid_size?(size, format_multi_res)
61
+ raise ArgumentError, "FaviconMaker: Size definition can't be decoded."
62
+ end
63
+ end
64
+
51
65
  def fetch_image_magick_version
52
66
  version = (`convert --version`).scan(/ImageMagick (\d\.\d\.\d)/).flatten.first
53
67
  end
@@ -68,6 +82,11 @@ module FaviconMaker
68
82
  image.define "png:include-chunk=none,trns,gama"
69
83
  image.colorspace colorspace_in
70
84
  image.resize size
85
+ image.combine_options do |c|
86
+ c.background "none"
87
+ c.gravity "center"
88
+ c.extent size
89
+ end unless InputValidator.size_square?(size)
71
90
  image.format "png"
72
91
  image.strip
73
92
  image.colorspace colorspace_out
@@ -84,7 +103,7 @@ module FaviconMaker
84
103
  end
85
104
 
86
105
  def print_image_magick_ancient_version_warning
87
- puts "FaviconMaker: WARNING! Your installed ImageMagick version #{IM_VERSION} is not up-to-date and might produce suboptimal output!"
106
+ puts "FaviconMaker: WARNING! Your installed ImageMagick version #{RECENT_IM_VERSION} is not up-to-date and might produce suboptimal output!"
88
107
  end
89
108
 
90
109
 
@@ -0,0 +1,27 @@
1
+ module FaviconMaker
2
+
3
+ module InputValidator
4
+
5
+ def self.valid_size?(size, multiple=false)
6
+ matches = size =~ /^(\d+)/ && size.scan(/(\d+x\d+)/)
7
+ return false if matches.nil? || matches.empty?
8
+ return true if multiple && matches.size >= 1
9
+ return true if matches.size == 1
10
+ false
11
+ end
12
+
13
+ def self.format_multi_resolution?(format)
14
+ format.to_s == "ico"
15
+ end
16
+
17
+ def self.valid_format?(format)
18
+ ["ico", "png"].include?(format.to_s)
19
+ end
20
+
21
+ def self.size_square?(size)
22
+ width, height = *size.split('x').map(&:to_i)
23
+ width == height
24
+ end
25
+ end
26
+
27
+ end
@@ -1,3 +1,8 @@
1
- module FaviconMaker
2
- VERSION = "1.0"
3
- end
1
+ module FaviconMaker
2
+ MAJOR = 1
3
+ MINOR = 1
4
+ PATCH = nil
5
+ BUILD = nil
6
+
7
+ VERSION = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
8
+ end
data/lib/favicon_maker.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require "favicon_maker/maker_config"
2
2
  require "favicon_maker/generator"
3
- require "favicon_maker/creator"
3
+ require "favicon_maker/creator"
4
+ require "favicon_maker/input_validator"
@@ -9,6 +9,8 @@ describe FaviconMaker, '#create_versions' do
9
9
 
10
10
  let(:output_path) { File.join(absolute_root_dir, relative_output_dir) }
11
11
 
12
+ let(:total_count) { 19 }
13
+
12
14
  def cleanup(output_dir)
13
15
  if Dir.exists?(output_dir)
14
16
  Dir[File.join(output_dir, "*")].each do |file|
@@ -60,6 +62,7 @@ describe FaviconMaker, '#create_versions' do
60
62
  icon "favicon.png", size: "16x16"
61
63
  icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
62
64
  icon "mstile-144x144", format: "png"
65
+ icon "mstile-310x150", format: "png"
63
66
  end
64
67
 
65
68
  each_icon do |filepath, template_filepath|
@@ -70,9 +73,9 @@ describe FaviconMaker, '#create_versions' do
70
73
  return files, template_files
71
74
  end
72
75
 
73
- it "creates 18 files" do
76
+ it "creates multiple files" do
74
77
  files, template_files = subject
75
- expect(files.size).to eql(18)
78
+ expect(files.size).to eql(total_count)
76
79
  files.each do |file|
77
80
  expect(File.exists?(file)).to be_true
78
81
  end
@@ -123,6 +126,7 @@ describe FaviconMaker, '#create_versions' do
123
126
  icon "favicon.png", size: "16x16"
124
127
  icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
125
128
  icon "mstile-144x144", format: "png"
129
+ icon "mstile-310x150", format: "png"
126
130
  end
127
131
 
128
132
  each_icon do |filepath|
@@ -132,9 +136,9 @@ describe FaviconMaker, '#create_versions' do
132
136
  files
133
137
  end
134
138
 
135
- it "creates 18 files" do
139
+ it "creates multiple files" do
136
140
  files = subject
137
- expect(files.size).to eql(18)
141
+ expect(files.size).to eql(total_count)
138
142
  files.each do |file|
139
143
  expect(File.exists?(file)).to be_true
140
144
  end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe FaviconMaker::InputValidator do
4
+
5
+ describe '.valid_size?' do
6
+
7
+ context 'with valid size' do
8
+ subject { "64x64" }
9
+
10
+ it "returns true" do
11
+ expect(FaviconMaker::InputValidator.valid_size?(subject)).to be_true
12
+ end
13
+ end
14
+
15
+ context 'with valid sizes and multiple flag' do
16
+ subject { "64x64,32x32,16x16" }
17
+
18
+ it "returns true" do
19
+ expect(FaviconMaker::InputValidator.valid_size?(subject, true)).to be_true
20
+ end
21
+ end
22
+
23
+ context 'with invalid sizes' do
24
+ subject { ["x64x64", "ABx64", "16x", "x64,32x32,16x16"] }
25
+
26
+ it "returns false" do
27
+ subject.each do |s|
28
+ expect(FaviconMaker::InputValidator.valid_size?(s)).to be_false
29
+ end
30
+ subject.each do |s|
31
+ expect(FaviconMaker::InputValidator.valid_size?(s, true)).to be_false
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ describe '.valid_format?' do
39
+
40
+ context 'with valid formats' do
41
+ subject { ["png", "ico"] }
42
+
43
+ it "returns true" do
44
+ subject.each do |s|
45
+ expect(FaviconMaker::InputValidator.valid_format?(s)).to be_true
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'with invalid format' do
51
+ subject { "jpg" }
52
+
53
+ it "returns false" do
54
+ expect(FaviconMaker::InputValidator.valid_format?(subject)).to be_false
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ describe '.format_multi_resolution?' do
61
+
62
+ context 'with multi-res format' do
63
+ subject { "ico" }
64
+
65
+ it "returns true" do
66
+ expect(FaviconMaker::InputValidator.format_multi_resolution?(subject)).to be_true
67
+ end
68
+ end
69
+
70
+ context 'with single-res format' do
71
+ subject { "png" }
72
+
73
+ it "returns false" do
74
+ expect(FaviconMaker::InputValidator.format_multi_resolution?(subject)).to be_false
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ describe '.size_square?' do
81
+
82
+ context 'with square size' do
83
+ subject { "64x64" }
84
+
85
+ it "returns true" do
86
+ expect(FaviconMaker::InputValidator.size_square?(subject)).to be_true
87
+ end
88
+ end
89
+
90
+ context 'with non-square size' do
91
+ subject { "64x32" }
92
+
93
+ it "returns false" do
94
+ expect(FaviconMaker::InputValidator.size_square?(subject)).to be_false
95
+ end
96
+ end
97
+ end
98
+
99
+ end
100
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: favicon_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Follmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-12 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -78,14 +78,17 @@ files:
78
78
  - Gemfile
79
79
  - Guardfile
80
80
  - LICENSE
81
+ - OLD_INSTRUCTIONS.md
81
82
  - README.md
82
83
  - favicon_maker.gemspec
83
84
  - lib/favicon_maker.rb
84
85
  - lib/favicon_maker/creator.rb
85
86
  - lib/favicon_maker/generator.rb
87
+ - lib/favicon_maker/input_validator.rb
86
88
  - lib/favicon_maker/maker_config.rb
87
89
  - lib/favicon_maker/version.rb
88
90
  - spec/favicon_maker_spec.rb
91
+ - spec/input_validator_spec.rb
89
92
  - spec/spec_helper.rb
90
93
  - spec/support/favicon base.png
91
94
  - spec/support/favicon_base.png
@@ -115,6 +118,7 @@ specification_version: 4
115
118
  summary: Create favicon files in various sizes from one or multiple base images
116
119
  test_files:
117
120
  - spec/favicon_maker_spec.rb
121
+ - spec/input_validator_spec.rb
118
122
  - spec/spec_helper.rb
119
123
  - spec/support/favicon base.png
120
124
  - spec/support/favicon_base.png