Class: DragonflyFonts::Processors::Encode

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_fonts/processors/encode.rb

Instance Method Summary collapse

Instance Method Details

#call(content, format, options = {}) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dragonfly_fonts/processors/encode.rb', line 6

def call(content, format, options = {})
  raise UnsupportedFormat unless content.ext
  raise UnsupportedFormat unless SUPPORTED_FORMATS.include?(content.ext.downcase)

  format = format.to_s

  raise UnsupportedOutputFormat unless SUPPORTED_OUTPUT_FORMATS.include?(format.downcase)

  if content.mime_type == Rack::Mime.mime_type(".#{format}")
    content.ext ||= format
    content.meta['format'] = format
    return
  end

  content.shell_update(ext: format, escape: false) do |old_path, new_path|
    case
    when content.ext == 'woff2' && format == 'ttf' then woff2_decompress(old_path, new_path)
    when format == 'eot' then ttf2eot(old_path, new_path)
    when format == 'ttx' then fonttools(old_path, new_path)
    when format == 'woff2' then woff2_compress(old_path, new_path)
    else fontforge(old_path, new_path)
    end
  end

  content.meta['format'] = format
  content.ext = format
end

#update_url(attrs, format, _args = '') ⇒ Object



34
35
36
# File 'lib/dragonfly_fonts/processors/encode.rb', line 34

def update_url(attrs, format, _args = '')
  attrs.ext = format.to_s
end