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)


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

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.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.from_uri(uri, context) ⇒ Object

Parameters:

  • context (Object)

    usually an instance of FontImporter



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

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

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  not glob.empty?
end

#filenameObject



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

def filename
  file = glob.first
  File.basename file, File.extname(file)
end

#generateObject

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



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

def generate
  unless exists?
    args = self.class.config.generator_options || {}
    args.merge!(
      :input     => path,
      :output    => output_dir,
      :font_name => @name,
      :no_hash   => !Compass.configuration.fontcustom_hash,
      :quiet     => true
    )
    ::Fontcustom::Generator::Font.start [::Fontcustom::Options.new(args)]
  end
end

#index_for_glyph(name) ⇒ Object



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

def index_for_glyph(name)
  @glyphs.index name
end

#output_dirObject



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

def output_dir
  Compass.configuration.fonts_path.to_s
end

#to_sObject



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

def to_s
  @name.to_s
end