fontist 1.4.0 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02323a2a83176e79be999c101277ab2d777986b07185ca8d18bbd47c0bae88ec
4
- data.tar.gz: c5909e4220f762be25a22fe776f4273ef2affa44b68c3f16d6d181b83cfcf287
3
+ metadata.gz: e024a76941056e06491654749b2a467dd1df4212752a3a98e8a9ee58755af281
4
+ data.tar.gz: d7caaade9c91008f4e0b91b157847d2de4dd26203d88c3558583549fec3bdb5a
5
5
  SHA512:
6
- metadata.gz: 831d21fc0882000bf30003193d8b4bacf8bbe002c8d07bebb1b36ab05cf552cbd844f0ddd0998beb59bc059e54ed365f92e79020c673130a90b61d3db515a2d7
7
- data.tar.gz: 88f6a870cda4177824d9c5499250e5a45a088afc269e185a942c71bd02ea4589539473e72445a13c38265e7de091a6ca95ffcbde37c4bed08c87c251a02f4cb8
6
+ metadata.gz: 8d68a69167a89f6aa143f972da95f5bb06d2831e7e243d6c3ef338d47cc924b5b59c9f0404fad95dbd09b5ed870a555fae6a22e043a7a2eaa564b89036ddebfc
7
+ data.tar.gz: 3497ef80333b61a6a3df80f2493b3442779de017965cffbcffa13fbeb11a056de4f4741121100c8c7b34bd118e8af1aa1deaccad92423d8b68aa4b3b33c05c5a
data/README.md CHANGED
@@ -132,6 +132,182 @@ The return values are ` OpenStruct` object, so you can easily do any other
132
132
  operation you would do in any ruby object.
133
133
 
134
134
 
135
+ ### Manifest
136
+
137
+ #### Locations
138
+
139
+ Fontist lets find font locations from a YAML manifest of the following format:
140
+
141
+ ```yml
142
+ Segoe UI:
143
+ - Regular
144
+ - Bold
145
+ Roboto Mono:
146
+ - Regular
147
+ ```
148
+
149
+ Calling the following code returns a nested hash with font paths.
150
+
151
+ ```ruby
152
+ Fontist::Manifest::Locations.call(manifest_path)
153
+ ```
154
+
155
+ ```ruby
156
+ {"Segoe UI"=>
157
+ {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
158
+ "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
159
+ "Roboto Mono"=>
160
+ {"Regular"=>[]}}
161
+ ```
162
+
163
+ #### Install
164
+
165
+ Fontist lets not only to get font locations but also to install fonts from the
166
+ manifest:
167
+
168
+ ```ruby
169
+ Fontist::Manifest::Install.call(manifest, confirmation: "yes")
170
+ ```
171
+
172
+ It will install fonts and return their locations:
173
+
174
+ ```ruby
175
+ {"Segoe UI"=>
176
+ {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
177
+ "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
178
+ "Roboto Mono"=>
179
+ {"Regular"=>["/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"]}}
180
+ ```
181
+
182
+ ### CLI
183
+
184
+ These commands makes possible to operate with fonts via command line. The CLI
185
+ properly supports exit status, so in a case of error it returns a status code
186
+ higher or equal than 1.
187
+
188
+ All searches are case-insensitive for ease of use.
189
+
190
+ #### Install
191
+
192
+ The `install` command is similar to the `Font.install` call. It first checks
193
+ whether this font is already installed, and if not, then installs the font and
194
+ returns its paths. Font or formula could be specified as a name.
195
+
196
+ ```
197
+ $ fontist install "segoe ui"
198
+ These fonts are found or installed:
199
+ /Users/user/.fontist/fonts/SEGOEUI.TTF
200
+ /Users/user/.fontist/fonts/SEGOEUIB.TTF
201
+ /Users/user/.fontist/fonts/SEGOEUII.TTF
202
+ /Users/user/.fontist/fonts/SEGOEUIZ.TTF
203
+ ```
204
+
205
+ #### Uninstall
206
+
207
+ Uninstalls any font supported by Fontist. Returns paths of an uninstalled font,
208
+ or prints an error telling that the font isn't installed or could not be found
209
+ in Fontist formulas. Aliased as `remove`.
210
+
211
+ ```
212
+ $ fontist uninstall "segoe ui"
213
+ These fonts are removed:
214
+ /Users/user/.fontist/fonts/SEGOEUII.TTF
215
+ /Users/user/.fontist/fonts/SEGOEUIZ.TTF
216
+ /Users/user/.fontist/fonts/SEGOEUIB.TTF
217
+ /Users/user/.fontist/fonts/SEGOEUI.TTF
218
+ ```
219
+
220
+ #### Status
221
+
222
+ Prints installed font paths grouped by formula and font.
223
+
224
+ ```
225
+ $ fontist status "segoe ui"
226
+ Fontist::Formulas::SegoeUIFont
227
+ Segoe UI
228
+ Regular (/Users/user/.fontist/fonts/SEGOEUI.TTF)
229
+ Bold (/Users/user/.fontist/fonts/SEGOEUIB.TTF)
230
+ Italic (/Users/user/.fontist/fonts/SEGOEUII.TTF)
231
+ Bold Italic (/Users/user/.fontist/fonts/SEGOEUIZ.TTF)
232
+ ```
233
+
234
+ #### List
235
+
236
+ Lists installation status of fonts supported by Fontist.
237
+
238
+ ```
239
+ $ fontist list "segoe ui"
240
+ Fontist::Formulas::SegoeUIFont
241
+ Segoe UI
242
+ Regular (installed)
243
+ Bold (installed)
244
+ Italic (installed)
245
+ Bold Italic (installed)
246
+ ```
247
+
248
+ ```
249
+ $ fontist list "roboto mono"
250
+ Fontist::Formulas::RobotoMonoFont
251
+ Roboto Mono
252
+ Regular (uninstalled)
253
+ Italic (uninstalled)
254
+ ```
255
+
256
+ #### Locations from manifest
257
+
258
+ Returns locations of fonts specified in a YAML file as an input.
259
+
260
+ For example, if there is a file `manifest.yml`:
261
+
262
+ ```yml
263
+ Segoe UI:
264
+ - Regular
265
+ - Bold
266
+ Roboto Mono:
267
+ - Regular
268
+ ```
269
+
270
+ Then the command will return the following YAML output:
271
+
272
+ ```yml
273
+ $ fontist manifest-locations manifest.yml
274
+ ---
275
+ Segoe UI:
276
+ Regular:
277
+ - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
278
+ Bold:
279
+ - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
280
+ Roboto Mono:
281
+ Regular: []
282
+ ```
283
+
284
+ Since Segoe UI is installed, but Roboto Mono is not.
285
+
286
+ #### Install from manifest
287
+
288
+ Install fonts from a YAML manifest:
289
+
290
+ ```yml
291
+ $ fontist manifest-install --confirm-license manifest.yml
292
+ ---
293
+ Segoe UI:
294
+ Regular:
295
+ - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
296
+ Bold:
297
+ - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
298
+ Roboto Mono:
299
+ Regular:
300
+ - "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"
301
+ ```
302
+
303
+ #### Help
304
+
305
+ List of all commands could be seen by:
306
+
307
+ ```
308
+ fontist help
309
+ ```
310
+
135
311
  ## Development
136
312
 
137
313
  We are following Sandi Metz's Rules for this gem, you can read the
@@ -197,12 +373,6 @@ git commit -m "Google Fonts update"
197
373
  git push
198
374
  ```
199
375
 
200
- ### TTC extraction
201
-
202
- The stripttc script is used for extraction of TTC files. It's taken from the
203
- https://github.com/DavidBarts/getfonts repository, and placed in the bin/
204
- directory.
205
-
206
376
  ## Contributing
207
377
 
208
378
  First, thank you for contributing! We love pull requests from everyone. By
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
3
  require "fontist"
5
4
  require "fontist/cli"
6
5
 
7
6
  status_code = Fontist::CLI.start(ARGV)
8
- exit status_code.is_a?(Integer) ? status_code : 0
7
+ exit status_code.is_a?(Integer) ? status_code : 1
@@ -34,7 +34,9 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "ruby-ole", "~> 1.0"
35
35
  spec.add_runtime_dependency "thor", "~> 1.0.1"
36
36
  spec.add_runtime_dependency "git", "~> 1.0"
37
+ spec.add_runtime_dependency "ttfunk", "~> 1.0"
37
38
 
39
+ spec.add_development_dependency "extract_ttc", "~> 0.1"
38
40
  spec.add_development_dependency "pry"
39
41
  spec.add_development_dependency "bundler", "~> 2.0"
40
42
  spec.add_development_dependency "rake", "~> 12.3.3"
@@ -13,6 +13,7 @@ require "fontist/formulas"
13
13
  require "fontist/formula"
14
14
  require "fontist/system_font"
15
15
  require "fontist/fontist_font"
16
+ require "fontist/manifest"
16
17
 
17
18
  module Fontist
18
19
  def self.ui
@@ -54,4 +55,8 @@ module Fontist
54
55
  def self.system_file_path
55
56
  Fontist.lib_path.join("fontist", "system.yml")
56
57
  end
58
+
59
+ def self.system_index_path
60
+ Fontist.fontist_path.join("system_index.yml")
61
+ end
57
62
  end
@@ -5,15 +5,23 @@ module Fontist
5
5
  STATUS_SUCCESS = 0
6
6
  STATUS_ERROR = 1
7
7
 
8
+ def self.exit_on_failure?
9
+ false
10
+ end
11
+
8
12
  desc "install FONT", "Install font by font or formula"
13
+ option :force, type: :boolean, aliases: :f,
14
+ desc: "Install even if it's already installed in system"
15
+ option :confirm_license, type: :boolean, desc: "Confirm license agreement"
9
16
  def install(font)
10
- fonts_paths = Fontist::Font.install(font)
11
- Fontist.ui.success("These fonts are found or installed:")
12
- Fontist.ui.success(fonts_paths.join("\n"))
17
+ Fontist::Font.install(
18
+ font,
19
+ force: options[:force],
20
+ confirmation: options[:confirm_license] ? "yes" : "no"
21
+ )
13
22
  STATUS_SUCCESS
14
23
  rescue Fontist::Errors::NonSupportedFontError
15
- Fontist.ui.error("Could not find font '#{font}'.")
16
- STATUS_ERROR
24
+ could_not_find_font(font)
17
25
  end
18
26
 
19
27
  desc "uninstall/remove FONT", "Uninstall font by font or formula"
@@ -26,8 +34,7 @@ module Fontist
26
34
  Fontist.ui.error(e.message)
27
35
  STATUS_ERROR
28
36
  rescue Fontist::Errors::NonSupportedFontError
29
- Fontist.ui.error("Could not find font '#{font}'.")
30
- STATUS_ERROR
37
+ could_not_find_font(font)
31
38
  end
32
39
  map remove: :uninstall
33
40
 
@@ -41,7 +48,7 @@ module Fontist
41
48
  rescue Fontist::Errors::MissingFontError => e
42
49
  error(e.message)
43
50
  rescue Fontist::Errors::NonSupportedFontError
44
- error("Could not find font '#{font}'.")
51
+ could_not_find_font(font)
45
52
  end
46
53
 
47
54
  desc "list [FONT]", "List installation status of FONT or fonts in fontist"
@@ -50,7 +57,7 @@ module Fontist
50
57
  print_list(formulas)
51
58
  success
52
59
  rescue Fontist::Errors::NonSupportedFontError
53
- error("Could not find font '#{font}'.")
60
+ could_not_find_font(font)
54
61
  end
55
62
 
56
63
  desc "update", "Update formulas"
@@ -60,9 +67,39 @@ module Fontist
60
67
  STATUS_SUCCESS
61
68
  end
62
69
 
70
+ desc "manifest-locations MANIFEST",
71
+ "Get locations of fonts from MANIFEST (yaml)"
72
+ def manifest_locations(manifest)
73
+ paths = Fontist::Manifest::Locations.call(manifest)
74
+ print_yaml(paths)
75
+ success
76
+ rescue Fontist::Errors::ManifestCouldNotBeFoundError
77
+ error("Manifest could not be found.")
78
+ rescue Fontist::Errors::ManifestCouldNotBeReadError
79
+ error("Manifest could not be read.")
80
+ end
81
+
82
+ desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
83
+ option :confirm_license, type: :boolean, desc: "Confirm license agreement"
84
+ def manifest_install(manifest)
85
+ paths = Fontist::Manifest::Install.call(
86
+ manifest,
87
+ confirmation: options[:confirm_license] ? "yes" : "no"
88
+ )
89
+
90
+ print_yaml(paths)
91
+ success
92
+ rescue Fontist::Errors::ManifestCouldNotBeFoundError
93
+ error("Manifest could not be found.")
94
+ rescue Fontist::Errors::ManifestCouldNotBeReadError
95
+ error("Manifest could not be read.")
96
+ end
97
+
63
98
  desc "create-formula URL", "Create a new formula with fonts from URL"
64
99
  option :name, desc: "Example: Times New Roman"
65
100
  option :mirror, repeatable: true
101
+ option :subarchive, desc: "Subarchive to choose when there are several ones"
102
+ option :subdir, desc: "Subdirectory to take fonts from"
66
103
  def create_formula(url)
67
104
  require "fontist/import/create_formula"
68
105
  name = Fontist::Import::CreateFormula.new(url, options).call
@@ -76,11 +113,24 @@ module Fontist
76
113
  STATUS_SUCCESS
77
114
  end
78
115
 
116
+ def could_not_find_font(font)
117
+ error("Font '#{font}' not found locally nor available in the Fontist " \
118
+ "formula repository.\n" \
119
+ "Perhaps it is available at the latest Fontist formula " \
120
+ "repository.\n" \
121
+ "You can update the formula repository using the command " \
122
+ "`fontist update` and try again.")
123
+ end
124
+
79
125
  def error(message)
80
126
  Fontist.ui.error(message)
81
127
  STATUS_ERROR
82
128
  end
83
129
 
130
+ def print_yaml(object)
131
+ Fontist.ui.say(YAML.dump(object))
132
+ end
133
+
84
134
  def print_formulas(formulas)
85
135
  formulas.each do |formula, fonts|
86
136
  Fontist.ui.success(formula.installer)
@@ -7,7 +7,10 @@ module Fontist
7
7
  class InvalidResourceError < StandardError; end
8
8
  class TimeoutError < StandardError; end
9
9
  class MissingAttributeError < StandardError; end
10
+ class UnknownFontTypeError < StandardError; end
10
11
  class FontNotFoundError < StandardError; end
11
12
  class BinaryCallError < StandardError; end
13
+ class ManifestCouldNotBeReadError < StandardError; end
14
+ class ManifestCouldNotBeFoundError < StandardError; end
12
15
  end
13
16
  end
@@ -3,6 +3,7 @@ module Fontist
3
3
  def initialize(options = {})
4
4
  @name = options.fetch(:name, nil)
5
5
  @confirmation = options.fetch(:confirmation, "no")
6
+ @force = options.fetch(:force, false)
6
7
 
7
8
  check_or_create_fontist_path!
8
9
  end
@@ -15,8 +16,12 @@ module Fontist
15
16
  new(name: name).find
16
17
  end
17
18
 
18
- def self.install(name, confirmation: "no")
19
- new(name: name, confirmation: confirmation).install
19
+ def self.install(name, confirmation: "no", force: false)
20
+ new(name: name, confirmation: confirmation, force: force).install
21
+ end
22
+
23
+ def self.try_install(name, confirmation: "no")
24
+ new(name: name, confirmation: confirmation).try_install
20
25
  end
21
26
 
22
27
  def self.uninstall(name)
@@ -38,11 +43,15 @@ module Fontist
38
43
  end
39
44
 
40
45
  def install
41
- find_system_font || download_font || raise(
46
+ (find_system_font unless @force) || download_font || raise(
42
47
  Fontist::Errors::NonSupportedFontError
43
48
  )
44
49
  end
45
50
 
51
+ def try_install
52
+ download_font
53
+ end
54
+
46
55
  def uninstall
47
56
  uninstall_font || downloadable_font || raise(
48
57
  Fontist::Errors::NonSupportedFontError
@@ -72,7 +81,16 @@ module Fontist
72
81
  attr_reader :name, :confirmation
73
82
 
74
83
  def find_system_font
75
- Fontist::SystemFont.find(name)
84
+ paths = Fontist::SystemFont.find(name)
85
+ unless paths
86
+ Fontist.ui.say(%(Font "#{name}" not found locally.))
87
+ return
88
+ end
89
+
90
+ Fontist.ui.say("Fonts found at:")
91
+ paths.each do |path|
92
+ Fontist.ui.say("- #{path}")
93
+ end
76
94
  end
77
95
 
78
96
  def check_or_create_fontist_path!
@@ -104,7 +122,13 @@ module Fontist
104
122
  def download_font
105
123
  if formula
106
124
  check_and_confirm_required_license(formula)
107
- font_installer(formula).fetch_font(name, confirmation: confirmation)
125
+ paths = font_installer(formula).fetch_font(name,
126
+ confirmation: confirmation)
127
+
128
+ Fontist.ui.say("Fonts installed at:")
129
+ paths.each do |path|
130
+ Fontist.ui.say("- #{path}")
131
+ end
108
132
  end
109
133
  end
110
134
 
@@ -223,6 +247,5 @@ module Fontist
223
247
  def installed(style)
224
248
  path(style) ? true : false
225
249
  end
226
-
227
250
  end
228
251
  end