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
-
#glyph(index) ⇒ Sass::Script::String
Returns ‘:before` pseudo class styles for the letter at `index` of the font.
-
#glyph_font_name(map) ⇒ Sass::Script::String
Retuns the font name of ‘map`.
-
#glyph_font_name_quoted(map) ⇒ Sass::Script::String
Returns the font name of ‘map in quotes.
-
#glyph_font_sources(map) ⇒ Sass::Script::String
Returns all ‘url(…) format(…)` definitions for the font files of the `map`.
-
#glyph_font_type_url(map, type) ⇒ String
Helper method.
-
#glyph_map(uri) ⇒ Compass::Fontcustom::GlyphMap
Returns a ‘GlyphMap` representing a font.
- #sanitize_symbol(name) ⇒ Object
Instance Method Details
#glyph(index) ⇒ Sass::Script::String
Returns ‘:before` pseudo class styles for the letter at `index` of the font.
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`.
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
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`.
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`.
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.
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 |