Sha256: 620908756aa86b82de4e41e72e3e5c5b35a7b2489207440f83d8cdffc7eea0bb

Contents?: true

Size: 1.64 KB

Versions: 19

Compression:

Stored size: 1.64 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(*args, &block)
            options = Caracal::Utilities.extract_options!(args)
            options.merge!({ show: !!args.first }) unless args.first.nil?  # careful: falsey value
            
            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

19 entries across 19 versions & 1 rubygems

Version Path
caracal-1.0.8 lib/caracal/core/page_numbers.rb
caracal-1.0.7 lib/caracal/core/page_numbers.rb
caracal-1.0.6 lib/caracal/core/page_numbers.rb
caracal-1.0.5 lib/caracal/core/page_numbers.rb
caracal-1.0.4 lib/caracal/core/page_numbers.rb
caracal-1.0.3 lib/caracal/core/page_numbers.rb
caracal-1.0.2 lib/caracal/core/page_numbers.rb
caracal-1.0.1 lib/caracal/core/page_numbers.rb
caracal-1.0.0 lib/caracal/core/page_numbers.rb
caracal-0.3.0 lib/caracal/core/page_numbers.rb
caracal-0.2.1 lib/caracal/core/page_numbers.rb
caracal-0.2.0 lib/caracal/core/page_numbers.rb
caracal-0.1.8 lib/caracal/core/page_numbers.rb
caracal-0.1.7 lib/caracal/core/page_numbers.rb
caracal-0.1.6 lib/caracal/core/page_numbers.rb
caracal-0.1.5 lib/caracal/core/page_numbers.rb
caracal-0.1.4 lib/caracal/core/page_numbers.rb
caracal-0.1.3 lib/caracal/core/page_numbers.rb
caracal-0.1.2 lib/caracal/core/page_numbers.rb