Module: Fontico

Defined in:
lib/fontico.rb,
lib/fontico/icon.rb,
lib/fontico/prawn.rb,
lib/fontico/helper.rb,
lib/fontico/builder.rb,
lib/fontico/railtie.rb,
lib/fontico/version.rb,
lib/fontico/lockfile.rb,
lib/fontico/manifest.rb,
lib/fontico/outliner.rb,
lib/fontico/resolver.rb,
lib/fontico/node_runner.rb,
lib/fontico/preprocessor.rb,
lib/fontico/emitters/font.rb,
lib/fontico/provider_fonts.rb,
lib/fontico/emitters/sprite.rb,
lib/fontico/emitters/stylesheet.rb

Defined Under Namespace

Modules: Emitters, Helper, Prawn, ProviderFonts Classes: Builder, Error, Icon, Lockfile, Manifest, NodeRunner, Outliner, Preprocessor, Railtie, Resolver

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.build_errorObject (readonly)

Why the last rebuild could not deliver: the exception it died on, and the icons it left out of the sprite.



61
62
63
# File 'lib/fontico.rb', line 61

def build_error
  @build_error
end

.css_classObject

Base class on every emitted ; also the stylesheet's selector.



32
# File 'lib/fontico.rb', line 32

def css_class = @css_class ||= "ico"

.inline_sprite=(value) ⇒ Object (writeonly)

Sets the attribute inline_sprite

Parameters:

  • value

    the value to set the attribute inline_sprite to.



29
30
31
# File 'lib/fontico.rb', line 29

def inline_sprite=(value)
  @inline_sprite = value
end

.manifest_pathObject



36
# File 'lib/fontico.rb', line 36

def manifest_path = @manifest_path ||= File.join(root, "icons.yml")

.output_dirObject



35
# File 'lib/fontico.rb', line 35

def output_dir    = @output_dir ||= "app/assets/builds"

.rootObject



34
# File 'lib/fontico.rb', line 34

def root          = @root ||= Dir.pwd

Class Method Details

.build(**opts) ⇒ Object



45
# File 'lib/fontico.rb', line 45

def build(**opts) = Builder.new(manifest, root: root, output: output_dir, **opts).call

.check!(name = nil) ⇒ Object

Raised at the call site, because that is the only place with anything useful to say. An icon left out of the sprite still resolves through the manifest and renders a perfectly valid at a symbol that isn't there — an invisible empty box, on a page that 200s. Silence is the one outcome worse than a stack trace.

Free in production: only the dev reloader ever fills these in.

Raises:



72
73
74
75
76
77
# File 'lib/fontico.rb', line 72

def check!(name = nil)
  raise Error, "icons.yml did not build: #{@build_error.message}" if @build_error

  reason = missing_icons[name]
  raise Error, "icon #{name.inspect} was left out of the sprite: #{reason}" if reason
end

.codepoint(name) ⇒ Object

The character to print when drawing this icon from the font — for Prawn, where you write the glyph literally. Pinned append-only in icons.lock so a reference in Ruby source never goes stale.

Raises:



86
87
88
89
90
91
# File 'lib/fontico.rb', line 86

def codepoint(name)
  cp = lockfile.codepoint_for(name.to_s)
  raise Error, "no icon named #{name.inspect}; run rake fontico:build" if cp.nil?

  cp
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Fontico)

    the object that the method was called on



96
# File 'lib/fontico.rb', line 96

def configure = yield(self)

.font_fileObject



81
# File 'lib/fontico.rb', line 81

def font_file = File.join(root, output_dir, "icons.ttf")

.glyph(name) ⇒ Object



93
# File 'lib/fontico.rb', line 93

def glyph(name) = [codepoint(name)].pack("U")

.inline_sprite?Boolean

Inline mode embeds definitions in the layout instead of referencing an external file — required when assets are served from a CDN, where cross-origin silently renders nothing.

Returns:

  • (Boolean)


43
# File 'lib/fontico.rb', line 43

def inline_sprite? = !!@inline_sprite

.lockfileObject



79
# File 'lib/fontico.rb', line 79

def lockfile = Lockfile.new(File.join(root, "icons.lock"))

.manifestObject



37
# File 'lib/fontico.rb', line 37

def manifest      = @manifest ||= Manifest.load(manifest_path)

.missing_iconsObject



63
# File 'lib/fontico.rb', line 63

def missing_icons = @missing_icons ||= {}

.rebuild!Object

The dev reloader's build, and the only caller that records what went wrong. Building stays forgiving on purpose — one typo must not stop the other 199 icons — so nothing raises here; the complaint is held until someone actually draws an icon. See #check!.



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

def rebuild!
  @build_error = nil
  @missing_icons = build.missing || {}
rescue StandardError => e
  @build_error = e
  @missing_icons = {}
end

.reset!Object



94
# File 'lib/fontico.rb', line 94

def reset!        = (@manifest = @build_error = @missing_icons = nil)

.sprite_fileObject



38
# File 'lib/fontico.rb', line 38

def sprite_file   = File.join(root, output_dir, "icons.svg")