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
164
165
166
|
# File 'lib/fontist/manifest.rb', line 164
def self.font_class
ManifestFont
end
|
.from_file(path, locations: false) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/fontist/manifest.rb', line 106
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
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/fontist/manifest.rb', line 134
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
168
169
170
171
172
|
# File 'lib/fontist/manifest.rb', line 168
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/fontist/manifest.rb', line 174
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
209
210
211
212
|
# File 'lib/fontist/manifest.rb', line 209
def to_file(path)
FileUtils.mkdir_p(File.dirname(path))
File.write(path, to_yaml)
end
|
#to_response(locations: false) ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/fontist/manifest.rb', line 196
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
|