xcassets 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aba4781c8d422f88d7431e60e86879dfd6134f4d
4
+ data.tar.gz: 72474205a1ba7e032524b7482756f24b405427e7
5
+ SHA512:
6
+ metadata.gz: 93cf09c33f9c22de3c0f85debf17fb401d85843be5cc169a67e87bdf40a753f15e51a60048b88cf9a916bc19563b0223e81715c6d4a30089dc6419b32469c75c
7
+ data.tar.gz: 340da785986d5f252459045eee98c274e0780b249544334d0edbd6bcca16aa0a77a7cfae7c8f071e634543860a3b933990f0e33d09edc167b54c85ad2732ad6c
data/.gitignore ADDED
@@ -0,0 +1,54 @@
1
+ ### https://raw.github.com/github/gitignore/abad92dac5a4306f72242dae3bca6e277bce3615/Ruby.gitignore
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /spec/examples.txt
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+
15
+ # Used by dotenv library to load environment variables.
16
+ # .env
17
+
18
+ ## Specific to RubyMotion:
19
+ .dat*
20
+ .repl_history
21
+ build/
22
+ *.bridgesupport
23
+ build-iPhoneOS/
24
+ build-iPhoneSimulator/
25
+
26
+ ## Specific to RubyMotion (use of CocoaPods):
27
+ #
28
+ # We recommend against adding the Pods directory to your .gitignore. However
29
+ # you should judge for yourself, the pros and cons are mentioned at:
30
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
31
+ #
32
+ # vendor/Pods/
33
+
34
+ ## Documentation cache and generated files:
35
+ /.yardoc/
36
+ /_yardoc/
37
+ /doc/
38
+ /rdoc/
39
+
40
+ ## Environment normalization:
41
+ /.bundle/
42
+ /vendor/bundle
43
+ /lib/bundler/man/
44
+
45
+ # for a library or gem, you might want to ignore these files since the code is
46
+ # intended to run in multiple environments; otherwise, check them in:
47
+ # Gemfile.lock
48
+ # .ruby-version
49
+ # .ruby-gemset
50
+
51
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
52
+ .rvmrc
53
+
54
+
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xcassets.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xcassets (0.1.0)
5
+ fastimage (~> 1.8.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ ast (2.3.0)
12
+ fastimage (1.8.1)
13
+ addressable (~> 2.3, >= 2.3.5)
14
+ minitest (5.9.1)
15
+ parser (2.3.1.4)
16
+ ast (~> 2.2)
17
+ powerpack (0.1.1)
18
+ rainbow (2.1.0)
19
+ rake (10.5.0)
20
+ rubocop (0.44.1)
21
+ parser (>= 2.3.1.1, < 3.0)
22
+ powerpack (~> 0.1)
23
+ rainbow (>= 1.99.1, < 3.0)
24
+ ruby-progressbar (~> 1.7)
25
+ unicode-display_width (~> 1.0, >= 1.0.1)
26
+ ruby-progressbar (1.8.1)
27
+ unicode-display_width (1.1.1)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.13)
34
+ minitest (~> 5.0)
35
+ rake (~> 10.0)
36
+ rubocop
37
+ xcassets!
38
+
39
+ BUNDLED WITH
40
+ 1.13.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ryosuke Ito <rito.0305@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # XCAssets
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/xcassets`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'xcassets'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install xcassets
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'xcassets/dsl'
27
+
28
+ include XCAssets::DSL
29
+
30
+ assets = xcassets 'Assets' do
31
+ iconset 'LaunchImage' do
32
+ image fixture('40x40.png') => 'Default.png'
33
+ image fixture('40x40.png')
34
+ end
35
+ end
36
+
37
+ assets.save(Dir.pwd)
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/xcassets.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'test'
7
+ t.libs << 'lib'
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ RuboCop::RakeTask.new
12
+
13
+ task default: [:test, :rubocop]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'xcassets'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/xcassets.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'xcassets/xcassets'
2
+ require 'xcassets/iconset'
3
+ require 'xcassets/image'
4
+ require 'xcassets/version'
@@ -0,0 +1,30 @@
1
+ require 'xcassets'
2
+
3
+ module XCAssets
4
+ module DSL
5
+ def xcassets(name, **options, &block)
6
+ @assets = ::XCAssets::XCAssets.new(name, **options)
7
+ instance_eval(&block)
8
+ @assets
9
+ end
10
+
11
+ def iconset(name, **options, &block)
12
+ @iconset = ::XCAssets::Iconset.new(name, **options)
13
+ @assets.add(@iconset) if @assets
14
+ instance_eval(&block)
15
+ @iconset
16
+ end
17
+
18
+ def image(source, **options)
19
+ source, options[:filename] = source.first if source.is_a?(Hash)
20
+ image = ::XCAssets::Image.new(source, **options)
21
+ @iconset.add(image)
22
+ image
23
+ end
24
+
25
+ def images(*filenames)
26
+ filenames.flat_map { |filename| Dir.glob(filename) }
27
+ .each { |filename| image(filename) }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+
3
+ module XCAssets
4
+ class Iconset
5
+ attr_reader :name, :author, :version, :images
6
+
7
+ def initialize(name, author: 'xcassets', version: 1)
8
+ @name = name
9
+ @images = []
10
+ @author = author
11
+ @version = version
12
+ end
13
+
14
+ def info
15
+ { author: @author, version: @version }
16
+ end
17
+
18
+ def contents
19
+ @images.each_with_object(info: info, images: []) do |image, hash|
20
+ hash[:images] << image.contents
21
+ end
22
+ end
23
+
24
+ def add(image)
25
+ @images << image
26
+ end
27
+
28
+ def save(parent_path)
29
+ path = File.join(parent_path, "#{name}.iconset")
30
+ Dir.mkdir(path)
31
+ @images.each do |image|
32
+ image.save(path)
33
+ end
34
+ json_path = File.join(path, 'Contents.json')
35
+ File.open(json_path, 'w') do |file|
36
+ JSON.dump(contents, file)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,50 @@
1
+ require 'fileutils'
2
+ require 'fastimage'
3
+
4
+ module XCAssets
5
+ class Image
6
+ attr_reader :source, :filename, :size, :idiom, :scale
7
+
8
+ def initialize(source, filename: nil, size: nil, idiom: nil, scale: nil)
9
+ unless File.readable?(source)
10
+ raise IOError, "#{File.absolute_path(source)} is not readable."
11
+ end
12
+ @source = source
13
+ @filename = filename || File.basename(source)
14
+ @size = size || FastImage.size(source).join('x')
15
+ @idiom = (idiom || guess_idiom).to_sym
16
+ @scale = (scale || guess_scale).to_i
17
+ end
18
+
19
+ def contents
20
+ {
21
+ filename: @filename,
22
+ size: @size,
23
+ idiom: @idiom.to_s,
24
+ scale: "#{@scale}x"
25
+ }
26
+ end
27
+
28
+ def save(parent_path)
29
+ new_path = File.join(parent_path, filename)
30
+ FileUtils.copy(@source, new_path)
31
+ end
32
+
33
+ private
34
+
35
+ def guess_idiom
36
+ if @filename.include?('~iphone') then :iphone
37
+ elsif @filename.include?('~ipad') then :ipad
38
+ else :universal
39
+ end
40
+ end
41
+
42
+ def guess_scale
43
+ basename = File.basename(@filename, '.*')
44
+ if basename.end_with?('@2x') then 2
45
+ elsif basename.end_with?('@3x') then 3
46
+ else 1
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module XCAssets
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module XCAssets
4
+ class XCAssets
5
+ attr_reader :name, :author, :version, :iconsets
6
+
7
+ def initialize(name, author: 'xcassets', version: 1)
8
+ @name = name
9
+ @author = author
10
+ @version = version
11
+ @iconsets = []
12
+ end
13
+
14
+ def info
15
+ { author: @author, version: @version }
16
+ end
17
+
18
+ def contents
19
+ { info: info }
20
+ end
21
+
22
+ def add(iconset)
23
+ @iconsets << iconset
24
+ end
25
+
26
+ def save(parent_path)
27
+ path = File.join(parent_path, "#{name}.xcassets")
28
+ Dir.mkdir(path)
29
+ @iconsets.each do |iconset|
30
+ iconset.save(path)
31
+ end
32
+ json_path = File.join(path, 'Contents.json')
33
+ File.open(json_path, 'w') do |file|
34
+ JSON.dump(contents, file)
35
+ end
36
+ end
37
+ end
38
+ end
data/xcassets.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xcassets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'xcassets'
8
+ spec.version = XCAssets::VERSION
9
+ spec.authors = ['Ryosuke Ito']
10
+ spec.email = ['rito.0305@gmail.com']
11
+
12
+ spec.summary = 'Generates *.xcassets'
13
+ spec.description = 'Generates *.xcassets'
14
+ spec.homepage = 'https://github.com/manicmaniac/xcassets'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'fastimage', '~> 1.8.1'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.13'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'minitest', '~> 5.0'
30
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcassets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryosuke Ito
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fastimage
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
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
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Generates *.xcassets
84
+ email:
85
+ - rito.0305@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/xcassets.rb
100
+ - lib/xcassets/dsl.rb
101
+ - lib/xcassets/iconset.rb
102
+ - lib/xcassets/image.rb
103
+ - lib/xcassets/version.rb
104
+ - lib/xcassets/xcassets.rb
105
+ - xcassets.gemspec
106
+ homepage: https://github.com/manicmaniac/xcassets
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Generates *.xcassets
130
+ test_files: []