forked from urvin-compliance/caracal
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from the-curve-consulting/mbarber/PWM-262
PWM-262: Specify portrait and landscape page orientations in the same document
- Loading branch information
Showing
7 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'caracal/core/models/base_model' | ||
|
||
module Caracal | ||
module Core | ||
module Models | ||
|
||
# This class handles block options passed to tables via their data | ||
# collections. | ||
# | ||
class PageFlipModel < BaseModel | ||
|
||
#------------------------------------------------------------- | ||
# Configuration | ||
#------------------------------------------------------------- | ||
|
||
# initialization | ||
def initialize(options={}, &block) | ||
super options, &block | ||
end | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
#=============== DATA ACCESSORS ======================= | ||
|
||
# .contents | ||
def contents | ||
@contents ||= [] | ||
end | ||
|
||
#=============== VALIDATION =========================== | ||
|
||
# .valid? | ||
def valid? | ||
contents.size > 0 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'caracal/core/models/page_flip_model' | ||
require 'caracal/errors' | ||
|
||
|
||
module Caracal | ||
module Core | ||
|
||
# This module encapsulates all the functionality related to flipping | ||
# specific page contents | ||
# | ||
module PageFlips | ||
def self.included(base) | ||
base.class_eval do | ||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
def page_flip(*args, &block) | ||
options = Caracal::Utilities.extract_options!(args) | ||
|
||
model = Caracal::Core::Models::PageFlipModel.new(options, &block) | ||
|
||
if model.valid? | ||
contents << model | ||
end | ||
|
||
model | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'spec_helper' | ||
|
||
describe Caracal::Core::Models::PageFlipModel do | ||
let(:name) { 'Arial' } | ||
|
||
subject { described_class.new } | ||
|
||
|
||
#------------------------------------------------------------- | ||
# Configuration | ||
#------------------------------------------------------------- | ||
|
||
describe 'configuration tests' do | ||
|
||
describe 'inheritance' do | ||
it { expect(subject).to be_a(Caracal::Core::Models::BaseModel) } | ||
end | ||
end | ||
|
||
#=============== VALIDATION =========================== | ||
|
||
describe '.valid?' do | ||
describe 'when content provided' do | ||
before { allow(subject).to receive(:contents).and_return(['a']) } | ||
|
||
it { expect(subject.valid?).to eq true } | ||
end | ||
describe 'when content not provided' do | ||
before { allow(subject).to receive(:contents).and_return([]) } | ||
|
||
it { expect(subject.valid?).to eq false } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe Caracal::Core::PageFlips do | ||
subject { Caracal::Document.new } | ||
|
||
|
||
#------------------------------------------------------------- | ||
# Public Methods | ||
#------------------------------------------------------------- | ||
|
||
describe 'public method tests' do | ||
|
||
# .page | ||
describe '.page_flip' do | ||
let!(:size) { subject.contents.size } | ||
|
||
before do | ||
subject.page_flip do |x| | ||
x.p | ||
end | ||
end | ||
|
||
it { expect(subject.contents.size).to eq size + 1 } | ||
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::PageFlipModel) } | ||
end | ||
end | ||
end |