motion-assets 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/motion-assets.rb +1 -0
- data/lib/motion/project/assets.rb +127 -26
- data/lib/motion/project/icons.rb +35 -0
- data/lib/motion/project/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe5eb2bdbee7006a2f514026703af1379f68f9e7
|
4
|
+
data.tar.gz: dfd66401c31488c6a468ef8f866f0e38d225ac97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53add8dd45ee8a0d402f60aa305be6d4aef156d91b815ed78650e45cde07fbd7fffd7a0ac235c06f9f18a0346cf88aa3a75fb94bb26e52f1debf326652d0b567
|
7
|
+
data.tar.gz: 06414c87f84ee31e5f9dbd8ea56f5a92266259ee23a579b6a4b181df976ec3f62ae557858f0cca96a15c8b39e20e26c266d25802491df68501a2076a6ed40296
|
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
/!\ Alpha code will break a lot in the coming week
|
2
|
+
|
3
|
+
|
1
4
|
# motion-assets
|
2
5
|
|
3
6
|
motion-assets allows RubyMotion projects to use ImageMagick to generate all the icons sizes.
|
@@ -23,15 +26,18 @@ Or if you use Bundler:
|
|
23
26
|
gem 'motion-assets'
|
24
27
|
```
|
25
28
|
|
29
|
+
Optional, you can install ImageOption to optimize your images : https://imageoptim.com
|
30
|
+
|
26
31
|
|
27
32
|
## Setup
|
28
33
|
|
29
|
-
In the `Rakefile`, set
|
34
|
+
In the `Rakefile`, set paths for your base images :
|
30
35
|
|
31
36
|
```ruby
|
32
37
|
Motion::Project::App.setup do |app|
|
33
38
|
# ...
|
34
|
-
app.assets.
|
39
|
+
app.assets.source_icon = "./src_images/icon-1024x1024.png"
|
40
|
+
app.assets.source_splash = "./src_images/splash-1024x1024.png"
|
35
41
|
end
|
36
42
|
```
|
37
43
|
|
@@ -56,4 +62,4 @@ $ [bundle exec] rake assets:generate
|
|
56
62
|
```
|
57
63
|
|
58
64
|
|
59
|
-
note : the sample icon comes from the greal
|
65
|
+
note : the sample icon comes from the greal Pixelmator tool, http://www.pixelmator.com/
|
data/lib/motion-assets.rb
CHANGED
@@ -8,12 +8,8 @@ module Motion::Project
|
|
8
8
|
class Config
|
9
9
|
variable :assets
|
10
10
|
|
11
|
-
def assets
|
11
|
+
def assets
|
12
12
|
@assets ||= Motion::Project::Assets.new(self)
|
13
|
-
if block
|
14
|
-
@assets.instance_eval(&block)
|
15
|
-
end
|
16
|
-
@assets
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
@@ -34,48 +30,153 @@ module Motion::Project
|
|
34
30
|
iTunesArtwork@2x.png|1024x1024
|
35
31
|
}
|
36
32
|
|
33
|
+
IOS_SPLASHES = %w{
|
34
|
+
Default~iphone.png|320x480
|
35
|
+
Default@2x~iphone.png|640x960
|
36
|
+
Default-Portrait~ipad.png|768x1024
|
37
|
+
Default-Portrait@2x~ipad.png|1536x2048
|
38
|
+
Default-Landscape~ipad.png|1024x768
|
39
|
+
Default-Landscape@2x~ipad.png|2048x1536
|
40
|
+
Default-568h@2x~iphone.png|640x1136
|
41
|
+
Default-667h.png|750x1334
|
42
|
+
Default-736h.png|1242x2208
|
43
|
+
Default-Landscape-736h.png|2208x1242
|
44
|
+
}
|
45
|
+
|
37
46
|
ANDROID_ICONS = %w{
|
38
|
-
drawable-xxxhdpi/icon.png|
|
39
|
-
drawable-xxhdpi/icon.png|
|
40
|
-
drawable-xhdpi/icon.png|
|
41
|
-
drawable-hdpi/icon.png|
|
42
|
-
drawable-mdpi/icon.png|
|
43
|
-
drawable-ldpi/icon.png|
|
47
|
+
drawable-xxxhdpi/icon.png|192x192
|
48
|
+
drawable-xxhdpi/icon.png|144x144
|
49
|
+
drawable-xhdpi/icon.png|96x96
|
50
|
+
drawable-hdpi/icon.png|72x72
|
51
|
+
drawable-mdpi/icon.png|48x48
|
52
|
+
drawable-ldpi/icon.png|36x36
|
53
|
+
}
|
54
|
+
|
55
|
+
ANDROID_SPLASHES = %w{
|
56
|
+
drawable-hdpi/splash-land.png|800x480
|
57
|
+
drawable-ldpi/splash-land.png|320x200
|
58
|
+
drawable-mdpi/splash-land.png|480x320
|
59
|
+
drawable-xhdpi/splash-land.png|1280x720
|
60
|
+
drawable-hdpi/splash-port.png|480x800
|
61
|
+
drawable-ldpi/splash-port.png|200x320
|
62
|
+
drawable-mdpi/splash-port.png|320x480
|
63
|
+
drawable-xhdpi/splash-port.png|720px1280
|
44
64
|
}
|
45
65
|
|
46
66
|
def initialize(config)
|
47
67
|
@config = config
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
68
|
+
@images = []
|
69
|
+
@icons = Icons.new(config)
|
70
|
+
@image_optim = '/Applications/ImageOptim.app/Contents/MacOS/ImageOptim'
|
71
|
+
|
72
|
+
if ios?
|
73
|
+
@icons << IOS_ICONS
|
74
|
+
@splashes = IOS_SPLASHES
|
75
|
+
end
|
76
|
+
if android?
|
77
|
+
@icons << ANDROID_ICONS
|
78
|
+
@splashes = ANDROID_SPLASHES
|
52
79
|
end
|
53
|
-
@
|
80
|
+
@source_icon = "./src_images/icon.png"
|
81
|
+
@source_splash = "./src_images/splash.png"
|
82
|
+
end
|
83
|
+
|
84
|
+
def source_icon=(source_icon)
|
85
|
+
@source_icon = source_icon
|
54
86
|
end
|
55
87
|
|
56
|
-
def
|
57
|
-
@
|
88
|
+
def source_splash=(source_splash)
|
89
|
+
@source_splash = source_splash
|
58
90
|
end
|
59
91
|
|
60
92
|
def icons
|
61
93
|
@icons
|
62
94
|
end
|
63
95
|
|
96
|
+
def splashes
|
97
|
+
@splashes
|
98
|
+
end
|
99
|
+
|
64
100
|
def generate!
|
65
|
-
|
66
|
-
|
101
|
+
validate_source_icon!
|
102
|
+
validate_source_splash!
|
103
|
+
generate_icons
|
104
|
+
generate_splashes
|
105
|
+
optimize_images
|
106
|
+
end
|
107
|
+
|
108
|
+
protected
|
109
|
+
|
110
|
+
def generate_splashes
|
111
|
+
App.info "[info]", "Generating splashes..."
|
112
|
+
@splashes.each do |splash|
|
113
|
+
parts = splash.split('|')
|
114
|
+
path = File.join(@config.resources_dirs.first, parts[0])
|
115
|
+
FileUtils.mkdir_p(File.dirname(path))
|
116
|
+
generate_image(@source_splash, path, parts[1])
|
117
|
+
@images << path
|
118
|
+
App.info "-", parts[0]
|
67
119
|
end
|
120
|
+
end
|
68
121
|
|
122
|
+
def generate_icons
|
123
|
+
App.info "[info]", "Generating icons..."
|
69
124
|
@icons.each do |icon|
|
70
125
|
parts = icon.split('|')
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
126
|
+
path = File.join(@config.resources_dirs.first, parts[0])
|
127
|
+
FileUtils.mkdir_p(File.dirname(path))
|
128
|
+
generate_image(@source_icon, path, parts[1])
|
129
|
+
@images << path
|
130
|
+
App.info "-", parts[0]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def optimize_images
|
135
|
+
if File.exist?(@image_optim)
|
136
|
+
App.info "[info]", "Optimizing images..."
|
137
|
+
system("#{@image_optim} #{@images.join(' ')}")
|
138
|
+
else
|
139
|
+
App.info "[warning]", "motion-assets uses ImageOptim to optimize your images, please install it : https://imageoptim.com"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def generate_image(source, path, dimensions)
|
144
|
+
image = MiniMagick::Image.open(source)
|
145
|
+
image.resize(dimensions)
|
146
|
+
image.format("png")
|
147
|
+
image.write(path)
|
148
|
+
end
|
149
|
+
|
150
|
+
def validate_source_icon!
|
151
|
+
unless File.exist?(@source_icon)
|
152
|
+
App.fail "You have to provide a valid base icon in your rakefile : app.assets.source_icon = './some/path/image.png"
|
153
|
+
end
|
154
|
+
image = MiniMagick::Image.open(@source_icon)
|
155
|
+
if ios? && image.dimensions != [1024, 1024]
|
156
|
+
App.info "[warning]", "Your source icon image dimensions #{image.dimensions} is different from recommended dimensions : [1024, 1024]"
|
157
|
+
end
|
158
|
+
if android? && image.dimensions != [512, 512]
|
159
|
+
App.info "[warning]", "Your source icon image dimensions #{image.dimensions} is different from recommended dimensions : [512, 512]"
|
77
160
|
end
|
78
161
|
end
|
162
|
+
|
163
|
+
def validate_source_splash!
|
164
|
+
unless File.exist?(@source_splash)
|
165
|
+
App.fail "You have to provide a valid base splash in your rakefile : app.assets.source_splash = './some/path/image.png"
|
166
|
+
end
|
167
|
+
image = MiniMagick::Image.open(@source_splash)
|
168
|
+
if image.dimensions != [2028, 2028]
|
169
|
+
App.info "[warning]", "Your source splash image dimensions #{image.dimensions} is different from recommended dimensions : [2028, 2028]"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def android?
|
174
|
+
Motion::Project::App.template == :android
|
175
|
+
end
|
176
|
+
|
177
|
+
def ios?
|
178
|
+
Motion::Project::App.template == :ios
|
179
|
+
end
|
79
180
|
end
|
80
181
|
end
|
81
182
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Icons
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
def initialize(config)
|
5
|
+
@list = []
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def list
|
10
|
+
@list
|
11
|
+
end
|
12
|
+
|
13
|
+
def <<(*icons)
|
14
|
+
@list << icons
|
15
|
+
@list.flatten!
|
16
|
+
icons.flatten.each do |icon|
|
17
|
+
@config.icons << icon.split('|').first
|
18
|
+
end
|
19
|
+
self
|
20
|
+
end
|
21
|
+
alias_method :push, :<<
|
22
|
+
|
23
|
+
def delete(*icons)
|
24
|
+
@list.delete(icons)
|
25
|
+
@list.flatten!
|
26
|
+
icons.flatten.each do |icon|
|
27
|
+
@config.icons.delete icon.split('|').first
|
28
|
+
end
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def each(&block)
|
33
|
+
@list.each(&block)
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joffrey Jaffeux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_magick
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- lib/motion-assets.rb
|
37
37
|
- lib/motion/project/assets.rb
|
38
|
+
- lib/motion/project/icons.rb
|
38
39
|
- lib/motion/project/version.rb
|
39
40
|
homepage: http://www.rubymotion.com
|
40
41
|
licenses:
|