Class: Fontist::Manifest
- Inherits:
-
Lutaml::Model::Collection
- Object
- Lutaml::Model::Collection
- Fontist::Manifest
show all
- Defined in:
- lib/fontist/manifest.rb
Overview
Manifest class for managing font manifests.
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.font_class ⇒ Object
190
191
192
|
# File 'lib/fontist/manifest.rb', line 190
def self.font_class
ManifestFont
end
|
.from_file(path, locations: false) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/fontist/manifest.rb', line 132
def self.from_file(path, locations: false)
Fontist.ui.debug("Manifest: #{path}")
unless File.exist?(path)
raise Fontist::Errors::ManifestCouldNotBeFoundError,
"Manifest file not found: #{path}"
end
file_content = File.read(path).strip
if file_content.empty?
raise Fontist::Errors::ManifestCouldNotBeReadError,
"Manifest file is empty: #{path}"
end
manifest_model = begin
from_yaml(file_content)
rescue StandardError => e
raise Fontist::Errors::ManifestCouldNotBeReadError,
"Manifest file could not be read: #{e.message}"
end
with_performance_optimizations do
manifest_model.to_response(locations: locations)
end
end
|
.from_hash(data, options = {}) ⇒ Object
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/fontist/manifest.rb', line 160
def self.from_hash(data, options = {})
locations = options.delete(:locations) || false
model = super
with_performance_optimizations do
model.to_response(locations: locations)
end
end
|
Enable performance optimizations for manifest compilation This includes:
Instance Method Details
#fonts_casted ⇒ Object
194
195
196
197
198
|
# File 'lib/fontist/manifest.rb', line 194
def fonts_casted
Array(fonts).map do |font|
self.class.font_class === font ? font : self.class.font_class.new(font.to_h)
end
end
|
#install(confirmation: "no", hide_licenses: false, no_progress: false, location: nil) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/fontist/manifest.rb', line 200
def install(confirmation: "no", hide_licenses: false, no_progress: false,
location: nil)
installed_any = false
fonts_casted.each do |font|
paths = font.group_paths
if paths.empty?
font.install(confirmation: confirmation,
hide_licenses: hide_licenses,
no_progress: no_progress,
location: location)
installed_any = true
end
end
if installed_any
Fontist::SystemFont.reset_fontist_font_paths_cache
end
to_response
end
|
#to_file(path) ⇒ Object
235
236
237
238
|
# File 'lib/fontist/manifest.rb', line 235
def to_file(path)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, to_yaml)
end
|
#to_response(locations: false) ⇒ Object
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/fontist/manifest.rb', line 222
def to_response(locations: false)
return self if fonts_casted.any?(&:group_paths_empty?) && !locations
self.class.with_performance_optimizations do
ManifestResponse.new.tap do |response|
response.fonts = fonts_casted.map do |font|
font.to_response(locations: locations)
end
end
end
end
|