Module: Caracal::Core::Fonts
- Included in:
- Document
- Defined in:
- lib/caracal/core/fonts.rb
Overview
This module encapsulates all the functionality related to registering fonts.
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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(={}, &block) model = Caracal::Core::Models::FontModel.new(, &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 |