resper 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b590233c5ec183b09a8453a6ab29a6cc01c61af4
4
+ data.tar.gz: 0da82a71178e90bc81537dd603336370d056776a
5
+ SHA512:
6
+ metadata.gz: 3116dbdeb6216c2443b2f0606f13dc4d2f5740056a12f6346b172bf93e4928ed0641e627e8c07d5ee467032b247cfe6e470ab51903dfed6ee2e46a48d2dc162e
7
+ data.tar.gz: 5a04b18868162c237a7badf64092ccdfc05992352b8bcff7b74f0d469edc0a3dc8724413c766d98a383b4af567c7ec7efd8c2baa8e71f3ec9ce3a08d0b97e9af
@@ -0,0 +1,3 @@
1
+ === 0.1.0 / 2017-03-17
2
+
3
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in resper.gemspec
4
+ gemspec
@@ -0,0 +1,9 @@
1
+ Gemfile
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.md
5
+ Rakefile
6
+ bin/resper
7
+ lib/string.rb
8
+ lib/resper.rb
9
+ rake/gem.rake
@@ -0,0 +1,60 @@
1
+ # Resper
2
+
3
+ home :: https://src.sibext.com/snacks/resper
4
+
5
+ ## Description
6
+
7
+ There is tool for extracting vector graphic resources to Android and iOS app
8
+
9
+
10
+ ## First Start
11
+
12
+ ```
13
+ brew remove imagemagick
14
+ brew install imagemagick --with-librsvg
15
+ brew install pngquant
16
+ gem install resper
17
+ ```
18
+
19
+ # Usage
20
+
21
+ ```
22
+ resper -f example/icon.svg -s 20
23
+ ```
24
+
25
+ or
26
+
27
+ ```
28
+ resper -f example/icon.svg -w 20 -h 20
29
+ ```
30
+
31
+ More info:
32
+
33
+ ```
34
+ resper -i
35
+ ```
36
+
37
+ ## License
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2017 Sibext Ltd.
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # -*- ruby -*-
2
+ # Load rakefile extensions (tasks)
3
+ Dir['rake/*.rake'].sort.each { |f| load f }
4
+
5
+ # vim: syntax=ruby
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'ostruct'
5
+ require 'fileutils'
6
+
7
+ options = OpenStruct.new
8
+
9
+ options.base_size = 20
10
+ options.input_file = 'example/icon.svg'
11
+ options.output_android = 'res'
12
+ options.output_ios = 'Images.xcassets'
13
+ options.format = 'svg'
14
+
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Usage: resper [options]"
17
+
18
+ opts.on("-sBASE_SIZE", "--base-size=BASE_SIZE", "Base size for mdpi, default: 20") do |opt|
19
+ options.base_size = opt.to_i
20
+ end
21
+ opts.on("-wBASE_WIDTH", "--base-width=BASE_WIDTH", "Base width for mdpi, base size will be ignored") do |opt|
22
+ options.base_width = opt.to_i
23
+ end
24
+ opts.on("-hBASE_HEIGHT", "--base-height=BASE_HEIGHT", "Base height for mdpi, base size will be ignored") do |opt|
25
+ options.base_height = opt.to_i
26
+ end
27
+ opts.on("-fINPUT_FILE", "--input-file=INPUT_FILE", "Input file with vector graphic resource") do |opt|
28
+ options.input_file = opt
29
+ end
30
+ opts.on("-tFORMAT", "--type=FORMAT", "Vector graphic resource format") do |opt|
31
+ options.format = opt
32
+ end
33
+ opts.on("-aOUTPUT_ANDROID", "--output-android=OUTPUT_ANDROID", "Output Android folder, default: res") do |opt|
34
+ options.output_android = opt
35
+ end
36
+ opts.on("-aOUTPUT_IOS", "--output-ios=OUTPUT_IOS", "Output iOS folder, default: Images.xcassets") do |opt|
37
+ options.output_ios = opt
38
+ end
39
+ opts.on("-i", "--help", "Prints this help") do
40
+ puts opts
41
+ exit
42
+ end
43
+ end.parse!
44
+
45
+ require 'resper'
46
+
47
+ options.base_width = options.base_size if options.base_width.nil?
48
+ options.base_height = options.base_size if options.base_height.nil?
49
+
50
+ res = Resper::Parser.new options.input_file, options.base_width, options.base_height, [options.output_android, options.output_ios], options.format
51
+
52
+ res.parse_resources!
@@ -0,0 +1,121 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Created on 2017-03-17
4
+
5
+ @author: Nikolay Moskvin <moskvin@sibext.com>
6
+
7
+ =end
8
+
9
+ module Resper
10
+
11
+ VERSION = '0.1.1'
12
+
13
+ require 'json'
14
+ require 'string'
15
+
16
+ class Parser
17
+
18
+ @@ANDROID_SCALES = [
19
+ {s: 1.0, d: 160, o: 'mdpi'},
20
+ {s: 1.5, d: 240, o: 'hdpi'},
21
+ {s: 2.0, d: 320, o: 'xhdpi'},
22
+ {s: 3.0, d: 480, o: 'xxhdpi'},
23
+ {s: 4.0, d: 640, o: 'xxxhdpi'},
24
+ ]
25
+
26
+ @@IOS_UNIVERSAL_SCALES = [
27
+ {s: 1.0, d: 160, o: ''},
28
+ {s: 2.0, d: 320, o: '@2x'},
29
+ {s: 3.0, d: 480, o: '@3x'},
30
+ ]
31
+
32
+ def initialize input, width, height, output, format
33
+ @input = input
34
+ @width = width
35
+ @height = height
36
+ @output = output
37
+ @format = format
38
+ end
39
+
40
+ def parse_resources!
41
+ @@ANDROID_SCALES.each do |scale|
42
+ file = for_android w: scale[:s]*@width, h: scale[:s]*@height,
43
+ d: scale[:d], o: "drawable-#{scale[:o]}"
44
+ reduce_size file
45
+ end
46
+
47
+ @@IOS_UNIVERSAL_SCALES.each do |scale|
48
+ file = for_ios scale[:s], scale[:o], scale[:d]
49
+ reduce_size file
50
+ end
51
+ generate_universal_contents
52
+
53
+ end
54
+
55
+ private
56
+
57
+ def for_android w:, h:, d:, o:
58
+ out = File.join(android_output_path, o)
59
+ convert width: w, height: h, density: d, to: out, name: android_image_name
60
+ end
61
+
62
+ def for_ios factor, postfix, density
63
+ convert width: @width*factor, height: @height*factor,
64
+ density: density, to: ios_output_path, name: ios_image_name(postfix)
65
+ end
66
+
67
+ def generate_universal_contents
68
+ images = @@IOS_UNIVERSAL_SCALES.map do |scale|
69
+ {
70
+ idiom: 'universal',
71
+ filename: ios_image_name(scale[:o]),
72
+ scale: "#{scale[:s].to_i}x"
73
+ }
74
+ end
75
+ meta = {
76
+ images: images,
77
+ info: {
78
+ version: 1,
79
+ author: 'xcode'
80
+ }
81
+ }
82
+ File.open(File.join(ios_output_path, 'Contents.json'),'w') do |f|
83
+ f.write(JSON.pretty_generate(meta))
84
+ end
85
+ end
86
+
87
+ def convert width:, height:, density:, to:, name:
88
+ file_output = File.join(to, "#{name}")
89
+ FileUtils.mkdir_p to
90
+ `convert -resize '#{width}x#{height}' -density #{density} -verbose -background none #{@format}:#{@input} #{file_output}`
91
+ file_output
92
+ end
93
+
94
+ def reduce_size png_path
95
+ system('pngquant', "#{png_path}", '--ext=.png', '--force')
96
+ end
97
+
98
+ def ios_output_path
99
+ File.join(@output[1], "#{ios_image_name_without_ext}.imageset")
100
+ end
101
+
102
+ def ios_image_name postfix
103
+ "#{ios_image_name_without_ext}#{postfix}.png"
104
+ end
105
+
106
+ def ios_image_name_without_ext
107
+ File.basename(@input, ".*").split('_').map{|e| e.capitalize}.join
108
+ end
109
+
110
+ def android_output_path
111
+ @output[0]
112
+ end
113
+
114
+ def android_image_name
115
+ name = File.basename(@input, ".*")
116
+ "#{name.underscore}.png"
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Created on 2017-03-17
4
+
5
+ @author: Nikolay Moskvin <moskvin@sibext.com>
6
+
7
+ =end
8
+
9
+ class String
10
+ def underscore
11
+ self.gsub(/::/, '/').
12
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
13
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
14
+ tr("-", "_").
15
+ downcase
16
+ end
17
+ end
18
+
19
+
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'hoe'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'hoe'
6
+ end
7
+
8
+ Hoe.plugin :debugging, :doofus, :git, :bundler, :deps
9
+ #, :minitest
10
+
11
+ HOE = Hoe.spec "resper" do
12
+ developer("Nikolay Moskvin", "moskvin@sibext.com")
13
+ self.history_file = "CHANGELOG.rdoc"
14
+ self.readme_file = "README.md"
15
+ license "MIT"
16
+ require_ruby_version ">= 2.1.5"
17
+ require_rubygems_version ">= 1.3.5"
18
+
19
+ extra_dev_deps << ['rake-compiler', "~> 0.9.3"]
20
+ extra_dev_deps << ["mini_portile", "~> 0.6.1"]
21
+ extra_dev_deps << ["minitest", "~> 5.0"]
22
+ extra_dev_deps << ["hoe-bundler", "~> 1.0"]
23
+ end
24
+
25
+ Hoe.add_include_dirs '.'
26
+
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Moskvin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_portile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe-bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hoe
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.16'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.16'
97
+ description: There is tool for extracting vector graphic resources to Android and
98
+ iOS app
99
+ email:
100
+ - moskvin@sibext.com
101
+ executables:
102
+ - resper
103
+ extensions: []
104
+ extra_rdoc_files:
105
+ - CHANGELOG.rdoc
106
+ - Manifest.txt
107
+ - README.md
108
+ files:
109
+ - CHANGELOG.rdoc
110
+ - Gemfile
111
+ - Manifest.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/resper
115
+ - lib/resper.rb
116
+ - lib/string.rb
117
+ - rake/gem.rake
118
+ homepage: https://src.sibext.com/snacks/resper
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options:
124
+ - "--main"
125
+ - README.md
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.1.5
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 1.3.5
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.10
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: There is tool for extracting vector graphic resources to Android and iOS
144
+ app
145
+ test_files: []