module Caracal::Core::Fonts
This module encapsulates all the functionality related to registering fonts.
Public Class Methods
default_fonts()
click to toggle source
# File lib/caracal/core/fonts.rb, line 19 def self.default_fonts [ { name: 'Arial' }, { name: 'Trebuchet MS' } ] end
included(base)
click to toggle source
# File lib/caracal/core/fonts.rb, line 12 def self.included(base) base.class_eval do #------------------------------------------------------------- # Class Methods #------------------------------------------------------------- def self.default_fonts [ { name: 'Arial' }, { name: 'Trebuchet MS' } ] end #------------------------------------------------------------- # Public Methods #------------------------------------------------------------- #============== ATTRIBUTES ========================== def font(options={}, &block) model = Caracal::Core::Models::FontModel.new(options, &block) if model.valid? register_font(model) else raise Caracal::Errors::InvalidModelError, 'font must specify the :name attribute.' end model end #============== GETTERS ============================= def fonts @fonts ||= [] end def find_font(name) fonts.find { |f| f.matches?(name) } end #============== REGISTRATION ======================== def register_font(model) unregister_font(model.font_name) fonts << model model end def unregister_font(name) if f = find_font(name) fonts.delete(f) end end end end
Public Instance Methods
find_font(name)
click to toggle source
# File lib/caracal/core/fonts.rb, line 51 def find_font(name) fonts.find { |f| f.matches?(name) } end
font(options={}, &block)
click to toggle source
ATTRIBUTES ==========================¶ ↑
# File lib/caracal/core/fonts.rb, line 33 def font(options={}, &block) model = Caracal::Core::Models::FontModel.new(options, &block) if model.valid? register_font(model) else raise Caracal::Errors::InvalidModelError, 'font must specify the :name attribute.' end model end
fonts()
click to toggle source
register_font(model)
click to toggle source
unregister_font(name)
click to toggle source
# File lib/caracal/core/fonts.rb, line 64 def unregister_font(name) if f = find_font(name) fonts.delete(f) end end