motion-assets 0.1.0 → 0.1.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 +6 -1
- data/lib/motion/project/assets.rb +53 -19
- data/lib/motion/project/icons.rb +25 -9
- data/lib/motion/project/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42a198c9ee75c5cb11f3ff165059ded24c3df0de
|
4
|
+
data.tar.gz: 8b78ee302a50bb9649193d010d92c02aef00f471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a765cadb43e1d4684a7028a5b48a8a03907866452b18ecaee5db0e7c884bf739345b7559720e516e9780c46a4ddfa120615bfb0ccfb1b95579525828b4ef6775
|
7
|
+
data.tar.gz: 19e8f674d082a9ddb50c6782f6d060a131ee6f0eae435879a84d402d82e5706493295da031ce896defd787b3ac5ed0a02c560bc1a524e6b68f30c4e1b5bb0e0b
|
data/README.md
CHANGED
@@ -38,6 +38,9 @@ Motion::Project::App.setup do |app|
|
|
38
38
|
# ...
|
39
39
|
app.assets.source_icon = "./src_images/icon-1024x1024.png"
|
40
40
|
app.assets.source_splash = "./src_images/splash-1024x1024.png"
|
41
|
+
|
42
|
+
# optional
|
43
|
+
app.assets.output_dir = "./some/directory"
|
41
44
|
end
|
42
45
|
```
|
43
46
|
|
@@ -53,6 +56,8 @@ Motion::Project::App.setup do |app|
|
|
53
56
|
end
|
54
57
|
```
|
55
58
|
|
59
|
+
Note : motion-assets will autopopulate your `app.icons` array with the list of created icons.
|
60
|
+
|
56
61
|
## Tasks
|
57
62
|
|
58
63
|
To tell motion-assets to generate the assets :
|
@@ -62,4 +67,4 @@ $ [bundle exec] rake assets:generate
|
|
62
67
|
```
|
63
68
|
|
64
69
|
|
65
|
-
note : the sample icon comes from the
|
70
|
+
note : the sample icon comes from the great Pixelmator tool, http://www.pixelmator.com/
|
@@ -14,6 +14,10 @@ module Motion::Project
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Assets
|
17
|
+
BASE_SPLASH_SIZE = [2028, 2028]
|
18
|
+
BASE_IOS_ICON_SIZE = [1024, 1024]
|
19
|
+
BASE_ANDROID_ICON_SIZE = [512, 512]
|
20
|
+
|
17
21
|
IOS_ICONS = %w{
|
18
22
|
Icon-Small.png|29x29
|
19
23
|
Icon-Small@2x.png|58x58
|
@@ -57,28 +61,36 @@ module Motion::Project
|
|
57
61
|
drawable-ldpi/splash-land.png|320x200
|
58
62
|
drawable-mdpi/splash-land.png|480x320
|
59
63
|
drawable-xhdpi/splash-land.png|1280x720
|
64
|
+
drawable-xxhdpi/splash-land.png|1600x960
|
65
|
+
drawable-xxxhdpi/splash-land.png|1920x1280
|
60
66
|
drawable-hdpi/splash-port.png|480x800
|
61
67
|
drawable-ldpi/splash-port.png|200x320
|
62
68
|
drawable-mdpi/splash-port.png|320x480
|
63
|
-
drawable-xhdpi/splash-port.png|
|
69
|
+
drawable-xhdpi/splash-port.png|720x1280
|
70
|
+
drawable-xxhdpi/splash-port.png|960x1600
|
71
|
+
drawable-xxxhdpi/splash-port.png|1280x1920
|
64
72
|
}
|
65
73
|
|
66
74
|
def initialize(config)
|
67
75
|
@config = config
|
68
76
|
@images = []
|
69
|
-
@icons = Icons.new(config)
|
77
|
+
@icons = Icons.new(@config, platform)
|
70
78
|
@image_optim = '/Applications/ImageOptim.app/Contents/MacOS/ImageOptim'
|
71
79
|
|
72
80
|
if ios?
|
73
81
|
@icons << IOS_ICONS
|
74
82
|
@splashes = IOS_SPLASHES
|
75
83
|
end
|
84
|
+
|
76
85
|
if android?
|
86
|
+
@config.icon = 'icon.png'
|
77
87
|
@icons << ANDROID_ICONS
|
78
88
|
@splashes = ANDROID_SPLASHES
|
79
89
|
end
|
90
|
+
|
80
91
|
@source_icon = "./src_images/icon.png"
|
81
92
|
@source_splash = "./src_images/splash.png"
|
93
|
+
@output_dir = @config.resources_dirs.first
|
82
94
|
end
|
83
95
|
|
84
96
|
def source_icon=(source_icon)
|
@@ -89,17 +101,30 @@ module Motion::Project
|
|
89
101
|
@source_splash = source_splash
|
90
102
|
end
|
91
103
|
|
104
|
+
def output_dir=(output_dir)
|
105
|
+
@output_dir = output_dir
|
106
|
+
end
|
107
|
+
|
92
108
|
def icons
|
93
109
|
@icons
|
94
110
|
end
|
95
111
|
|
112
|
+
def icons=(icons)
|
113
|
+
@icons = Icons.new(@config, platform)
|
114
|
+
if ios?
|
115
|
+
@config.icons = []
|
116
|
+
end
|
117
|
+
@icons << icons
|
118
|
+
end
|
119
|
+
|
96
120
|
def splashes
|
97
121
|
@splashes
|
98
122
|
end
|
99
123
|
|
100
124
|
def generate!
|
101
|
-
validate_source_icon
|
102
|
-
validate_source_splash
|
125
|
+
validate_source_icon
|
126
|
+
validate_source_splash
|
127
|
+
validate_output_dir
|
103
128
|
generate_icons
|
104
129
|
generate_splashes
|
105
130
|
optimize_images
|
@@ -107,11 +132,17 @@ module Motion::Project
|
|
107
132
|
|
108
133
|
protected
|
109
134
|
|
135
|
+
def validate_output_dir
|
136
|
+
unless File.exist?(@output_dir)
|
137
|
+
App.fail "Output directory : #{@output_dir} doesn't exist, please create it."
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
110
141
|
def generate_splashes
|
111
142
|
App.info "[info]", "Generating splashes..."
|
112
143
|
@splashes.each do |splash|
|
113
144
|
parts = splash.split('|')
|
114
|
-
path = File.join(@
|
145
|
+
path = File.join(@output_dir, parts[0])
|
115
146
|
FileUtils.mkdir_p(File.dirname(path))
|
116
147
|
generate_image(@source_splash, path, parts[1])
|
117
148
|
@images << path
|
@@ -122,12 +153,11 @@ module Motion::Project
|
|
122
153
|
def generate_icons
|
123
154
|
App.info "[info]", "Generating icons..."
|
124
155
|
@icons.each do |icon|
|
125
|
-
|
126
|
-
path = File.join(@config.resources_dirs.first, parts[0])
|
156
|
+
path = File.join(@output_dir, icon.name)
|
127
157
|
FileUtils.mkdir_p(File.dirname(path))
|
128
|
-
generate_image(@source_icon, path,
|
158
|
+
generate_image(@source_icon, path, icon.dimensions)
|
129
159
|
@images << path
|
130
|
-
App.info "-",
|
160
|
+
App.info "-", icon.name
|
131
161
|
end
|
132
162
|
end
|
133
163
|
|
@@ -147,35 +177,39 @@ module Motion::Project
|
|
147
177
|
image.write(path)
|
148
178
|
end
|
149
179
|
|
150
|
-
def validate_source_icon
|
180
|
+
def validate_source_icon
|
151
181
|
unless File.exist?(@source_icon)
|
152
182
|
App.fail "You have to provide a valid base icon in your rakefile : app.assets.source_icon = './some/path/image.png"
|
153
183
|
end
|
154
184
|
image = MiniMagick::Image.open(@source_icon)
|
155
|
-
if ios? && image.dimensions !=
|
156
|
-
App.info "[warning]", "Your source icon image dimensions #{image.dimensions} is different from recommended dimensions :
|
185
|
+
if ios? && image.dimensions != BASE_IOS_ICON_SIZE
|
186
|
+
App.info "[warning]", "Your source icon image dimensions #{image.dimensions} is different from recommended dimensions : #{BASE_IOS_ICON_SIZE}"
|
157
187
|
end
|
158
|
-
if android? && image.dimensions !=
|
159
|
-
App.info "[warning]", "Your source icon image dimensions #{image.dimensions} is different from recommended dimensions :
|
188
|
+
if android? && image.dimensions != BASE_ANDROID_ICON_SIZE
|
189
|
+
App.info "[warning]", "Your source icon image dimensions #{image.dimensions} is different from recommended dimensions : #{BASE_ANDROID_ICON_SIZE}"
|
160
190
|
end
|
161
191
|
end
|
162
192
|
|
163
|
-
def validate_source_splash
|
193
|
+
def validate_source_splash
|
164
194
|
unless File.exist?(@source_splash)
|
165
195
|
App.fail "You have to provide a valid base splash in your rakefile : app.assets.source_splash = './some/path/image.png"
|
166
196
|
end
|
167
197
|
image = MiniMagick::Image.open(@source_splash)
|
168
|
-
if image.dimensions !=
|
169
|
-
App.info "[warning]", "Your source splash image dimensions #{image.dimensions} is different from recommended dimensions :
|
198
|
+
if image.dimensions != BASE_SPLASH_SIZE
|
199
|
+
App.info "[warning]", "Your source splash image dimensions #{image.dimensions} is different from recommended dimensions : #{BASE_SPLASH_SIZE}"
|
170
200
|
end
|
171
201
|
end
|
172
202
|
|
173
203
|
def android?
|
174
|
-
|
204
|
+
platform == :android
|
175
205
|
end
|
176
206
|
|
177
207
|
def ios?
|
178
|
-
|
208
|
+
platform == :ios
|
209
|
+
end
|
210
|
+
|
211
|
+
def platform
|
212
|
+
Motion::Project::App.template
|
179
213
|
end
|
180
214
|
end
|
181
215
|
end
|
data/lib/motion/project/icons.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
class Icons
|
2
2
|
include Enumerable
|
3
|
+
Struct.new("Icon", :name, :dimensions)
|
3
4
|
|
4
|
-
def initialize(config)
|
5
|
+
def initialize(config, platform)
|
5
6
|
@list = []
|
6
7
|
@config = config
|
8
|
+
@platform = platform
|
7
9
|
end
|
8
10
|
|
9
11
|
def list
|
@@ -11,20 +13,27 @@ class Icons
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def <<(*icons)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
icons.flatten.each do |icon_string|
|
17
|
+
icon = create_icon(icon_string)
|
18
|
+
@list << icon
|
19
|
+
|
20
|
+
if @platform == :ios
|
21
|
+
@config.icons << icon.name
|
22
|
+
end
|
18
23
|
end
|
19
24
|
self
|
20
25
|
end
|
21
26
|
alias_method :push, :<<
|
22
27
|
|
23
28
|
def delete(*icons)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@
|
29
|
+
icons.flatten.each do |icon_string|
|
30
|
+
icon = @list.find {|icon| icon.name == icon_string}
|
31
|
+
|
32
|
+
if @platform == :ios
|
33
|
+
@config.icons.delete icon.name
|
34
|
+
end
|
35
|
+
|
36
|
+
@list.delete(icon)
|
28
37
|
end
|
29
38
|
self
|
30
39
|
end
|
@@ -32,4 +41,11 @@ class Icons
|
|
32
41
|
def each(&block)
|
33
42
|
@list.each(&block)
|
34
43
|
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def create_icon(icon_string)
|
48
|
+
parts = icon_string.split('|')
|
49
|
+
Struct::Icon.new(parts[0], parts[1])
|
50
|
+
end
|
35
51
|
end
|