Class: Fuse::Document::Asset::Font

Inherits:
Fuse::Document::Asset show all
Defined in:
lib/fuse/document/asset/font.rb

Constant Summary collapse

CSS_FORMATS =
[
    { extension: :woff, format: 'woff' },
    { extension: :ttf,  format: 'truetype' },
    { extension: :otf,  format: 'opentype' }
]
MIME_TYPES =
{
    otf:  'application/x-font-opentype',
    ttf:  'application/x-font-truetype',
    woff: 'application/x-font-woff'
}
VARIANT_PATTERN =
%r`([^/]+?)(?:[-_ ](normal|bold|bolder|lighter|[1-9]00))?(?:[-_ ](normal|italic|oblique))?\.[a-z]+$`

Constants inherited from Fuse::Document::Asset

TYPES

Instance Attribute Summary

Attributes inherited from Fuse::Document::Asset

#path

Instance Method Summary collapse

Methods inherited from Fuse::Document::Asset

[], #call, const_missing, #extension, #filter?, #filtered, for, #full_path, #initialize, #raw, #relative_path, #to_datauri

Constructor Details

This class inherits a constructor from Fuse::Document::Asset

Instance Method Details

#faceObject



33
34
35
# File 'lib/fuse/document/asset/font.rb', line 33

def face
  @face ||= [family, weight, style].join('-')
end

#typeObject



37
38
39
# File 'lib/fuse/document/asset/font.rb', line 37

def type
  MIME_TYPES[extension.to_sym] || super
end

#variantObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/fuse/document/asset/font.rb', line 22

def variant
  @variant ||= begin
    match = VARIANT_PATTERN.match(path)
    {
        family: match[1],
        weight: match[2] || 'normal',
        style:  match[3] || 'normal'
    }
  end
end