Skip to content

Commit

Permalink
Merge pull request #7 from the-curve-consulting/mbarber/PWM-262-V3
Browse files Browse the repository at this point in the history
PWM-262: Specify portrait and landscape page orientations in the same document
  • Loading branch information
EndoMatrix authored Feb 7, 2024
2 parents 5198a25 + 56bffff commit 3e5e21f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
23 changes: 23 additions & 0 deletions lib/caracal/core/models/page_flip_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class PageFlipModel < BaseModel
# Configuration
#-------------------------------------------------------------

# accessors
attr_reader :page_width
attr_reader :page_margin_left
attr_reader :page_margin_right

# initialization
def initialize(options={}, &block)
super options, &block
Expand All @@ -21,6 +26,15 @@ def initialize(options={}, &block)
#-------------------------------------------------------------
# Public Methods
#-------------------------------------------------------------

#========== SETTERS ===============================

# integers
[:width, :margin_left, :margin_right].each do |m|
define_method "#{ m }" do |value|
instance_variable_set("@page_#{ m }", value.to_i)
end
end

#=============== DATA ACCESSORS =======================

Expand All @@ -35,6 +49,15 @@ def contents
def valid?
contents.size > 0
end

#--------------------------------------------------
# Private Instance Methods
#--------------------------------------------------
private

def option_keys
[:width, :margin_left, :margin_right]
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/caracal/core/page_flips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def self.included(base)
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?
Expand Down
2 changes: 1 addition & 1 deletion lib/caracal/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Caracal
VERSION = '1.4.4'
VERSION = '1.4.5'
end
19 changes: 16 additions & 3 deletions spec/lib/caracal/core/tables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@

it { expect(subject.contents.size).to eq size + 1 }
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::TableModel) }
it { expect(subject.contents.last.table_width).to be(9360) }
end

describe '.table within a page-flip' do
let!(:size) { subject.contents.size }

before do
subject.page_flip do |x|
x.table [['Sample Text']]
end
end

it { expect(subject.contents.size).to eq size + 1 }
it { expect(subject.contents.last.contents.first).to be_a(Caracal::Core::Models::TableModel) }
it { expect(subject.contents.last.contents.first.table_width).to be(12960) }
end

end

end
end

0 comments on commit 3e5e21f

Please sign in to comment.