fontist 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0d083618f330800ccb94e30d93fa8b5bf65d5e0a
4
- data.tar.gz: 133e64a85156c8fa5dcfc284ef57b3047fdbec0e
2
+ SHA256:
3
+ metadata.gz: 1fea467133e3e6a8a287dd36a2a03790fb63859f983b0398f0f558de519a0a64
4
+ data.tar.gz: b8c717aef31834b5a9b3c3f903dacf0d267ddd85aa6f0a1eca34566a45b219bf
5
5
  SHA512:
6
- metadata.gz: f5a33afe8b4157afadbaa8530e39de7a0b51222904101c396668e6e5d030fc51f6895f9f60478d9a32dc46af1bda7f1cef1aff0f27e2bc10bc3ae0e7b661d71f
7
- data.tar.gz: 3b1d0e38e2b42cf5e24f568cec75a34666ff7b3a98b36b673969365a4ec87b4add38b5fe3dac79a16871596d19b9454eac9fd6ada0097764a26af364f7fd5fee
6
+ metadata.gz: 20d44b20267db6f15f1b36be660f91690cef7c6f4b0653341231b3f18658ec0f88ea8225884b7b2ac1d06f3e8aa5be79aea600fed5be91513f43031a10b5de5b
7
+ data.tar.gz: 6138e6bed40c741f21c6d116f021aef9f6c7cca24506337fe681ba5e6c6e996c8e8e6a84e50103601231d6cab9f5cafc7b5527b418d65fbd6c1477c67ceda201
data/README.md CHANGED
@@ -434,6 +434,20 @@ git commit -m "Google Fonts update"
434
434
  git push
435
435
  ```
436
436
 
437
+ ### Import of SIL fonts
438
+
439
+ Fontist contains formulas of [SIL fonts](https://software.sil.org/fonts/). They
440
+ can be updated with:
441
+
442
+ ```sh
443
+ fontist import-sil
444
+ cd ~/.fontist/formulas
445
+ git add Formulas/sil
446
+ git add index.yml
447
+ git commit -m "SIL fonts update"
448
+ git push
449
+ ```
450
+
437
451
  ### Releasing
438
452
 
439
453
  Releasing is done automatically with GitHub Action. Just bump and tag with `gem-release`.
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency "pry"
41
41
  spec.add_development_dependency "bundler", "~> 2.0"
42
42
  spec.add_development_dependency "gem-release"
43
+ spec.add_development_dependency "nokogiri", "~> 1.0"
43
44
  spec.add_development_dependency "rake", "~> 12.3.3"
44
45
  spec.add_development_dependency "rspec", "~> 3.0"
45
46
  spec.add_development_dependency "rubocop", "0.75.0"
@@ -124,6 +124,12 @@ module Fontist
124
124
  STATUS_SUCCESS
125
125
  end
126
126
 
127
+ desc "import-sil", "Import formulas from SIL"
128
+ def import_sil
129
+ require "fontist/import/sil_import"
130
+ Fontist::Import::SilImport.new.call
131
+ end
132
+
127
133
  private
128
134
 
129
135
  def success
@@ -3,9 +3,9 @@ require "fontist/font_installer"
3
3
  module Fontist
4
4
  class Font
5
5
  def initialize(options = {})
6
- @name = options.fetch(:name, nil)
7
- @confirmation = options.fetch(:confirmation, "no")
8
- @force = options.fetch(:force, false)
6
+ @name = options[:name]
7
+ @confirmation = options[:confirmation] || "no"
8
+ @force = options[:force] || false
9
9
 
10
10
  check_or_create_fontist_path!
11
11
  end
@@ -121,7 +121,7 @@ module Fontist
121
121
  if formula.license_required && !confirmation.casecmp("yes").zero?
122
122
  @confirmation = show_license_and_ask_for_input(formula.license)
123
123
 
124
- if !confirmation.casecmp("yes").zero?
124
+ unless confirmation&.casecmp?("yes")
125
125
  raise Fontist::Errors::LicensingError.new(
126
126
  "Fontist will not download these fonts unless you accept the terms."
127
127
  )
@@ -50,9 +50,10 @@ module Fontist
50
50
 
51
51
  def save(hash)
52
52
  filename = Import.name_to_filename(hash[:name])
53
+ path = @options[:formula_dir] ? File.join(@options[:formula_dir], filename) : filename
53
54
  yaml = YAML.dump(Helpers::HashHelper.stringify_keys(hash))
54
- File.write(filename, yaml)
55
- filename
55
+ File.write(path, yaml)
56
+ path
56
57
  end
57
58
  end
58
59
  end
@@ -6,3 +6,6 @@
6
6
  - Open Sans
7
7
  - Work Sans
8
8
  - Fira Code
9
+ - Andika
10
+ - Harmattan
11
+ - Padauk
@@ -7,7 +7,7 @@ module Fontist
7
7
  class RecursiveExtraction
8
8
  FONTS_PATTERN = "**/*.{ttf,otf,ttc}".freeze
9
9
  ARCHIVE_EXTENSIONS = %w[zip msi exe cab].freeze
10
- LICENSE_PATTERN = /(OFL\.txt|UFL\.txt|LICENSE\.txt|COPYING)$/i.freeze
10
+ LICENSE_PATTERN = /(ofl\.txt|ufl\.txt|licenses?\.txt|copying)$/i.freeze
11
11
 
12
12
  def initialize(archive, subarchive: nil, subdir: nil)
13
13
  @archive = archive
@@ -0,0 +1,99 @@
1
+ require "nokogiri"
2
+ require "fontist/import/create_formula"
3
+
4
+ module Fontist
5
+ module Import
6
+ class SilImport
7
+ ROOT = "https://software.sil.org/fonts/".freeze
8
+
9
+ def call
10
+ links = font_links
11
+ Fontist.ui.success("Found #{links.size} links.")
12
+
13
+ paths = []
14
+ links.each do |link|
15
+ path = create_formula_by_page_link(link)
16
+ paths << path if path
17
+ end
18
+
19
+ Fontist::Index.rebuild
20
+
21
+ Fontist.ui.success("Created #{paths.size} formulas.")
22
+ end
23
+
24
+ private
25
+
26
+ def font_links
27
+ html = URI.parse(ROOT).open.read
28
+ document = Nokogiri::HTML.parse(html)
29
+ document.css("table.products div.title > a")
30
+ end
31
+
32
+ def create_formula_by_page_link(link)
33
+ url = find_archive_url_by_page_link(link)
34
+ return unless url
35
+
36
+ create_formula_by_archive_url(url)
37
+ end
38
+
39
+ def create_formula_by_archive_url(url)
40
+ path = Fontist::Import::CreateFormula.new(url, formula_dir: formula_dir).call
41
+ Fontist.ui.success("Formula has been successfully created: #{path}")
42
+
43
+ path
44
+ end
45
+
46
+ def find_archive_url_by_page_link(link)
47
+ Fontist.ui.print("Searching for an archive of #{link.content}... ")
48
+
49
+ page_uri = URI.join(ROOT, link[:href])
50
+ archive_uri = find_archive_url_by_page_uri(page_uri)
51
+ unless archive_uri
52
+ Fontist.ui.error("NOT FOUND")
53
+ return
54
+ end
55
+
56
+ Fontist.ui.success("DONE")
57
+
58
+ archive_uri.to_s
59
+ end
60
+
61
+ def find_archive_url_by_page_uri(uri)
62
+ response = uri.open
63
+ current_url = response.base_uri
64
+ html = response.read
65
+ document = Nokogiri::HTML.parse(html)
66
+ link = find_archive_link(document)
67
+ return URI.join(current_url, link[:href]) if link
68
+
69
+ page_link = find_download_page(document)
70
+ return unless page_link
71
+
72
+ page_uri = URI.join(current_url, page_link[:href])
73
+ find_archive_url_by_page_uri(page_uri)
74
+ end
75
+
76
+ def find_archive_link(document)
77
+ links = document.css("a.btn-download")
78
+ download_links = links.select { |tag| tag.content.include?("DOWNLOAD CURRENT VERSION") }
79
+ return download_links.first unless download_links.empty?
80
+
81
+ links = document.css("a")
82
+ download_links = links.select { |tag| tag.content.match?(/Download.*\.zip/) }
83
+ download_links.first
84
+ end
85
+
86
+ def find_download_page(document)
87
+ links = document.css("a.btn-download")
88
+ page_links = links.select { |tag| tag.content == "DOWNLOADS" }
89
+ page_links.first
90
+ end
91
+
92
+ def formula_dir
93
+ @formula_dir ||= Fontist.formulas_path.join("sil").tap do |path|
94
+ FileUtils.mkdir_p(path) unless File.exist?(path)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.8.1".freeze
2
+ VERSION = "1.8.2".freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  - Abu Nashir
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-20 00:00:00.000000000 Z
12
+ date: 2020-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: down
@@ -179,6 +179,20 @@ dependencies:
179
179
  - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: nokogiri
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '1.0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '1.0'
182
196
  - !ruby/object:Gem::Dependency
183
197
  name: rake
184
198
  requirement: !ruby/object:Gem::Requirement
@@ -325,6 +339,7 @@ files:
325
339
  - lib/fontist/import/otfinfo/template.erb
326
340
  - lib/fontist/import/otfinfo_generate.rb
327
341
  - lib/fontist/import/recursive_extraction.rb
342
+ - lib/fontist/import/sil_import.rb
328
343
  - lib/fontist/import/template_helper.rb
329
344
  - lib/fontist/import/text_helper.rb
330
345
  - lib/fontist/index.rb
@@ -370,9 +385,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
385
  - !ruby/object:Gem::Version
371
386
  version: '0'
372
387
  requirements: []
373
- rubyforge_project:
374
- rubygems_version: 2.6.14.4
375
- signing_key:
388
+ rubygems_version: 3.0.3
389
+ signing_key:
376
390
  specification_version: 4
377
391
  summary: A libarary find or download fonts
378
392
  test_files: []