Module: Caracal::Core::PageFlips

Included in:
Document
Defined in:
lib/caracal/core/page_flips.rb

Overview

This module encapsulates all the functionality related to flipping specific page contents

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
# File 'lib/caracal/core/page_flips.rb', line 12

def self.included(base)
  base.class_eval do

    #-------------------------------------------------------------
    # Public Methods
    #-------------------------------------------------------------

    def page_flip(*args, &block)
      options = Caracal::Utilities.extract_options!(args)

      # Pass through the page dimensions from the parent document,
      # using the page height as the page width, due to it using
      # the inverse dimensions.
      options.merge!({
        width: page_height,
        margin_left: page_margin_left,
        margin_right: page_margin_right
      })

      model = Caracal::Core::Models::PageFlipModel.new(options, &block)
      
      if model.valid?
        contents << model
      end

      model
    end
  end
end