Sha256: e342a752adf109e1b823a310cfca19e66fcd6647975b7948012ffda2af4d0fa3

Contents?: true

Size: 1.66 KB

Versions: 7

Compression:

Stored size: 1.66 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_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: falsey value

            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_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

7 entries across 7 versions & 1 rubygems

Version Path
caracal-1.1.1 lib/caracal/core/page_numbers.rb
caracal-1.1.0 lib/caracal/core/page_numbers.rb
caracal-1.0.13 lib/caracal/core/page_numbers.rb
caracal-1.0.12 lib/caracal/core/page_numbers.rb
caracal-1.0.11 lib/caracal/core/page_numbers.rb
caracal-1.0.10 lib/caracal/core/page_numbers.rb
caracal-1.0.9 lib/caracal/core/page_numbers.rb