Why the last rebuild could not deliver: the exception it died on, and
the icons it left out of the sprite.
87
88
89
# File 'lib/fontico.rb', line 87defbuild_error@build_errorend
.css_class ⇒ Object
Base class on every emitted
32
# File 'lib/fontico.rb', line 32defcss_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 29definline_sprite=(value)@inline_sprite=valueend
.manifest_path ⇒ Object
36
37
38
# File 'lib/fontico.rb', line 36defmanifest_path=@manifest_path||=File.join(root,"icons.yml")# Same shape as I18n.load_path: engines first, the app last, later wins
# a name. Unset, it is just the app's icons.yml (non-Rails, tests).
.output_dir ⇒ Object
35
# File 'lib/fontico.rb', line 35defoutput_dir=@output_dir||="app/assets/builds"
.root ⇒ Object
34
# File 'lib/fontico.rb', line 34defroot=@root||=Dir.pwd
Class Method Details
.build(**opts) ⇒ Object
71
# File 'lib/fontico.rb', line 71defbuild(**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
Free in production: only the dev reloader ever fills these in.
# File 'lib/fontico.rb', line 98defcheck!(name=nil)raiseError,"icons.yml did not build: #{@build_error.message}"if@build_errorreason=missing_icons[name]raiseError,"icon #{name.inspect} was left out of the sprite: #{reason}"ifreasonend
.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.
# File 'lib/fontico.rb', line 112defcodepoint(name)cp=lockfile.codepoint_for(name.to_s)raiseError,"no icon named #{name.inspect} in icons.lock"ifcp.nil?cpend
# File 'lib/fontico.rb', line 122defconfigure=yield(self)
.discover(app) ⇒ Object
Rails engines that ship config/icons.yml (or icons.yml at the gem
root), then the app's file. The app is last on purpose.
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fontico.rb', line 51defdiscover(app)files=[]app.railties.eachdo|rt|nextunlessrt.is_a?(Rails::Engine)nextifrt.is_a?(Rails::Application)root=rt.rootfound=%w[config/icons.ymlicons.yml].map{root.join(_1)}.find{File.file?(_1.to_s)}files<<found.to_siffoundend# manifest_path goes in even when absent: the dev watcher has to notice
# an icons.yml created after boot. Manifest.load skips what isn't there.
(files.select{File.file?(_1)}<<manifest_path).uniqend
.font_file ⇒ Object
107
# File 'lib/fontico.rb', line 107deffont_file=File.join(root,output_dir,"icons.ttf")
.glyph(name) ⇒ Object
119
# File 'lib/fontico.rb', line 119defglyph(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
Returns:
(Boolean)
69
# File 'lib/fontico.rb', line 69definline_sprite?=!!@inline_sprite
.load_path ⇒ Object
Same shape as I18n.load_path: engines first, the app last, later wins
a name. Unset, it is just the app's icons.yml (non-Rails, tests).
39
# File 'lib/fontico.rb', line 39defload_path=@load_path||[manifest_path].select{File.file?(_1)}
.load_path=(paths) ⇒ Object
41
42
43
44
# File 'lib/fontico.rb', line 41defload_path=(paths)@load_path=paths.nil??nil:Array(paths)reset!end
.lockfile ⇒ Object
105
# File 'lib/fontico.rb', line 105deflockfile=Lockfile.new(File.join(root,"icons.lock"))
.manifest ⇒ Object
46
# File 'lib/fontico.rb', line 46defmanifest=@manifest||=Manifest.load(*load_path)
.missing_icons ⇒ Object
89
# File 'lib/fontico.rb', line 89defmissing_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!.
77
78
79
80
81
82
83
# File 'lib/fontico.rb', line 77defrebuild!@build_error=nil@missing_icons=build.missing||{}rescueStandardError=>e@build_error=e@missing_icons={}end
.reset! ⇒ Object
120
# File 'lib/fontico.rb', line 120defreset!=(@manifest=@build_error=@missing_icons=nil)
.sprite_file ⇒ Object
47
# File 'lib/fontico.rb', line 47defsprite_file=File.join(root,output_dir,"icons.svg")