dens 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/bin/dens +7 -0
- data/dens.gemspec +24 -0
- data/lib/dens.rb +52 -0
- data/lib/dens/cli.rb +17 -0
- data/lib/dens/version.rb +3 -0
- data/spec/cli_spec.rb +18 -0
- data/spec/dens_spec.rb +71 -0
- data/spec/spec_helper.rb +7 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ebd9abd4ec96d79d86b88186eefb143d764b1aa5
|
4
|
+
data.tar.gz: 3b760c98d335b43b7268f18f0fb8fd8220d02bd0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11f50dd887e6a48b86b86c91adaec63c5902cf3108a2f29817b481a3795930e82cdd631a35e27dfec303fbaf3537ff5d19178910426a989a78d8a1f1ab664763
|
7
|
+
data.tar.gz: 2061657c995d161e129bd80f0a4012fd784b25680db23e424c586b5cdbf0884847ec560c05f720dc56abd3b0fc4f8c9be98a6d92dc5de348bcdfd655ae248c06
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Klaas Pieter Annema
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Dens
|
2
|
+
|
3
|
+
Moves different density assets to their respective Android resource directories.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install dens
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
`dens [origin_directory] [resource_directory]`
|
12
|
+
|
13
|
+
Moves any file suffixed with a density into it's respective resource directory. For example
|
14
|
+
`image-hdpi.png` will be moved into `[resource_directory]/drawable-hdpi/image.png`.
|
15
|
+
If the destination directory does not exist the image will be moved into the
|
16
|
+
regular drawable directory.
|
17
|
+
|
18
|
+
Image files must be have the .png extension and the density must be seperated
|
19
|
+
from the image name using '-' as the seperator. These image names work:
|
20
|
+
|
21
|
+
- image.png
|
22
|
+
- image-hdpi.png
|
23
|
+
- image-something.png (will be moved into the drawable directory unless your
|
24
|
+
resource folder contains a drawable-something directory)
|
25
|
+
|
26
|
+
These image names won't work (as expected):
|
27
|
+
|
28
|
+
- image_hdpi.png
|
29
|
+
- image.jpg
|
30
|
+
|
31
|
+
This is a very early implementation. There will be
|
32
|
+
[issues](https://github.com/klaaspieter/dens/issues)!
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( http://github.com/klaaspieter/dens/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/dens
ADDED
data/dens.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dens/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dens"
|
8
|
+
spec.version = Dens::VERSION
|
9
|
+
spec.authors = ["Klaas Pieter Annema"]
|
10
|
+
spec.email = ["klaaspieter@annema.me"]
|
11
|
+
spec.summary = %q{Moves different density assets to their respective Android resource directories}
|
12
|
+
spec.description = %q{Moves different density assets to their respective Android resource directories}
|
13
|
+
spec.homepage = "https://github.com/klaaspieter/dens"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 0"
|
24
|
+
end
|
data/lib/dens.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "dens/version"
|
2
|
+
require "dens/cli"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module Dens
|
6
|
+
|
7
|
+
def self.move(origin, destination)
|
8
|
+
Mover.move(origin, destination)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Mover
|
12
|
+
attr_reader :origin, :destination
|
13
|
+
|
14
|
+
OriginDoesNotExistError = Class.new(RuntimeError)
|
15
|
+
DestinationDoesNotExistError = Class.new(RuntimeError)
|
16
|
+
|
17
|
+
def initialize(origin, destination = Dir.pwd)
|
18
|
+
@origin = origin
|
19
|
+
@destination = destination
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.move(origin, destination)
|
23
|
+
Mover.new(origin, destination).move
|
24
|
+
end
|
25
|
+
|
26
|
+
def move
|
27
|
+
raise OriginDoesNotExistError unless Dir.exists?(origin)
|
28
|
+
raise DestinationDoesNotExistError unless Dir.exists?(destination)
|
29
|
+
|
30
|
+
Dir.glob(File.join(origin, "*.png")).each do |drawable_origin|
|
31
|
+
drawable_extension = File.extname(drawable_origin)
|
32
|
+
drawable_name = File.basename(drawable_origin, drawable_extension)
|
33
|
+
|
34
|
+
partitions = drawable_name.partition("-")
|
35
|
+
density = partitions.last
|
36
|
+
name = partitions.first
|
37
|
+
|
38
|
+
drawable_destination = File.join(destination, "drawable", name)
|
39
|
+
if (!density.empty?)
|
40
|
+
directory = File.join(destination, "drawable-#{density}")
|
41
|
+
if File.exists?(directory)
|
42
|
+
drawable_destination = File.join(directory, name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
drawable_destination += drawable_extension
|
46
|
+
|
47
|
+
puts "#{drawable_origin} => #{drawable_destination}"
|
48
|
+
FileUtils.move(drawable_origin, drawable_destination)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/dens/cli.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Dens::CLI
|
2
|
+
attr_reader :origin, :destination, :mover
|
3
|
+
|
4
|
+
def initialize(options = {})
|
5
|
+
@origin = options.fetch(:origin)
|
6
|
+
@destination = options.fetch(:destination)
|
7
|
+
@mover = options.fetch(:mover, Dens::Mover)
|
8
|
+
end
|
9
|
+
|
10
|
+
def start
|
11
|
+
mover.move(origin, destination)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.start
|
15
|
+
Dens::CLI.new(origin: ARGV[0], destination: ARGV[1]).start
|
16
|
+
end
|
17
|
+
end
|
data/lib/dens/version.rb
ADDED
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dens::CLI do
|
4
|
+
|
5
|
+
it "moves files from the origin to the destination" do
|
6
|
+
mover = double(:mover)
|
7
|
+
origin = "origin"
|
8
|
+
destination = "destination"
|
9
|
+
|
10
|
+
expect(mover).to receive(:move).with(origin, destination)
|
11
|
+
Dens::CLI.new(
|
12
|
+
origin: origin,
|
13
|
+
destination: destination,
|
14
|
+
mover: mover
|
15
|
+
).start
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/dens_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "tmpdir"
|
3
|
+
|
4
|
+
include Dens
|
5
|
+
|
6
|
+
describe Mover do
|
7
|
+
|
8
|
+
it "has an origin" do
|
9
|
+
mover = Mover.new("origin", "destination")
|
10
|
+
expect(mover.origin).to eq "origin"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a destination" do
|
14
|
+
mover = Mover.new("origin", "destination")
|
15
|
+
expect(mover.destination).to eq "destination"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "uses the current working directory as the default destination" do
|
19
|
+
mover = Mover.new("origin")
|
20
|
+
expect(mover.destination).to eq Dir.pwd
|
21
|
+
end
|
22
|
+
|
23
|
+
it "verifies existence of the origin directory" do
|
24
|
+
origin, destination, drawable = create_tmp_dirs
|
25
|
+
expect{Mover.move("does not exist", destination)}.to raise_error(Mover::OriginDoesNotExistError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "verifies existence of the destination directory" do
|
29
|
+
origin, destination, drawable = create_tmp_dirs
|
30
|
+
expect{Mover.move(origin, "does not exist")}.to raise_error(Mover::DestinationDoesNotExistError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "moves files without a suffix into drawable" do
|
34
|
+
origin, destination, drawable = create_tmp_dirs
|
35
|
+
Mover.move(origin, destination)
|
36
|
+
expect(File.exists?(drawable)).to be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "moves files with a suffix into drawable-[suffix]" do
|
40
|
+
origin, destination, drawable = create_tmp_dirs "-density"
|
41
|
+
Mover.move(origin, destination)
|
42
|
+
expect(File.exists?(drawable)).to be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "moves files into drawable if drawable-density doesn't exist" do
|
46
|
+
origin = create_origin("-density")
|
47
|
+
destination, drawable = create_destination
|
48
|
+
Mover.move(origin, destination)
|
49
|
+
expect(File.exists?(drawable)).to be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_tmp_dirs(suffix = "")
|
53
|
+
origin = create_origin(suffix)
|
54
|
+
destination, drawable = create_destination(suffix)
|
55
|
+
[origin, destination, drawable]
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_origin(suffix = "")
|
59
|
+
origin = Dir.mktmpdir
|
60
|
+
FileUtils.touch(File.join(origin, "drawable#{suffix}.png"))
|
61
|
+
origin
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_destination(suffix = "")
|
65
|
+
destination = Dir.mktmpdir
|
66
|
+
drawable_directory = File.join(destination, "drawable#{suffix}")
|
67
|
+
Dir.mkdir(drawable_directory)
|
68
|
+
drawable = File.join(drawable_directory, "drawable.png")
|
69
|
+
[destination, drawable]
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dens
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Klaas Pieter Annema
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Moves different density assets to their respective Android resource directories
|
56
|
+
email:
|
57
|
+
- klaaspieter@annema.me
|
58
|
+
executables:
|
59
|
+
- dens
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/dens
|
69
|
+
- dens.gemspec
|
70
|
+
- lib/dens.rb
|
71
|
+
- lib/dens/cli.rb
|
72
|
+
- lib/dens/version.rb
|
73
|
+
- spec/cli_spec.rb
|
74
|
+
- spec/dens_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/klaaspieter/dens
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Moves different density assets to their respective Android resource directories
|
100
|
+
test_files:
|
101
|
+
- spec/cli_spec.rb
|
102
|
+
- spec/dens_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
has_rdoc:
|