convert_font 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/convert_font +55 -0
- data/convert_font.gemspec +28 -0
- data/lib/convert_font.rb +6 -0
- data/lib/convert_font/converter.rb +54 -0
- data/lib/convert_font/version.rb +3 -0
- data/spec/convert_font/temp_font_eot.tar.gz +0 -0
- data/spec/convert_font/temp_font_ttf.tar.gz +0 -0
- data/spec/convert_font/temp_font_woff.tar.gz +0 -0
- data/spec/convert_font_spec.rb +50 -0
- data/spec/spec_helper.rb +2 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b07020f87eb69c0099993f2a7de088a330dd96f0
|
4
|
+
data.tar.gz: da6f59e1b2d64e3c3353876e05ddb3555af56fc3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8467f0216e00af536431050b30835515cbc99e9e800697411b16f8ec4db8123896961d983c6528cc80abb4c2393c7c6c725ff198d075730e5627a05c57e78f4
|
7
|
+
data.tar.gz: 725d9155aaf74d7c7a5d59fcc6d9a2beb31d194b70cb2190d4ec24c474e5869c6b65fa3c6bb3710e54c047e0e7bf2d78225e3333ed56fa4aef11b4972b6d074c
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.tar
|
4
|
+
*.otf
|
5
|
+
*.ttf
|
6
|
+
*.woff
|
7
|
+
*.eot
|
8
|
+
.bundle
|
9
|
+
.config
|
10
|
+
.yardoc
|
11
|
+
Gemfile.lock
|
12
|
+
InstalledFiles
|
13
|
+
_yardoc
|
14
|
+
coverage
|
15
|
+
doc/
|
16
|
+
lib/bundler/man
|
17
|
+
pkg
|
18
|
+
rdoc
|
19
|
+
spec/reports
|
20
|
+
test/tmp
|
21
|
+
test/version_tmp
|
22
|
+
tmp
|
23
|
+
spec/convert_font/config_spec.yml
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^convert_font/*.rb$})
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch(%r{^lib/convert_font/(.+)\.rb$})
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
11
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 jonlunsford
|
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,44 @@
|
|
1
|
+
# ConvertFont
|
2
|
+
|
3
|
+
A CLI tool to convert fonts.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install convert_font
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
#### Basic
|
12
|
+
|
13
|
+
convert_font convert -i /home/myproject/my_font_file.ttf -f eot,woff,svg
|
14
|
+
|
15
|
+
Convert the font at `/home/myproject/my_font_file.ttf` to the formats eot, woff, and svg. The converted fonts will be placed in your current working directory.
|
16
|
+
|
17
|
+
#### Advanced
|
18
|
+
|
19
|
+
convert_font convert -i /home/myproject/my_font_file.ttf -f eot,woff,svg -d /home/Downloads/ -c false
|
20
|
+
|
21
|
+
Convert the font at `/home/myproject/my_font_file.ttf` to the formats eot, woff, and svg. The converted fonts will be placed in `/home/Downloads/`. The downloaded .tar.gz files will NOT be cleaned up.
|
22
|
+
|
23
|
+
`convert` tells `convert_font` to.... convert a font (redundant, I know).
|
24
|
+
|
25
|
+
`-i` is the absolute path to your font file, ex. `-i /home/myproject/my_font_file.ttf`.
|
26
|
+
|
27
|
+
`-f` is a comma separated list of formats, ex. `-f eot,woff,svg`.
|
28
|
+
|
29
|
+
`-d` is the destination of the converted fonts, if ommited the current working directory is used, ex. `-d /home/Downloads/`.
|
30
|
+
|
31
|
+
`-c` is a flag to NOT clean up the downloaded .tar.gz files, ex. `-c false`
|
32
|
+
|
33
|
+
## Changelog
|
34
|
+
|
35
|
+
- **Version 0.0.1:** Initial Release
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Write specs, pull requests go much smoother if you have tests written for your new feature.
|
42
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/convert_font
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.join File.dirname(__FILE__), "..", "lib"
|
3
|
+
require "rubygems"
|
4
|
+
require "convert_font"
|
5
|
+
require "optparse"
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
opt_parser = OptionParser.new do |opt|
|
10
|
+
opt.banner = "Usage: convert_font [command] [OPTIONS]"
|
11
|
+
opt.separator ""
|
12
|
+
opt.separator "Commands"
|
13
|
+
opt.separator " convert: convert a font."
|
14
|
+
opt.separator ""
|
15
|
+
opt.separator "Options"
|
16
|
+
|
17
|
+
opt.on("-i", "--input_file FILE", "The absolute path to the font file you would like to convert, ex. /home/users/my_font_file.ttf") do |font_file|
|
18
|
+
options[:font_file] = font_file
|
19
|
+
end
|
20
|
+
|
21
|
+
opt.on("-f", "--formats=format[,...]", "Each file format you would your font converted to separated by a comma, ex. ttf,eot,woff,svg") do |format|
|
22
|
+
input_formats = format.split(",")
|
23
|
+
options[:formats] = input_formats.map { |s| s.to_sym }
|
24
|
+
end
|
25
|
+
|
26
|
+
opt.on("-d", "--destination DESTINATION", "Absolute path to where the converted files will go. If omitted the current directory will be used.") do |destination|
|
27
|
+
options[:destination] = destination
|
28
|
+
end
|
29
|
+
|
30
|
+
opt.on("-c", "--cleanup CLEANUP", "If you DON'T want the downloaded .tar.gz files to be cleaned up, ex. -c false") do |cleanup|
|
31
|
+
options[:cleanup] = cleanup
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
opt_parser.parse!
|
36
|
+
|
37
|
+
if ARGV[0]
|
38
|
+
KEY = "qzinxBQILDuGzIlmz13HK7svAw6z8uu5"
|
39
|
+
END_POINT = "https://ofc.p.mashape.com/directConvert/"
|
40
|
+
|
41
|
+
cleanup = options[:cleanup] ? false : true
|
42
|
+
destination = options[:destination] ? options[:destination] : Dir.pwd
|
43
|
+
|
44
|
+
converter = ConvertFont::Converter.new KEY, END_POINT, cleanup
|
45
|
+
|
46
|
+
if !File.file?(options[:font_file])
|
47
|
+
puts "It appears the path to your font file is incorrect. 'convert_font --help'"
|
48
|
+
elsif options[:formats].nil? || options[:formats].count <= 0
|
49
|
+
puts "Please provide at least one format to convert to. 'convert_font --help'"
|
50
|
+
else
|
51
|
+
converter.convert(options[:font_file], options[:formats], destination)
|
52
|
+
end
|
53
|
+
else
|
54
|
+
puts opt_parser
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'convert_font/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "convert_font"
|
8
|
+
spec.version = ConvertFont::VERSION
|
9
|
+
spec.authors = ["jonlunsford"]
|
10
|
+
spec.email = ["jon@capturethecastle.net"]
|
11
|
+
spec.description = %q{A CLI tool to convert fonts.}
|
12
|
+
spec.summary = %q{This tool takes a font file and converts it to the formats you need.}
|
13
|
+
spec.homepage = "https://github.com/jonlunsford/convert_font"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency "unirest"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard"
|
27
|
+
spec.add_development_dependency "guard-rspec"
|
28
|
+
end
|
data/lib/convert_font.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems/package'
|
2
|
+
require 'zlib'
|
3
|
+
require 'unirest'
|
4
|
+
|
5
|
+
module ConvertFont
|
6
|
+
class Converter
|
7
|
+
|
8
|
+
attr_accessor :api_key, :api_url, :enable_cleanup
|
9
|
+
|
10
|
+
def initialize api_key, api_url, enable_cleanup = true
|
11
|
+
@api_key = api_key
|
12
|
+
@api_url = api_url
|
13
|
+
@enable_cleanup = enable_cleanup
|
14
|
+
|
15
|
+
self.set_default_request_headers
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_default_request_headers
|
19
|
+
Unirest.default_header('X-Mashape-Authorization', @api_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def convert file, types, destination
|
23
|
+
destination << "/" if destination[-1] != "/"
|
24
|
+
types.to_enum.with_index(0).each do |type, i|
|
25
|
+
puts "Now converting: #{type}"
|
26
|
+
response = Unirest.post @api_url, parameters: {"file" => File.new(file, "rb"), "format" => type.to_s}
|
27
|
+
open("#{destination}temp_font_#{type.to_s}.tar.gz", "w") do |temp_file|
|
28
|
+
temp_file.write(response.body)
|
29
|
+
end
|
30
|
+
extract("#{destination}temp_font_#{type.to_s}.tar.gz", destination);
|
31
|
+
puts "#{type} converted."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract file, destination
|
36
|
+
destination << "/" if destination[-1] != "/"
|
37
|
+
tar = Gem::Package::TarReader.new(Zlib::GzipReader.open(file))
|
38
|
+
tar.rewind
|
39
|
+
tar.each do |entry|
|
40
|
+
if entry.file?
|
41
|
+
names = entry.full_name.split("/")
|
42
|
+
unless names.last.include? ".txt"
|
43
|
+
open(destination + names.last, "wb") do |new_file|
|
44
|
+
new_file.write(entry.read)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
tar.close
|
50
|
+
FileUtils.rm_rf file if @enable_cleanup
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConvertFont do
|
4
|
+
context "Dependencies" do
|
5
|
+
it "depends on unirest" do
|
6
|
+
Unirest.should_not be_nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ConvertFont::Converter do
|
12
|
+
# config_spec.yml is excluded from this repo, you must provide your own keys for deveopment purposes.
|
13
|
+
let(:config) { YAML.load_file(File.dirname(__FILE__) + "/convert_font/config_spec.yml") }
|
14
|
+
let(:converter) {converter = ConvertFont::Converter.new config["api_key"], config["api_url"], false}
|
15
|
+
|
16
|
+
it "should accept an api key" do
|
17
|
+
converter.api_key.should eq config["api_key"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should accept an api url" do
|
21
|
+
converter.api_url.should eq config["api_url"]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set an api key as a default header" do
|
25
|
+
converter.set_default_request_headers.should_not be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should extract tar.qz files" do
|
29
|
+
gzip = File.dirname(__FILE__) + "/convert_font/temp_font_ttf.tar.gz"
|
30
|
+
font_file = File.dirname(__FILE__) + "/convert_font/SourceSansPro-Regular.ttf"
|
31
|
+
FileUtils.rm_rf font_file if File.file?(font_file)
|
32
|
+
converter.extract(gzip, File.dirname(__FILE__) + "/convert_font/")
|
33
|
+
expect(File.file?(font_file)).to be true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow destination paths to NOT have a trailing slash" do
|
37
|
+
gzip = File.dirname(__FILE__) + "/convert_font/temp_font_eot.tar.gz"
|
38
|
+
font_file = File.dirname(__FILE__) + "/convert_font/SourceSansPro-Regular.eot"
|
39
|
+
FileUtils.rm_rf font_file if File.file?(font_file)
|
40
|
+
converter.extract(gzip, File.dirname(__FILE__) + "/convert_font")
|
41
|
+
expect(File.file?(font_file)).to be true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should convert a font" do
|
45
|
+
font_file = File.dirname(__FILE__) + "/convert_font/SourceSansPro-Regular.woff"
|
46
|
+
FileUtils.rm_rf font_file if File.file?(font_file)
|
47
|
+
converter.convert(File.dirname(__FILE__) + "/convert_font/SourceSansPro-Regular.otf", [:woff], File.dirname(__FILE__) + "/convert_font/")
|
48
|
+
expect(File.file?(font_file)).to be true
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: convert_font
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jonlunsford
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: unirest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A CLI tool to convert fonts.
|
98
|
+
email:
|
99
|
+
- jon@capturethecastle.net
|
100
|
+
executables:
|
101
|
+
- convert_font
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- Guardfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/convert_font
|
112
|
+
- convert_font.gemspec
|
113
|
+
- lib/convert_font.rb
|
114
|
+
- lib/convert_font/converter.rb
|
115
|
+
- lib/convert_font/version.rb
|
116
|
+
- spec/convert_font/temp_font_eot.tar.gz
|
117
|
+
- spec/convert_font/temp_font_ttf.tar.gz
|
118
|
+
- spec/convert_font/temp_font_woff.tar.gz
|
119
|
+
- spec/convert_font_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: https://github.com/jonlunsford/convert_font
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.1.5
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: This tool takes a font file and converts it to the formats you need.
|
145
|
+
test_files:
|
146
|
+
- spec/convert_font/temp_font_eot.tar.gz
|
147
|
+
- spec/convert_font/temp_font_ttf.tar.gz
|
148
|
+
- spec/convert_font/temp_font_woff.tar.gz
|
149
|
+
- spec/convert_font_spec.rb
|
150
|
+
- spec/spec_helper.rb
|