favicon_maker 0.3 → 1.0

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: 7b2fef14009c845e3a40a3794579d66c12d0f40e
4
- data.tar.gz: 8f8d56288229bf603dc326df4b872a2f4a61b4c4
3
+ metadata.gz: 5060beb595085399132ea1b324f4746153e142a1
4
+ data.tar.gz: b1037564b82ab94cad83b1616c0fab17c7c95390
5
5
  SHA512:
6
- metadata.gz: 6fbfcfc6086db90c91d36a4f84394adb8bea4ada8101fb73b01c27a49d282c1938ba66e77743d233bcfc80d100c85542638b5e0fa5458e76d95aedf15923e835
7
- data.tar.gz: 4ccd98ea5d07a56699ba295953c9dc6db1a2d3e2d4a4409da0ea2b18683f143e0393477e6376cec9388e20440d02b5ac366a715928173aa205ad571746e2bc5c
6
+ metadata.gz: 5dc5392d5193014f9e8a307ddaf17154d5dcfdd43f2a9b38606655e81bc34dd3badfffafd75d5964e3d853d64ebae2d9d86dc5cf976a0bfc93cf818480fe579a
7
+ data.tar.gz: c3fedf492456d8f9c8c3a945835610469118a95de51e441c70f65c4d515628463ae334218812e76436af469357a05d1898f4a86773723ea39d60c4b9df6abd4d
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ # watch(%r{^lib/(.+)\.rb$}) { |m| ["spec/lib/#{m[1]}_spec.rb", "spec/favicon_maker_spec.rb"] }
7
+ watch(%r{^lib/favicon_maker/(.+)\.rb$}) { |m| ["spec/lib/#{m[1]}_spec.rb", "spec/favicon_maker_spec.rb"] }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
10
+
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  FaviconMaker [![Build Status](https://secure.travis-ci.org/follmann/favicon_maker.png)](http://travis-ci.org/follmann/favicon_maker)
2
3
  ============
3
4
 
@@ -5,83 +6,185 @@ Tired of creating a gazillion different favicons to satisfy all kinds of devices
5
6
 
6
7
  I know I was, so I created FaviconMaker to ease the tedious process of creating multiple versions of your favicon.
7
8
 
8
- The basic idea is to have one image file as source for all the different sizes and or formats (png/ico). If the input folder contains a precomposed file like a visually improved version of the 16x16 favicon.ico this file version will not be generated but the file optionally be copied to the output folder. The remaining versions will still be sourced from the input image defined.
9
-
10
- ## Install
11
- ### Standalone
12
- gem install favicon_maker
13
-
14
- ### Using Bundler (recommended)
15
- ...
16
- gem "favicon_maker"
17
- ...
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
10
+
11
+ ## Installation
12
+ Using Bundler
13
+
14
+ ``` shell
15
+ gem "favicon_maker"
16
+ ```
17
+ ## Using the DSL
18
+ ### 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
23
+
24
+ ### Complete example:
25
+ ``` ruby
26
+ FaviconMaker.generate do
27
+
28
+ setup do
29
+ template_dir "/home/app/favicon-templates"
30
+ output_dir "/home/app/public"
31
+ end
32
+
33
+ from "favicon_base_hires.png" do
34
+ icon "apple-touch-icon-152x152-precomposed.png"
35
+ icon "apple-touch-icon-144x144-precomposed.png"
36
+ icon "apple-touch-icon-120x120-precomposed.png"
37
+ icon "apple-touch-icon-114x114-precomposed.png"
38
+ icon "favicon-196x196.png"
39
+ icon "favicon-160x160.png"
40
+ icon "favicon-96x96.png"
41
+ icon "mstile-144x144", format: "png"
42
+ end
43
+
44
+ from "favicon_base.png" do
45
+ icon "apple-touch-icon-76x76-precomposed.png"
46
+ icon "apple-touch-icon-72x72-precomposed.png"
47
+ icon "apple-touch-icon-60x60-precomposed.png"
48
+ icon "apple-touch-icon-57x57-precomposed.png"
49
+ icon "apple-touch-icon-precomposed.png", size: "57x57"
50
+ icon "apple-touch-icon.png", size: "57x57"
51
+ icon "favicon-32x32.png"
52
+ icon "favicon-16x16.png"
53
+ icon "favicon.png", size: "16x16"
54
+ icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
55
+ end
56
+
57
+ each_icon do |filepath|
58
+ puts filepath # verbose example
59
+ end
60
+ end
61
+ ```
62
+
63
+ ## Changes from v0.3 to v1.0
64
+ * Almost entire rewrite
65
+ * DSL to configure the output
66
+ * No internal configuration and format definitions anymore
67
+ * Support for multiple template files
18
68
 
19
69
  ## Integration
20
70
  ### Middleman
21
- 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)
22
- ### Capistrano
23
- 1. Edit your Capfile and add the following line
24
-
25
- require "favicon_maker"
26
-
27
- 2. Add the following snippet to your deploy.rb
71
+ 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) with version v3.5 or higher
28
72
 
29
- namespace :favicon do
30
- task :create_versions do
31
- options = {
32
- :root_dir => release_path,
33
- :input_dir => File.join("app", "assets", "public"),
34
- :output_dir => "public"
35
- }
36
- FaviconMaker::Generator.create_versions(options) do |filepath|
37
- puts "Created favicon: #{filepath}"
38
- end
39
- end
40
- end
41
-
42
- after "deploy:update_code", "favicon:create_versions"
73
+ ## Template Image Guideline
74
+ 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.
43
75
 
44
- **Note: This snippet is untested but should work**
45
-
46
- ## Basic Usage
47
- ### Simple
48
- require "rubygems"
49
- require "favicon_maker"
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
50
80
 
51
- FaviconMaker::Generator.create_versions
52
-
53
- Uses the following defaults:
54
-
55
- options = {
56
- :versions => [:apple_152, :apple_144, :apple_120, :apple_114, :apple_76, :apple_72, :apple_60, :apple_57, :apple, :fav_196, :fav_160, :fav_96, :fav_32, :fav_16, :fav_png, :fav_ico, :mstile_144],
57
- :custom_versions => {},
58
- :root_dir => File.dirname(__FILE__),
59
- :input_dir => "favicons",
60
- :base_image => "favicon_base.png",
61
- :output_dir => "favicons_output",
62
- :copy => false
63
- }
64
-
65
- ### Advanced
66
- (untested attempted Rails integration, using all available options. Could be used in a Rake task or Capistrano recipe)
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
67
87
 
88
+ ``` ruby
89
+ namespace :favicon do
90
+ task :create_versions do
68
91
  options = {
69
- :versions => [:apple_152, :apple_144, :apple_120, :apple_114, :apple_76, :apple_72, :apple_60, :apple_57, :apple, :fav_196, :fav_160, :fav_96, :fav_32, :fav_16, :fav_png, :fav_ico, :mstile_144],
70
- :custom_versions => {:apple_extreme_retina => {:filename => "apple-touch-icon-228x228-precomposed.png", :dimensions => "228x228", :format => "png"}},
71
- :root_dir => Rails.root,
92
+ :root_dir => release_path,
72
93
  :input_dir => File.join("app", "assets", "public"),
73
- :base_image => "favicon.png",
74
- :output_dir => "public",
75
- :copy => true
94
+ :output_dir => "public"
76
95
  }
77
-
78
96
  FaviconMaker::Generator.create_versions(options) do |filepath|
79
97
  puts "Created favicon: #{filepath}"
80
98
  end
99
+ end
100
+ end
101
+
102
+ after "deploy:update_code", "favicon:create_versions"
103
+ ```
81
104
 
82
- ## Base Image Guideline
83
- Choose the version with the biggest dimension as your base image. Currently the size 196x196 for newer iOS devices marks the upper limit. So just create a PNG with 24 or 32 Bit color depth and 196x196 document size. Downscaling of images always works better than upscaling.
105
+ **Note: This snippet is untested but should work**
84
106
 
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
+ ```
85
187
  ## Copyright
86
188
 
87
- © 2011 Andreas Follmann. See LICENSE for details.
189
+ © 2011-2014 Andreas Follmann. See LICENSE for details.
190
+
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
10
10
  s.authors = ["Andreas Follmann"]
11
11
  #s.email = [""]
12
12
  s.homepage = "https://github.com/follmann/favicon_maker"
13
- s.summary = %q{Create favicon files in various sizes from a base image}
14
- s.description = %q{Create favicon files in various sizes from a base image}
13
+ s.summary = %q{Create favicon files in various sizes from one or multiple base images}
14
+ s.description = %q{Create favicon files in various sizes from one or multiple base images}
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency("mini_magick", ["~> 3.5"])
22
+ s.add_runtime_dependency("docile", ["~> 1.1.2"])
22
23
 
23
- s.add_development_dependency("rspec", ["~> 2.6.0"])
24
+ s.add_development_dependency("rspec", ["~> 2.14.1"])
25
+ s.add_development_dependency("guard-rspec")
24
26
  end
data/lib/favicon_maker.rb CHANGED
@@ -1,9 +1,3 @@
1
- module FaviconMaker
2
-
3
- libdir = File.dirname(__FILE__)
4
- $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
-
6
- # Auto-load modules on-demand
7
- autoload :Generator, "favicon_maker/generator"
8
-
9
- end
1
+ require "favicon_maker/maker_config"
2
+ require "favicon_maker/generator"
3
+ require "favicon_maker/creator"
@@ -0,0 +1,101 @@
1
+ require "mini_magick"
2
+ require 'fileutils'
3
+
4
+ module FaviconMaker
5
+
6
+ class Creator
7
+ RECENT_IM_VERSION = "6.8.0"
8
+ COLORSPACE_MIN_IM_VERSION = "6.7.5"
9
+
10
+ attr_accessor :template_file_path
11
+ attr_accessor :output_path
12
+ attr_accessor :colorspace_in
13
+ attr_accessor :colorspace_out
14
+ attr_accessor :finished_block
15
+
16
+ def initialize(template_file_path, output_path, finished_block)
17
+ @template_file_path = template_file_path
18
+ @output_path = output_path
19
+ @finished_block = finished_block
20
+
21
+ im_version = fetch_image_magick_version
22
+
23
+ if im_version
24
+ print_image_magick_ancient_version_warning if im_version < RECENT_IM_VERSION
25
+ if im_version < COLORSPACE_MIN_IM_VERSION
26
+ @colorspace_in = "sRGB"
27
+ @colorspace_out = "RGB"
28
+ else
29
+ @colorspace_in = "RGB"
30
+ @colorspace_out = "sRGB"
31
+ end
32
+ else
33
+ print_image_magick_no_version_warning
34
+ @colorspace_in = "RGB"
35
+ @colorspace_out = "sRGB"
36
+ end
37
+ end
38
+
39
+ def icon(output_filename, options={})
40
+ format = options[:format] || extract_format(output_filename)
41
+ size = options[:size] || extract_size(output_filename)
42
+ output_file_path = File.join(output_path, output_filename)
43
+
44
+ generate_file(template_file_path, output_file_path, size, format)
45
+
46
+ finished_block.call(output_file_path, template_file_path) if finished_block
47
+ end
48
+
49
+ private
50
+
51
+ def fetch_image_magick_version
52
+ version = (`convert --version`).scan(/ImageMagick (\d\.\d\.\d)/).flatten.first
53
+ end
54
+
55
+ def extract_format(output_filename)
56
+ File.extname(output_filename).split('.').last
57
+ end
58
+
59
+ def extract_size(output_filename)
60
+ matches = output_filename.match /.*-(\d+x\d+).*/
61
+ matches[1] if matches
62
+ end
63
+
64
+ def generate_file(template_file_path, output_file_path, size, format)
65
+ case format.to_sym
66
+ when :png
67
+ image = MiniMagick::Image.open(template_file_path)
68
+ image.define "png:include-chunk=none,trns,gama"
69
+ image.colorspace colorspace_in
70
+ image.resize size
71
+ image.format "png"
72
+ image.strip
73
+ image.colorspace colorspace_out
74
+ image.write output_file_path
75
+ when :ico
76
+ ico_cmd = "convert \"#{template_file_path}\" -colorspace #{colorspace_in} "
77
+ escapes = "\\" unless on_windows?
78
+ size.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |s|
79
+ ico_cmd << "#{escapes}( -clone 0 -resize #{s} #{escapes}) "
80
+ end
81
+ ico_cmd << "-delete 0 -colorspace #{colorspace_out} \"#{output_file_path}\""
82
+ print `#{ico_cmd}`
83
+ end
84
+ end
85
+
86
+ 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!"
88
+ end
89
+
90
+
91
+ def print_image_magick_no_version_warning
92
+ puts "FaviconMaker: WARNING! The version of your installed ImageMagick could not be detected!"
93
+ end
94
+
95
+ def on_windows?
96
+ (RbConfig::CONFIG['host_os'].match /mswin|mingw|cygwin/)
97
+ end
98
+
99
+ end
100
+
101
+ end
@@ -1,142 +1,43 @@
1
- module FaviconMaker
2
- require "mini_magick"
3
- require 'fileutils'
4
- require 'pathname'
5
-
6
- class Generator
7
-
8
- ICON_VERSION_DEFINITIONS = {
9
- :apple_152 => { :filename => "apple-touch-icon-152x152-precomposed.png", :sizes => "152x152", :format => "png" },
10
- :apple_144 => { :filename => "apple-touch-icon-144x144-precomposed.png", :sizes => "144x144", :format => "png" },
11
- :apple_120 => { :filename => "apple-touch-icon-120x120-precomposed.png", :sizes => "120x120", :format => "png" },
12
- :apple_114 => { :filename => "apple-touch-icon-114x114-precomposed.png", :sizes => "114x114", :format => "png" },
13
- :apple_76 => { :filename => "apple-touch-icon-76x76-precomposed.png", :sizes => "76x76", :format => "png" },
14
- :apple_72 => { :filename => "apple-touch-icon-72x72-precomposed.png", :sizes => "72x72", :format => "png" },
15
- :apple_60 => { :filename => "apple-touch-icon-60x60-precomposed.png", :sizes => "60x60", :format => "png" },
16
- :apple_57 => { :filename => "apple-touch-icon-57x57-precomposed.png", :sizes => "57x57", :format => "png" },
17
- :apple_pre => { :filename => "apple-touch-icon-precomposed.png", :sizes => "57x57", :format => "png" },
18
- :apple => { :filename => "apple-touch-icon.png", :sizes => "57x57", :format => "png" },
19
- :fav_196 => { :filename => "favicon-196x196.png", :sizes => "196x196", :format => "png" },
20
- :fav_160 => { :filename => "favicon-160x160.png", :sizes => "160x160", :format => "png" },
21
- :fav_96 => { :filename => "favicon-96x96.png", :sizes => "96x96", :format => "png" },
22
- :fav_32 => { :filename => "favicon-32x32.png", :sizes => "32x32", :format => "png" },
23
- :fav_16 => { :filename => "favicon-16x16.png", :sizes => "16x16", :format => "png" },
24
- :fav_png => { :filename => "favicon.png", :sizes => "16x16", :format => "png" },
25
- :fav_ico => { :filename => "favicon.ico", :sizes => "64x64,32x32,24x24,16x16", :format => "ico" },
26
- :mstile_144 => { :filename => "mstile-144x144", :sizes => "144x144", :format => "png" }
27
- }
28
-
29
- DEFAULT_OPTIONS = {
30
- :versions => ICON_VERSION_DEFINITIONS.keys,
31
- :custom_versions => {},
32
- :root_dir => File.dirname(__FILE__),
33
- :input_dir => "favicons",
34
- :base_image => "favicon_base.png",
35
- :output_dir => "favicons_output",
36
- :copy => false
37
- }
38
-
39
- IM_VERSION = (`convert --version`).scan(/ImageMagick (\d\.\d\.\d)/).flatten.first
40
- RECENT_VERSION = "6.8.0"
41
- COLORSPACE_MIN_VERSION = "6.7.5"
42
- COLORSPACE_IN, COLORSPACE_OUT = *(IM_VERSION < COLORSPACE_MIN_VERSION ? ["sRGB", "RGB"] : ["RGB", "sRGB"])
43
-
44
- class << self
1
+ require 'docile'
45
2
 
46
- def create_versions(options={}, &block)
47
- print_image_magick_warning if IM_VERSION < RECENT_VERSION
48
-
49
- options = DEFAULT_OPTIONS.merge(options)
50
- raise ArgumentError unless options[:versions].is_a? Array
51
-
52
- base_path = File.join(options[:root_dir], options[:input_dir])
53
- output_path = determine_output_path(options[:root_dir], options[:output_dir])
54
- input_file_path = File.join(base_path, options[:base_image])
55
- copy_composed = options[:copy]
56
-
57
- process_icon_versions(options[:versions], options[:custom_versions]) do |version|
58
- build_mode, output_file_path = copy_or_generate_file(
59
- input_file_path,
60
- base_path,
61
- output_path,
62
- copy_composed,
63
- version
64
- )
65
-
66
- if block_given?
67
- yield output_file_path, build_mode
68
- end
69
- end
70
- end
71
-
72
- private
3
+ module FaviconMaker
73
4
 
74
- def copy_or_generate_file(input_file_path, base_path, output_path, copy_composed, version)
75
- sizes = version[:dimensions] || version[:sizes]
76
- composed_file_path = File.join(base_path, version[:filename])
77
- output_file_path = File.join(output_path, version[:filename])
78
- output_format = version[:format]
5
+ class << self
6
+ def generate(&block)
7
+ Docile.dsl_eval(Generator.new, &block).start
8
+ end
9
+ end
79
10
 
80
- # check for self composed icon file
81
- if copy_composed && File.exist?(composed_file_path)
82
- copy_image(composed_file_path, output_file_path)
83
- return :copied, output_file_path
84
- else
85
- generate_file(output_format, sizes, input_file_path, output_file_path)
86
- return :generated, output_file_path
87
- end
88
- end
11
+ class Generator
12
+ extend Forwardable
89
13
 
90
- def generate_file(format, sizes, input_file_path, output_file_path)
91
- case format.to_sym
92
- when :png
93
- image = MiniMagick::Image.open(input_file_path)
94
- image.define "png:include-chunk=none,trns,gama"
95
- image.colorspace COLORSPACE_IN
96
- image.resize sizes
97
- image.format "png"
98
- image.strip
99
- image.colorspace COLORSPACE_OUT
100
- image.write output_file_path
101
- when :ico
102
- ico_cmd = "convert \"#{input_file_path}\" -colorspace #{COLORSPACE_IN} "
103
- escapes = "\\" unless on_windows?
104
- sizes.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |size|
105
- ico_cmd << "#{escapes}( -clone 0 -resize #{size} #{escapes}) "
106
- end
107
- ico_cmd << "-delete 0 -colorspace #{COLORSPACE_OUT} \"#{output_file_path}\""
108
- puts `#{ico_cmd}`
109
- end
110
- end
14
+ attr_accessor :config
15
+ attr_accessor :creators
16
+ attr_accessor :finished_block
111
17
 
112
- def copy_image(composed_file_path, output_file_path)
113
- FileUtils.cp(composed_file_path, output_file_path)
114
- end
18
+ delegate [:template_dir, :output_dir] => :config
115
19
 
116
- def determine_output_path(root_dir, output_dir)
117
- if Pathname.new(output_dir).absolute?
118
- output_dir
119
- else
120
- File.join(root_dir, output_dir)
121
- end
122
- end
20
+ def initialize
21
+ @creators = {}
22
+ end
123
23
 
124
- def process_icon_versions(versions, custom_versions, &block)
125
- icon_versions_available = ICON_VERSION_DEFINITIONS.merge(custom_versions)
24
+ def setup(&block)
25
+ @config = Docile.dsl_eval(MakerConfig.new, &block)
26
+ end
126
27
 
127
- (versions + custom_versions.keys).uniq.each do |version_label|
128
- yield icon_versions_available[version_label]
129
- end
130
- end
28
+ def from(template_filename, &block)
29
+ creators[template_filename] = block
30
+ end
131
31
 
132
- def print_image_magick_warning
133
- puts "FaviconMaker: WARNING! Your installed ImageMagick version #{IM_VERSION} is not up-to-date and might produce suboptimal output!"
134
- end
32
+ def each_icon(&block)
33
+ @finished_block = block
34
+ end
135
35
 
136
- def on_windows?
137
- (RbConfig::CONFIG['host_os'].match /mswin|mingw|cygwin/)
36
+ def start
37
+ creators.each do |template_filename, creator_block|
38
+ template_file = File.join(template_dir, template_filename)
39
+ Docile.dsl_eval(Creator.new(template_file, output_dir, finished_block), &creator_block)
138
40
  end
139
-
140
41
  end
141
42
  end
142
43
  end
@@ -0,0 +1,8 @@
1
+ class MakerConfig
2
+ [:template_dir, :output_dir].each do |method_name|
3
+ define_method method_name do |dir=nil|
4
+ instance_variable_set("@#{method_name}", dir) if dir
5
+ instance_variable_get("@#{method_name}")
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module FaviconMaker
2
- VERSION = "0.3"
2
+ VERSION = "1.0"
3
3
  end
@@ -2,116 +2,146 @@ require 'spec_helper'
2
2
 
3
3
  describe FaviconMaker, '#create_versions' do
4
4
 
5
- before(:all) do
6
- @multi_versions = []
7
- @uni_versions = []
8
- @options = {
9
- :versions => [
10
- :apple_152,
11
- :apple_144,
12
- :apple_120,
13
- :apple_114,
14
- :apple_76,
15
- :apple_72,
16
- :apple_60,
17
- :apple_57,
18
- :apple,
19
- :fav_196,
20
- :fav_160,
21
- :fav_96,
22
- :fav_32,
23
- :fav_16,
24
- :fav_png,
25
- :fav_ico,
26
- :mstile_144
27
- ],
28
- :custom_versions => {
29
- :apple_extreme_retina => {
30
- :filename => "apple-touch-icon-228x228-precomposed.png", :sizes => "228x228", :format => "png"
31
- }
32
- },
33
- :root_dir => File.join(Dir.pwd, "spec"),
34
- :input_dir => "support",
35
- :copy => true
36
- }
37
-
38
- @cleanup = lambda do |output_dir|
39
- if Dir.exists?(output_dir)
40
- Dir[File.join(output_dir, "*")].each do |file|
41
- File.delete(file)
42
- end
43
- Dir.delete(output_dir)
5
+ let(:absolute_root_dir) { File.join(Dir.pwd, "spec") }
6
+ let(:absolute_template_dir) { File.join(absolute_root_dir, "support") }
7
+
8
+ let(:base_image) { "favicon base.png" }
9
+
10
+ let(:output_path) { File.join(absolute_root_dir, relative_output_dir) }
11
+
12
+ def cleanup(output_dir)
13
+ if Dir.exists?(output_dir)
14
+ Dir[File.join(output_dir, "*")].each do |file|
15
+ File.delete(file)
44
16
  end
17
+ Dir.delete(output_dir)
45
18
  end
46
19
  end
47
20
 
48
21
  context "multi-color icon" do
22
+
23
+ let(:relative_output_dir) { "output1" }
24
+
49
25
  before do
50
- options = @options.merge({
51
- :base_image => "favicon base.png",
52
- :output_dir => "output1"
53
- })
26
+ cleanup(output_path)
27
+ Dir.mkdir(output_path)
28
+ end
54
29
 
55
- @output_dir = File.join(options[:root_dir], options[:output_dir])
30
+ subject do
31
+ files = []
32
+ template_files = []
56
33
 
57
- @cleanup.call(@output_dir)
34
+ FaviconMaker.generate do
58
35
 
59
- Dir.mkdir(@output_dir)
36
+ setup do
37
+ template_dir absolute_template_dir
38
+ output_dir output_path
39
+ end
60
40
 
61
- FaviconMaker::Generator.create_versions(options) do |filepath, status|
62
- @multi_versions << filepath
63
- end
64
- end
41
+ from "favicon base.png" do
42
+ icon "apple-touch-icon-152x152-precomposed.png"
43
+ icon "apple-touch-icon-144x144-precomposed.png"
44
+ icon "apple-touch-icon-120x120-precomposed.png"
45
+ icon "apple-touch-icon-114x114-precomposed.png"
46
+ icon "apple-touch-icon-76x76-precomposed.png"
47
+ icon "apple-touch-icon-72x72-precomposed.png"
48
+ icon "apple-touch-icon-60x60-precomposed.png"
49
+ icon "apple-touch-icon-57x57-precomposed.png"
50
+ icon "apple-touch-icon-precomposed.png", size: "57x57"
51
+ icon "apple-touch-icon.png", size: "57x57"
52
+ end
53
+
54
+ from "favicon_base.png" do
55
+ icon "favicon-196x196.png"
56
+ icon "favicon-160x160.png"
57
+ icon "favicon-96x96.png"
58
+ icon "favicon-32x32.png"
59
+ icon "favicon-16x16.png"
60
+ icon "favicon.png", size: "16x16"
61
+ icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
62
+ icon "mstile-144x144", format: "png"
63
+ end
65
64
 
66
- it "creates 18 different versions" do
67
- @multi_versions.size.should eql(18)
65
+ each_icon do |filepath, template_filepath|
66
+ files << filepath
67
+ template_files << template_filepath
68
+ end
69
+ end
70
+ return files, template_files
68
71
  end
69
72
 
70
- it "creates files for versions" do
71
- @multi_versions.each do |file|
72
- File.exists?(file).should be_true
73
+ it "creates 18 files" do
74
+ files, template_files = subject
75
+ expect(files.size).to eql(18)
76
+ files.each do |file|
77
+ expect(File.exists?(file)).to be_true
73
78
  end
79
+ expect(template_files.uniq.size).to eql(2)
74
80
  end
75
81
 
76
82
  after do
77
- @cleanup.call(@output_dir)
83
+ cleanup(output_path)
78
84
  end
79
85
 
80
86
  end
81
87
 
82
88
  context "uni-color icon" do
83
89
 
90
+ let(:relative_output_dir) { "output2" }
91
+
84
92
  before do
85
- options = @options.merge({
86
- :base_image => "favicon_base_uni.png",
87
- :output_dir => "output2"
88
- })
93
+ cleanup(output_path)
94
+ Dir.mkdir(output_path)
95
+ end
89
96
 
90
- @output_dir = File.join(options[:root_dir], options[:output_dir])
97
+ subject do
98
+ files = []
91
99
 
92
- @cleanup.call(@output_dir)
100
+ FaviconMaker.generate do
93
101
 
94
- Dir.mkdir(@output_dir)
102
+ setup do
103
+ template_dir absolute_template_dir
104
+ output_dir output_path
105
+ end
95
106
 
96
- FaviconMaker::Generator.create_versions(options) do |filepath, status|
97
- @uni_versions << filepath
98
- end
99
- end
107
+ from "favicon_base_uni.png" do
108
+ icon "apple-touch-icon-152x152-precomposed.png"
109
+ icon "apple-touch-icon-144x144-precomposed.png"
110
+ icon "apple-touch-icon-120x120-precomposed.png"
111
+ icon "apple-touch-icon-114x114-precomposed.png"
112
+ icon "apple-touch-icon-76x76-precomposed.png"
113
+ icon "apple-touch-icon-72x72-precomposed.png"
114
+ icon "apple-touch-icon-60x60-precomposed.png"
115
+ icon "apple-touch-icon-57x57-precomposed.png"
116
+ icon "apple-touch-icon-precomposed.png", size: "57x57"
117
+ icon "apple-touch-icon.png", size: "57x57"
118
+ icon "favicon-196x196.png"
119
+ icon "favicon-160x160.png"
120
+ icon "favicon-96x96.png"
121
+ icon "favicon-32x32.png"
122
+ icon "favicon-16x16.png"
123
+ icon "favicon.png", size: "16x16"
124
+ icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
125
+ icon "mstile-144x144", format: "png"
126
+ end
100
127
 
101
- it "creates 18 different versions" do
102
- @uni_versions.size.should eql(18)
128
+ each_icon do |filepath|
129
+ files << filepath
130
+ end
131
+ end
132
+ files
103
133
  end
104
134
 
105
- it "creates files for versions" do
106
- @uni_versions.each do |file|
107
- File.exists?(file).should be_true
135
+ it "creates 18 files" do
136
+ files = subject
137
+ expect(files.size).to eql(18)
138
+ files.each do |file|
139
+ expect(File.exists?(file)).to be_true
108
140
  end
109
141
  end
110
142
 
111
143
  after do
112
- @cleanup.call(@output_dir)
144
+ cleanup(output_path)
113
145
  end
114
-
115
146
  end
116
-
117
147
  end
Binary file
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: '0.3'
4
+ version: '1.0'
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-09 00:00:00.000000000 Z
11
+ date: 2014-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -24,21 +24,49 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: docile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: 2.6.0
47
+ version: 2.14.1
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: 2.6.0
41
- description: Create favicon files in various sizes from a base image
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Create favicon files in various sizes from one or multiple base images
42
70
  email:
43
71
  executables: []
44
72
  extensions: []
@@ -48,15 +76,19 @@ files:
48
76
  - .rspec
49
77
  - .travis.yml
50
78
  - Gemfile
79
+ - Guardfile
51
80
  - LICENSE
52
81
  - README.md
53
82
  - favicon_maker.gemspec
54
83
  - lib/favicon_maker.rb
84
+ - lib/favicon_maker/creator.rb
55
85
  - lib/favicon_maker/generator.rb
86
+ - lib/favicon_maker/maker_config.rb
56
87
  - lib/favicon_maker/version.rb
57
88
  - spec/favicon_maker_spec.rb
58
89
  - spec/spec_helper.rb
59
90
  - spec/support/favicon base.png
91
+ - spec/support/favicon_base.png
60
92
  - spec/support/favicon_base_uni.png
61
93
  homepage: https://github.com/follmann/favicon_maker
62
94
  licenses: []
@@ -80,9 +112,10 @@ rubyforge_project:
80
112
  rubygems_version: 2.1.11
81
113
  signing_key:
82
114
  specification_version: 4
83
- summary: Create favicon files in various sizes from a base image
115
+ summary: Create favicon files in various sizes from one or multiple base images
84
116
  test_files:
85
117
  - spec/favicon_maker_spec.rb
86
118
  - spec/spec_helper.rb
87
119
  - spec/support/favicon base.png
120
+ - spec/support/favicon_base.png
88
121
  - spec/support/favicon_base_uni.png