Sha256: 117ac97b24033ceee5e2fdcb43816cfe98b1abb9b65d3ba30c6c6b4b7489af6e
Contents?: true
Size: 1.89 KB
Versions: 2
Compression:
Stored size: 1.89 KB
Contents
require 'caracal/core/models/font_model' require 'caracal/errors' module Caracal module Core # This module encapsulates all the functionality related to registering # fonts. # module Fonts 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(opts, &block) model = Caracal::Core::Models::FontModel.new(opts, &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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
caracal-0.1.1 | lib/caracal/core/fonts.rb |
caracal-0.1.0 | lib/caracal/core/fonts.rb |