Module: Compass::Fontcustom::SassExtensions::Functions

Included in:
Sass::Script::Functions
Defined in:
lib/compass/fontcustom/sass_extensions.rb

Overview

Sass function extensions

Constant Summary collapse

FONT_TYPE_OPTIONS =

Font type format mappings used in css font-face declarations.

{
  eot: {format: 'embedded-opentype', postfix: '?#iefix'},
  woff: {format: 'woff'},
  ttf: {format: 'truetype'},
  svg: {format: 'svg', postfix: '#%{font_name}'}
}

Instance Method Summary collapse

Instance Method Details

#glyph(map, glyph) ⇒ Sass::Script::String

Returns ‘:before` pseudo class styles for the letter at `index` of the font.

Parameters:

Returns:

  • (Sass::Script::String)


23
24
25
26
27
# File 'lib/compass/fontcustom/sass_extensions.rb', line 23

def glyph(map, glyph)
  # Name transform should be implemented as in FontCustom
  glyph = map.glyphs[Util.sanitize_symbol(glyph).to_sym]
  Sass::Script::String.new "'\\#{glyph[:codepoint]}'"
end

#glyph_font_name(map) ⇒ Sass::Script::String

Retuns the font name of ‘map`.

Parameters:

Returns:

  • (Sass::Script::String)


63
64
65
# File 'lib/compass/fontcustom/sass_extensions.rb', line 63

def glyph_font_name(map)
  Sass::Script::String.new map.name
end

#glyph_font_name_quoted(map) ⇒ Sass::Script::String

Returns the font name of ‘map in quotes

Parameters:

Returns:

  • (Sass::Script::String)


72
73
74
# File 'lib/compass/fontcustom/sass_extensions.rb', line 72

def glyph_font_name_quoted(map)
  Sass::Script::String.new %Q{"#{map.name}"}
end

#glyph_font_sources(map) ⇒ Sass::Script::String

Returns all ‘url(…) format(…)` definitions for the font files of the `map`.

Parameters:

Returns:

  • (Sass::Script::String)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/compass/fontcustom/sass_extensions.rb', line 43

def glyph_font_sources(map)
  map.generate
  src = []

  fonts = map.fonts

  FONT_TYPE_OPTIONS.each do |font_type, options|
    if font = fonts[font_type]
      url = glyph_font_type_url("#{font}#{options[:postfix]}" % {font_name: map.name})
      src << "#{url} format('#{options[:format]}')"
    end
  end
  Sass::Script::String.new src.join ", "
end

#glyph_font_type_url(file_path) ⇒ String

Helper method. Returns a ‘Sass::Script::Functions#font_url for the font of `type` in `map`.

Returns:

  • (String)


80
81
82
83
# File 'lib/compass/fontcustom/sass_extensions.rb', line 80

def glyph_font_type_url(file_path)
  font_file = Sass::Script::String.new File.basename(file_path)
  font_url(font_file).value
end

#glyph_map(uri) ⇒ Compass::Fontcustom::GlyphMap

Returns a ‘GlyphMap` representing a font.

Parameters:

  • uri (String)

    the uri to glob files from

Returns:



34
35
36
# File 'lib/compass/fontcustom/sass_extensions.rb', line 34

def glyph_map(uri)
  GlyphMap.from_uri uri.value, self
end

#sanitize_symbol(name) ⇒ Object



85
86
87
# File 'lib/compass/fontcustom/sass_extensions.rb', line 85

def sanitize_symbol(name)
  Sass::Script::String.new Util.sanitize_symbol name.value
end