Sha256: b0b98b93680b20281262e704d2ddca1ba6173666467a7c5c8f981aa74c4c880b

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'caracal/core/models/page_number_model'
require 'caracal/errors'


module Caracal
  module Core
    
    # This module encapsulates all the functionality related to setting the 
    # document's page number behavior.
    #
    module PageNumbers
      def self.included(base)
        base.class_eval do
          
          #-------------------------------------------------------------
          # Configuration
          #-------------------------------------------------------------
    
          # constants
          const_set(:DEFAULT_PAGE_NUMBER_ALIGN,  :center)
          
          # accessors
          attr_reader :page_number_show
          attr_reader :page_number_align
          
          
          #-------------------------------------------------------------
          # Public Methods
          #-------------------------------------------------------------
    
          # This method controls whether and how page numbers are displayed
          # on the document.
          #
          def page_numbers(show = nil, **options, &block)
            options.merge!({ show: !!show })
            model = Caracal::Core::Models::PageNumberModel.new(options, &block)
            
            if model.valid?
              @page_number_show  = model.page_number_show
              @page_number_align = model.page_number_align
            else
              raise Caracal::Errors::InvalidModelError, 'page_numbers :align parameter must be :left, :center, or :right'
            end
          end
          
        end
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caracal-0.1.0 lib/caracal/core/page_numbers.rb