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_FORMATS =

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

{
  'eot?#iefix'       => 'embedded-opentype',
  'woff'             => 'woff',
  'ttf'              => 'truetype',
  "svg#%{font_name}" => 'svg'
}

Instance Method Summary collapse

Instance Method Details

#glyph(index) ⇒ Sass::Script::String

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

Parameters:

  • index (FixNum)

    the font’s index

Returns:

  • (Sass::Script::String)


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

def glyph(index)
  idx = (61696+index.value-1).to_s(16)
  css = %Q[&:before { content: "\\#{idx}"; }]
  Sass::Script::String.new %Q["\\#{idx}"]
end

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

Retuns the font name of ‘map`.

Parameters:

Returns:

  • (Sass::Script::String)


57
58
59
# File 'lib/compass/fontcustom/sass_extensions.rb', line 57

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)


66
67
68
# File 'lib/compass/fontcustom/sass_extensions.rb', line 66

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)


42
43
44
45
46
47
48
49
50
# File 'lib/compass/fontcustom/sass_extensions.rb', line 42

def glyph_font_sources(map)
  map.generate
  src = []
  FONT_TYPE_FORMATS.each do |type, format|
    url = glyph_font_type_url map, type
    src << "#{url} format('#{format}')"
  end
  Sass::Script::String.new src.join ", "
end

#glyph_font_type_url(map, type) ⇒ String

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

Returns:

  • (String)


74
75
76
77
78
79
# File 'lib/compass/fontcustom/sass_extensions.rb', line 74

def glyph_font_type_url(map, type)
  type = type % {font_name: map.name}
  file_name = "#{map.filename}.#{type}"
  font_file = Sass::Script::String.new file_name
  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:



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

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

#sanitize_symbol(name) ⇒ Object



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

def sanitize_symbol(name)
  sanitized = name.value.to_s.gsub(/[.+{};]+/, ' ').strip.gsub(/[ ]+/, '-')
  Sass::Script::String.new sanitized
end