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.

Raises:

  • (StandardError)


18
19
20
21
22
23
24
# File 'lib/compass/fontcustom/glyph_map.rb', line 18

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
# 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.map { |file| File.basename(file)[0..-5] }
  new glyphs, path, name, context
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/compass/fontcustom/glyph_map.rb', line 50

def exists?
  not glob.empty?
end

#filenameObject



45
46
47
48
# File 'lib/compass/fontcustom/glyph_map.rb', line 45

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

#generateObject

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



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/compass/fontcustom/glyph_map.rb', line 31

def generate
  unless exists?
    args = self.class.config.generator_options || {}
    args.merge!(
      :input     => File.join(Compass.configuration.images_path.to_s, self.path),
      :output    => output_dir,
      :font_name => @name,
      :file_hash => Compass.configuration.fontcustom_hash,
      :verbose   => false
    )
    ::Fontcustom::Generator::Font.start [args]
  end
end

#index_for_glyph(name) ⇒ Object



26
27
28
# File 'lib/compass/fontcustom/glyph_map.rb', line 26

def index_for_glyph(name)
  @glyphs.index name
end

#output_dirObject



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

def output_dir
  Compass.configuration.fonts_path.to_s
end

#to_sObject



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

def to_s
  @name.to_s
end