Class: Compass::Fontcustom::GlyphMap

Inherits:
Sass::Script::Literal
  • Object
show all
Includes:
Configurable
Defined in:
lib/compass/fontcustom/glyph_map.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Constructor Details

#initialize(glyphs, path, name, context) ⇒ GlyphMap

Returns a new instance of GlyphMap.

Parameters:

  • glyphs (Array)

    all the glyphs found at path

  • path (String)

    the absolute path where glyphs are stored

  • name (String)

    the name of the glyph font

  • context (Object)

    the invoking object

Raises:

  • (StandardError)


28
29
30
31
32
33
34
# File 'lib/compass/fontcustom/glyph_map.rb', line 28

def initialize(glyphs, path, name, context)
  raise StandardError, "No glyphs found at '#{path}'" if glyphs.empty?
  @glyphs = glyphs
  @path   = path
  @name   = name
  @context = context
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/compass/fontcustom/glyph_map.rb', line 10

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/compass/fontcustom/glyph_map.rb', line 10

def path
  @path
end

Class Method Details

.from_uri(uri, context) ⇒ Object

Parameters:

  • context (Object)

    usually an instance of FontImporter



13
14
15
16
17
18
19
20
21
22
# File 'lib/compass/fontcustom/glyph_map.rb', line 13

def self.from_uri(uri, context)
  path, name = FontImporter.path_and_name uri
  glyphs = FontImporter.files(uri).sort

  # TODO: improve extraction of aboslute path
  path = File.dirname glyphs.first
  glyphs.map! { |file| File.basename(file)[0..-5] }

  new glyphs, path, name, context
end

Instance Method Details

#fontsObject



51
52
53
54
55
56
57
# File 'lib/compass/fontcustom/glyph_map.rb', line 51

def fonts
  if @fontcustom
    @fontcustom.manifest.get(:fonts).each_with_object({}) do |font, result|
      result[File.extname(font)[1..-1].to_sym] = font
    end
  end
end

#generateObject

Starts the Fontcustom font generator to write font files to disk.



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

def generate
  args = (self.class.config.generator_options || {}).
    merge(output: output_dir, quiet: true, fonts: []).
    merge(Compass.configuration.fontcustom_options).
    merge(font_name: @name, input: path)
  @fontcustom = ::Fontcustom::Base.new(args)
  @fontcustom.compile
  File.delete(@fontcustom.manifest.manifest) if Compass.configuration.fontcustom_discard_manifest
end

#glyphsObject



59
60
61
# File 'lib/compass/fontcustom/glyph_map.rb', line 59

def glyphs
  @fontcustom.manifest.get :glyphs
end

#index_for_glyph(name) ⇒ Object



36
37
38
# File 'lib/compass/fontcustom/glyph_map.rb', line 36

def index_for_glyph(name)
  @glyphs.index name
end

#output_dirObject



67
68
69
# File 'lib/compass/fontcustom/glyph_map.rb', line 67

def output_dir
  Compass.configuration.fontcustom_fonts_path || Compass.configuration.fonts_path
end

#to_sObject



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

def to_s
  @name.to_s
end