mobile_export 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +9 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/exe/mobile_export +11 -0
- data/lib/mobile_export.rb +10 -0
- data/lib/mobile_export/android.rb +74 -0
- data/lib/mobile_export/version.rb +3 -0
- data/mobile_export.gemspec +21 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f2871c8957e94d2fcecc96aac1a24dc0a52ca12
|
4
|
+
data.tar.gz: 585e3f3c2198162549fc6372584aed4da28163ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c7e61315aa21d7af1b553f465fa382d2619d75289fdcb82dbde564c14a5122326a267a91af275a6d77c60a0f24424bbb622497834bc4df022eca172f430ac2c
|
7
|
+
data.tar.gz: 21f9606524db98f0a563d88682257e9086376a5bf17cf7c0d7bb31cbf8c13ef8da0d1dc51828561161fdf54d932bbcd0180ed0ed98220384f0bc41ab52fe801d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 JuanitoFatas
|
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,46 @@
|
|
1
|
+
# MobileExport
|
2
|
+
|
3
|
+
Organize your images for Android.
|
4
|
+
|
5
|
+
Given:
|
6
|
+
|
7
|
+
```
|
8
|
+
folder/
|
9
|
+
├── base_h.png
|
10
|
+
├── base_hhh.png
|
11
|
+
├── base_m.png
|
12
|
+
├── base_xh.png
|
13
|
+
└── base_xxh.png
|
14
|
+
```
|
15
|
+
|
16
|
+
After `mobile_export`:
|
17
|
+
|
18
|
+
```
|
19
|
+
folder/
|
20
|
+
├── drawable-hdpi
|
21
|
+
│ └── base.png
|
22
|
+
├── drawable-hhhdpi
|
23
|
+
│ └── base.png
|
24
|
+
├── drawable-mdpi
|
25
|
+
│ └── base.png
|
26
|
+
├── drawable-xhdpi
|
27
|
+
│ └── base.png
|
28
|
+
└── drawable-xxhdpi
|
29
|
+
└── base.png
|
30
|
+
```
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
$ gem install mobile_export
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
$ mobile_export
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/JuanitoFatas/mobile_export.
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mobile_export"
|
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
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
data/exe/mobile_export
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Exit cleanly from an early interrupt
|
4
|
+
Signal.trap("INT") { abort }
|
5
|
+
|
6
|
+
require "rubygems"
|
7
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
8
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
9
|
+
|
10
|
+
require "mobile_export"
|
11
|
+
MobileExport::CLI.execute
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module MobileExport
|
5
|
+
class Android
|
6
|
+
def initialize(current_directory = Pathname.getwd)
|
7
|
+
@current_directory = Pathname(current_directory)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
create_directories!
|
12
|
+
move_images!
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :current_directory
|
18
|
+
|
19
|
+
SUFFIX_FOLDER = {
|
20
|
+
"hhh" => "drawable-hhhdpi",
|
21
|
+
"xxh" => "drawable-xxhdpi",
|
22
|
+
"xh" => "drawable-xhdpi",
|
23
|
+
"h" => "drawable-hdpi",
|
24
|
+
"m" => "drawable-mdpi",
|
25
|
+
}
|
26
|
+
|
27
|
+
IMAGE_EXTENSIONS = %w(png jpg jpeg)
|
28
|
+
|
29
|
+
private_constant :SUFFIX_FOLDER
|
30
|
+
private_constant :IMAGE_EXTENSIONS
|
31
|
+
|
32
|
+
def create_directories!
|
33
|
+
SUFFIX_FOLDER.values.each do |directory|
|
34
|
+
path = current_directory.join directory
|
35
|
+
|
36
|
+
FileUtils.mkdir_p(path) if !path.directory?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def image_patterns_for_glob
|
41
|
+
@_image_patterns_for_glob ||= begin
|
42
|
+
current_directory.join("*.{#{IMAGE_EXTENSIONS.join(",".freeze)}}").to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def image_patterns
|
47
|
+
@_image_patterns ||= Regexp.compile(IMAGE_EXTENSIONS.join("|".freeze))
|
48
|
+
end
|
49
|
+
|
50
|
+
def all_image_files
|
51
|
+
@_all_image_files = Dir[image_patterns_for_glob]
|
52
|
+
end
|
53
|
+
|
54
|
+
def move_images!
|
55
|
+
SUFFIX_FOLDER.each do |suffix, folder|
|
56
|
+
destination = current_directory.join(folder)
|
57
|
+
files_with_suffix = all_image_files.select do |file|
|
58
|
+
file =~ /_#{suffix}\.(#{image_patterns})$/
|
59
|
+
end
|
60
|
+
|
61
|
+
files_with_suffix.each do |file|
|
62
|
+
matched = Pathname(file).basename.to_s.match(
|
63
|
+
/(?<filename>.*)_(?<suffix>(#{suffix}))(?<extension>\..*)$/
|
64
|
+
)
|
65
|
+
old_path = file
|
66
|
+
new_path = destination.join(matched[:filename] + matched[:extension]).to_s
|
67
|
+
|
68
|
+
puts "Move #{old_path} to #{new_path}."
|
69
|
+
FileUtils.mv old_path, new_path
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mobile_export/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mobile_export"
|
8
|
+
spec.version = MobileExport::VERSION
|
9
|
+
spec.authors = ["JuanitoFatas"]
|
10
|
+
spec.email = ["katehuang0320@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Organize image files for Mobile platform.}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/JuanitoFatas/mobile_export"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobile_export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JuanitoFatas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Organize image files for Mobile platform.
|
14
|
+
email:
|
15
|
+
- katehuang0320@gmail.com
|
16
|
+
executables:
|
17
|
+
- mobile_export
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".travis.yml"
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- exe/mobile_export
|
31
|
+
- lib/mobile_export.rb
|
32
|
+
- lib/mobile_export/android.rb
|
33
|
+
- lib/mobile_export/version.rb
|
34
|
+
- mobile_export.gemspec
|
35
|
+
homepage: https://github.com/JuanitoFatas/mobile_export
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.6.4
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Organize image files for Mobile platform.
|
59
|
+
test_files: []
|
60
|
+
has_rdoc:
|