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, #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



27
# File 'lib/fuse/document/asset/font.rb', line 27

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

#familyObject



14
# File 'lib/fuse/document/asset/font.rb', line 14

def family; @family ||= variant[:family] end

#styleObject



16
# File 'lib/fuse/document/asset/font.rb', line 16

def style;  @style  ||= variant[:style]  end

#typeObject



28
29
30
# File 'lib/fuse/document/asset/font.rb', line 28

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

#variantObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/fuse/document/asset/font.rb', line 17

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

#weightObject



15
# File 'lib/fuse/document/asset/font.rb', line 15

def weight; @weight ||= variant[:weight] end