Sha256: 0ca915321462d851969515d77788e60a2755d281c1a7a8f6486b6b69b9d8d2ed

Contents?: true

Size: 1.92 KB

Versions: 11

Compression:

Stored size: 1.92 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_align
          attr_reader :page_number_label
          attr_reader :page_number_label_size
          attr_reader :page_number_number_size
          attr_reader :page_number_show


          #-------------------------------------------------------------
          # 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: just `args.first` is falsey

            model = Caracal::Core::Models::PageNumberModel.new(options, &block)
            if model.valid?
              @page_number_align        = model.page_number_align
              @page_number_label        = model.page_number_label
              @page_number_label_size   = model.page_number_label_size
              @page_number_number_size  = model.page_number_number_size
              @page_number_show         = model.page_number_show
            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

11 entries across 11 versions & 2 rubygems

Version Path
caracal_the_curve-1.4.6 lib/caracal/core/page_numbers.rb
caracal_the_curve-1.4.5 lib/caracal/core/page_numbers.rb
caracal_the_curve-1.4.4 lib/caracal/core/page_numbers.rb
caracal_the_curve-1.4.3 lib/caracal/core/page_numbers.rb
caracal_the_curve-1.4.2 lib/caracal/core/page_numbers.rb
caracal_the_curve-1.4.1 lib/caracal/core/page_numbers.rb
caracal-1.4.1 lib/caracal/core/page_numbers.rb
caracal-1.4.0 lib/caracal/core/page_numbers.rb
caracal-1.3.0 lib/caracal/core/page_numbers.rb
caracal-1.2.0 lib/caracal/core/page_numbers.rb
caracal-1.1.2 lib/caracal/core/page_numbers.rb