caracal 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/CHANGELOG.md +95 -5
- data/README.md +171 -35
- data/caracal.gemspec +4 -4
- data/lib/caracal/core/custom_properties.rb +49 -0
- data/lib/caracal/core/iframes.rb +42 -0
- data/lib/caracal/core/ignorables.rb +47 -0
- data/lib/caracal/core/models/custom_property_model.rb +60 -0
- data/lib/caracal/core/models/iframe_model.rb +148 -0
- data/lib/caracal/core/models/namespace_model.rb +65 -0
- data/lib/caracal/core/models/page_break_model.rb +50 -4
- data/lib/caracal/core/models/page_number_model.rb +50 -24
- data/lib/caracal/core/models/page_size_model.rb +34 -25
- data/lib/caracal/core/models/paragraph_model.rb +11 -4
- data/lib/caracal/core/models/style_model.rb +44 -15
- data/lib/caracal/core/models/table_cell_model.rb +61 -50
- data/lib/caracal/core/models/table_model.rb +1 -1
- data/lib/caracal/core/models/text_model.rb +42 -20
- data/lib/caracal/core/namespaces.rb +89 -0
- data/lib/caracal/core/page_numbers.rb +22 -16
- data/lib/caracal/core/page_settings.rb +18 -16
- data/lib/caracal/document.rb +75 -58
- data/lib/caracal/renderers/content_types_renderer.rb +18 -17
- data/lib/caracal/renderers/core_renderer.rb +1 -1
- data/lib/caracal/renderers/custom_renderer.rb +64 -0
- data/lib/caracal/renderers/document_renderer.rb +205 -118
- data/lib/caracal/renderers/fonts_renderer.rb +2 -2
- data/lib/caracal/renderers/footer_renderer.rb +41 -20
- data/lib/caracal/renderers/numbering_renderer.rb +27 -26
- data/lib/caracal/renderers/package_relationships_renderer.rb +14 -13
- data/lib/caracal/renderers/settings_renderer.rb +5 -5
- data/lib/caracal/renderers/styles_renderer.rb +88 -73
- data/lib/caracal/renderers/xml_renderer.rb +20 -20
- data/lib/caracal/version.rb +1 -1
- data/lib/caracal.rb +11 -2
- data/spec/lib/caracal/core/iframes_spec.rb +29 -0
- data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
- data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +60 -62
- data/spec/lib/caracal/core/models/link_model_spec.rb +12 -11
- data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +66 -31
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +42 -32
- data/spec/lib/caracal/core/models/style_model_spec.rb +32 -1
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +10 -1
- data/spec/lib/caracal/core/models/text_model_spec.rb +18 -10
- data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +32 -23
- data/spec/lib/caracal/core/page_settings_spec.rb +33 -25
- data/spec/lib/caracal/core/relationships_spec.rb +47 -47
- data/spec/support/_fixtures/snippet.docx +0 -0
- metadata +28 -8
|
@@ -1,59 +1,69 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Caracal::Core::Models::PageSizeModel do
|
|
4
|
-
subject do
|
|
4
|
+
subject do
|
|
5
5
|
described_class.new do
|
|
6
6
|
width 15840
|
|
7
7
|
height 12240
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
#-------------------------------------------------------------
|
|
12
12
|
# Configuration
|
|
13
13
|
#-------------------------------------------------------------
|
|
14
14
|
|
|
15
15
|
describe 'configuration tests' do
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
# constants
|
|
18
18
|
describe 'constants' do
|
|
19
19
|
it { expect(described_class::DEFAULT_PAGE_WIDTH).to eq 12240 }
|
|
20
20
|
it { expect(described_class::DEFAULT_PAGE_HEIGHT).to eq 15840 }
|
|
21
|
+
it { expect(described_class::DEFAULT_PAGE_ORIENTATION).to eq 'portrait' }
|
|
21
22
|
end
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
# accessors
|
|
24
25
|
describe 'accessors' do
|
|
25
26
|
it { expect(subject.page_width).to eq 15840 }
|
|
26
27
|
it { expect(subject.page_height).to eq 12240 }
|
|
27
28
|
end
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
end
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
|
|
32
33
|
#-------------------------------------------------------------
|
|
33
34
|
# Public Methods
|
|
34
35
|
#-------------------------------------------------------------
|
|
35
|
-
|
|
36
|
+
|
|
36
37
|
describe 'public method tests' do
|
|
37
|
-
|
|
38
|
+
|
|
38
39
|
#=============== SETTERS ==========================
|
|
39
|
-
|
|
40
|
-
# .width
|
|
41
|
-
describe '.width' do
|
|
42
|
-
before { subject.width(10000) }
|
|
43
|
-
|
|
44
|
-
it { expect(subject.page_width).to eq 10000 }
|
|
45
|
-
end
|
|
46
|
-
|
|
40
|
+
|
|
47
41
|
# .height
|
|
48
42
|
describe '.height' do
|
|
49
43
|
before { subject.height(10000) }
|
|
50
|
-
|
|
44
|
+
|
|
51
45
|
it { expect(subject.page_height).to eq 10000 }
|
|
52
46
|
end
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
|
|
48
|
+
# .orientation
|
|
49
|
+
describe '.orientation' do
|
|
50
|
+
before { subject.orientation('landscape') }
|
|
51
|
+
|
|
52
|
+
it { expect(subject.page_orientation).to eq 'landscape' }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# .width
|
|
56
|
+
describe '.width' do
|
|
57
|
+
before { subject.width(10000) }
|
|
58
|
+
|
|
59
|
+
it { expect(subject.page_width).to eq 10000 }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
55
65
|
#=============== VALIDATION ===========================
|
|
56
|
-
|
|
66
|
+
|
|
57
67
|
describe '.valid?' do
|
|
58
68
|
describe 'when all sizes gt 0' do
|
|
59
69
|
it { expect(subject.valid?).to eq true }
|
|
@@ -63,29 +73,29 @@ describe Caracal::Core::Models::PageSizeModel do
|
|
|
63
73
|
before do
|
|
64
74
|
allow(subject).to receive("page_#{ d }").and_return(0)
|
|
65
75
|
end
|
|
66
|
-
|
|
76
|
+
|
|
67
77
|
it { expect(subject.valid?).to eq false }
|
|
68
78
|
end
|
|
69
79
|
end
|
|
70
80
|
end
|
|
71
|
-
|
|
81
|
+
|
|
72
82
|
end
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
|
|
84
|
+
|
|
75
85
|
#-------------------------------------------------------------
|
|
76
86
|
# Private Methods
|
|
77
87
|
#-------------------------------------------------------------
|
|
78
|
-
|
|
88
|
+
|
|
79
89
|
describe 'private method tests' do
|
|
80
|
-
|
|
90
|
+
|
|
81
91
|
# .option_keys
|
|
82
92
|
describe '.option_keys' do
|
|
83
93
|
let(:actual) { subject.send(:option_keys).sort }
|
|
84
|
-
let(:expected) { [:width, :height].sort }
|
|
85
|
-
|
|
94
|
+
let(:expected) { [:width, :height, :orientation].sort }
|
|
95
|
+
|
|
86
96
|
it { expect(actual).to eq expected }
|
|
87
97
|
end
|
|
88
|
-
|
|
98
|
+
|
|
89
99
|
end
|
|
90
|
-
|
|
91
|
-
end
|
|
100
|
+
|
|
101
|
+
end
|
|
@@ -19,6 +19,7 @@ describe Caracal::Core::Models::StyleModel do
|
|
|
19
19
|
|
|
20
20
|
# constants
|
|
21
21
|
describe 'constants' do
|
|
22
|
+
it { expect(described_class::DEFAULT_STYLE_TYPE).to eq 'paragraph' }
|
|
22
23
|
it { expect(described_class::DEFAULT_STYLE_COLOR).to eq '333333' }
|
|
23
24
|
it { expect(described_class::DEFAULT_STYLE_SIZE).to eq 20 }
|
|
24
25
|
it { expect(described_class::DEFAULT_STYLE_BOLD).to eq false }
|
|
@@ -38,6 +39,7 @@ describe Caracal::Core::Models::StyleModel do
|
|
|
38
39
|
it { expect(subject.style_default).to eq true }
|
|
39
40
|
it { expect(subject.style_id).to eq 'Normal' }
|
|
40
41
|
it { expect(subject.style_name).to eq 'normal' }
|
|
42
|
+
it { expect(subject.style_type).to eq 'paragraph' }
|
|
41
43
|
it { expect(subject.style_color).to eq '333333' }
|
|
42
44
|
it { expect(subject.style_font).to eq 'Arial' }
|
|
43
45
|
it { expect(subject.style_size).to eq 20 }
|
|
@@ -107,6 +109,21 @@ describe Caracal::Core::Models::StyleModel do
|
|
|
107
109
|
|
|
108
110
|
it { expect(subject.style_top).to eq 100 }
|
|
109
111
|
end
|
|
112
|
+
describe '.indent_left' do
|
|
113
|
+
before { subject.indent_left(1440) }
|
|
114
|
+
|
|
115
|
+
it { expect(subject.style_indent_left).to eq 1440 }
|
|
116
|
+
end
|
|
117
|
+
describe '.indent_right' do
|
|
118
|
+
before { subject.indent_right(720) }
|
|
119
|
+
|
|
120
|
+
it { expect(subject.style_indent_right).to eq 720 }
|
|
121
|
+
end
|
|
122
|
+
describe '.indent_right' do
|
|
123
|
+
before { subject.indent_first(567) }
|
|
124
|
+
|
|
125
|
+
it { expect(subject.style_indent_first).to eq 567 }
|
|
126
|
+
end
|
|
110
127
|
|
|
111
128
|
# strings
|
|
112
129
|
describe '.id' do
|
|
@@ -137,6 +154,20 @@ describe Caracal::Core::Models::StyleModel do
|
|
|
137
154
|
it { expect(subject.style_align).to eq :right }
|
|
138
155
|
end
|
|
139
156
|
|
|
157
|
+
# custom
|
|
158
|
+
describe '.type' do
|
|
159
|
+
describe 'when valid' do
|
|
160
|
+
before { subject.type 'character'}
|
|
161
|
+
|
|
162
|
+
it { expect(subject.style_type).to eq 'character' }
|
|
163
|
+
end
|
|
164
|
+
describe 'when invalid' do
|
|
165
|
+
before { subject.type 'bogus'}
|
|
166
|
+
|
|
167
|
+
it { expect(subject.style_type).to eq 'paragraph' }
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
140
171
|
|
|
141
172
|
#=================== STATE ===============================
|
|
142
173
|
|
|
@@ -184,7 +215,7 @@ describe Caracal::Core::Models::StyleModel do
|
|
|
184
215
|
# .option_keys
|
|
185
216
|
describe '.option_keys' do
|
|
186
217
|
let(:actual) { subject.send(:option_keys).sort }
|
|
187
|
-
let(:expected) { [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align].sort }
|
|
218
|
+
let(:expected) { [:type, :bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first].sort }
|
|
188
219
|
|
|
189
220
|
it { expect(actual).to eq expected }
|
|
190
221
|
end
|
|
@@ -23,6 +23,7 @@ describe Caracal::Core::Models::TableCellModel do
|
|
|
23
23
|
# constants
|
|
24
24
|
describe 'constants' do
|
|
25
25
|
it { expect(described_class::DEFAULT_CELL_BACKGROUND).to eq 'ffffff' }
|
|
26
|
+
it { expect(described_class::DEFAULT_CELL_VERTICAL_ALIGN).to eq :top }
|
|
26
27
|
it { expect(described_class::DEFAULT_CELL_MARGINS).to be_a(Caracal::Core::Models::MarginModel) }
|
|
27
28
|
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_top).to eq 100 }
|
|
28
29
|
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_bottom).to eq 100 }
|
|
@@ -35,6 +36,7 @@ describe Caracal::Core::Models::TableCellModel do
|
|
|
35
36
|
it { expect(subject.cell_background).to eq 'cccccc' }
|
|
36
37
|
it { expect(subject.cell_margins).to be_a(Caracal::Core::Models::MarginModel) }
|
|
37
38
|
it { expect(subject.cell_width).to eq 2000 }
|
|
39
|
+
it { expect(subject.cell_vertical_align).to eq :top }
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
end
|
|
@@ -95,6 +97,13 @@ describe Caracal::Core::Models::TableCellModel do
|
|
|
95
97
|
|
|
96
98
|
it { expect(subject.cell_width).to eq 7500 }
|
|
97
99
|
end
|
|
100
|
+
|
|
101
|
+
#.vertical_allign
|
|
102
|
+
describe '.vertical_align' do
|
|
103
|
+
before { subject.vertical_align(:center) }
|
|
104
|
+
|
|
105
|
+
it { expect(subject.cell_vertical_align).to eq :center }
|
|
106
|
+
end
|
|
98
107
|
|
|
99
108
|
|
|
100
109
|
#=============== CONTENT FNS =======================
|
|
@@ -211,7 +220,7 @@ describe Caracal::Core::Models::TableCellModel do
|
|
|
211
220
|
# .option_keys
|
|
212
221
|
describe '.option_keys' do
|
|
213
222
|
let(:actual) { subject.send(:option_keys).sort }
|
|
214
|
-
let(:expected) { [:background, :width, :margins].sort }
|
|
223
|
+
let(:expected) { [:background, :width, :vertical_align, :margins].sort }
|
|
215
224
|
|
|
216
225
|
it { expect(actual).to eq expected }
|
|
217
226
|
end
|
|
@@ -3,14 +3,15 @@ require 'spec_helper'
|
|
|
3
3
|
describe Caracal::Core::Models::TextModel do
|
|
4
4
|
subject do
|
|
5
5
|
described_class.new do
|
|
6
|
-
content
|
|
7
|
-
font
|
|
8
|
-
color
|
|
9
|
-
size
|
|
10
|
-
bold
|
|
11
|
-
italic
|
|
12
|
-
underline
|
|
13
|
-
bgcolor
|
|
6
|
+
content 'Lorem ipsum dolor....'
|
|
7
|
+
font 'Courier New'
|
|
8
|
+
color '666666'
|
|
9
|
+
size 20
|
|
10
|
+
bold false
|
|
11
|
+
italic false
|
|
12
|
+
underline true
|
|
13
|
+
bgcolor 'cccccc'
|
|
14
|
+
vertical_align :subscript
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
@@ -30,6 +31,7 @@ describe Caracal::Core::Models::TextModel do
|
|
|
30
31
|
it { expect(subject.text_italic).to eq false }
|
|
31
32
|
it { expect(subject.text_underline).to eq true }
|
|
32
33
|
it { expect(subject.text_bgcolor).to eq 'cccccc' }
|
|
34
|
+
it { expect(subject.text_vertical_align).to eq :subscript }
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
end
|
|
@@ -45,7 +47,7 @@ describe Caracal::Core::Models::TextModel do
|
|
|
45
47
|
|
|
46
48
|
# .run_attributes
|
|
47
49
|
describe '.run_attributes' do
|
|
48
|
-
let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
|
|
50
|
+
let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :subscript } }
|
|
49
51
|
|
|
50
52
|
it { expect(subject.run_attributes).to eq expected }
|
|
51
53
|
end
|
|
@@ -99,6 +101,12 @@ describe Caracal::Core::Models::TextModel do
|
|
|
99
101
|
it { expect(subject.text_font).to eq 'Palantino' }
|
|
100
102
|
end
|
|
101
103
|
|
|
104
|
+
#symbols
|
|
105
|
+
describe '.vertical_align' do
|
|
106
|
+
before { subject.vertical_align(:superscript) }
|
|
107
|
+
|
|
108
|
+
it { expect(subject.text_vertical_align).to eq :superscript }
|
|
109
|
+
end
|
|
102
110
|
|
|
103
111
|
#=============== VALIDATION ===========================
|
|
104
112
|
|
|
@@ -129,7 +137,7 @@ describe Caracal::Core::Models::TextModel do
|
|
|
129
137
|
# .option_keys
|
|
130
138
|
describe '.option_keys' do
|
|
131
139
|
let(:actual) { subject.send(:option_keys).sort }
|
|
132
|
-
let(:expected) { [:bgcolor, :bold, :color, :content, :font, :italic, :size, :underline].sort }
|
|
140
|
+
let(:expected) { [:bgcolor, :bold, :color, :content, :font, :italic, :size, :style, :underline, :vertical_align].sort }
|
|
133
141
|
|
|
134
142
|
it { expect(actual).to eq expected }
|
|
135
143
|
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Caracal::Core::Namespaces do
|
|
4
|
+
let(:m1) { Caracal::Core::Models::NamespaceModel.new({ prefix: 'com', href: 'http://www.example.com' }) }
|
|
5
|
+
let(:m2) { Caracal::Core::Models::NamespaceModel.new({ prefix: 'org', href: 'http://www.example.org' }) }
|
|
6
|
+
|
|
7
|
+
subject { Caracal::Document.new }
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
#-------------------------------------------------------------
|
|
11
|
+
# Class Methods
|
|
12
|
+
#-------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
describe 'public class tests' do
|
|
15
|
+
|
|
16
|
+
# .default_namespaces
|
|
17
|
+
describe '.default_namespaces' do
|
|
18
|
+
it { expect(subject.class.default_namespaces).to be_a(Array) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
#-------------------------------------------------------------
|
|
25
|
+
# Public Methods
|
|
26
|
+
#-------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
describe 'public method tests' do
|
|
29
|
+
|
|
30
|
+
#============== ATTRIBUTES =====================
|
|
31
|
+
|
|
32
|
+
# .namespace
|
|
33
|
+
describe '.namespace' do
|
|
34
|
+
it 'delegates to registration method' do
|
|
35
|
+
expect(subject).to receive(:register_namespace)
|
|
36
|
+
subject.namespace({ prefix: 'dummy', href: 'http://www.dummy.com' })
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#============== GETTERS ========================
|
|
42
|
+
|
|
43
|
+
# .namespaces
|
|
44
|
+
describe '.namespaces' do
|
|
45
|
+
it { expect(subject.namespaces).to be_a(Array) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# .find_namespace
|
|
49
|
+
describe '.find_namespace' do
|
|
50
|
+
let(:actual) { subject.find_namespace(key) }
|
|
51
|
+
|
|
52
|
+
before do
|
|
53
|
+
allow(subject).to receive(:namespaces).and_return([m1])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'when key is registered' do
|
|
57
|
+
let(:key) { m1.namespace_prefix }
|
|
58
|
+
|
|
59
|
+
it { expect(actual).to eq m1 }
|
|
60
|
+
end
|
|
61
|
+
describe 'when key is not registered' do
|
|
62
|
+
let(:key) { m2.namespace_prefix }
|
|
63
|
+
|
|
64
|
+
it { expect(actual).to eq nil }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
#============== REGISTRATION ========================
|
|
70
|
+
|
|
71
|
+
# .register_namespace
|
|
72
|
+
describe '.register_namespace' do
|
|
73
|
+
let(:default_length) { subject.class.default_namespaces.size }
|
|
74
|
+
|
|
75
|
+
describe 'when not already registered' do
|
|
76
|
+
before do
|
|
77
|
+
subject.register_namespace(m1)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it { expect(subject.namespaces.size).to eq default_length + 1 }
|
|
81
|
+
end
|
|
82
|
+
describe 'when already registered' do
|
|
83
|
+
before do
|
|
84
|
+
subject.register_namespace(m1)
|
|
85
|
+
subject.register_namespace(m1)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it { expect(subject.namespaces.size).to eq default_length + 1 }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# .unregister_namespace
|
|
93
|
+
describe '.unregister_namespace' do
|
|
94
|
+
let(:default_length) { subject.class.default_namespaces.size }
|
|
95
|
+
|
|
96
|
+
describe 'when registered' do
|
|
97
|
+
before do
|
|
98
|
+
subject.register_namespace(m1)
|
|
99
|
+
subject.unregister_namespace(m1.namespace_prefix)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it { expect(subject.namespaces.size).to eq default_length }
|
|
103
|
+
end
|
|
104
|
+
describe 'when not registered' do
|
|
105
|
+
before do
|
|
106
|
+
subject.register_namespace(m1)
|
|
107
|
+
subject.unregister_namespace(m2.namespace_prefix)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it { expect(subject.namespaces.size).to eq default_length + 1 }
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
@@ -2,79 +2,88 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Caracal::Core::PageSettings do
|
|
4
4
|
subject { Caracal::Document.new }
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
7
|
#-------------------------------------------------------------
|
|
8
8
|
# Configuration
|
|
9
9
|
#-------------------------------------------------------------
|
|
10
10
|
|
|
11
11
|
describe 'configuration tests' do
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
# constants
|
|
14
14
|
describe 'page number constants' do
|
|
15
15
|
it { expect(subject.class::DEFAULT_PAGE_NUMBER_ALIGN).to eq :center }
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
# readers
|
|
19
19
|
describe 'page number readers' do
|
|
20
|
-
it { expect(subject.page_number_show).to eq false }
|
|
21
20
|
it { expect(subject.page_number_align).to eq :center }
|
|
21
|
+
it { expect(subject.page_number_label).to eq nil }
|
|
22
|
+
it { expect(subject.page_number_show).to eq false }
|
|
22
23
|
end
|
|
23
|
-
|
|
24
|
+
|
|
24
25
|
end
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
|
|
27
28
|
#-------------------------------------------------------------
|
|
28
29
|
# Public Methods
|
|
29
30
|
#-------------------------------------------------------------
|
|
30
31
|
|
|
31
32
|
describe 'public methods tests' do
|
|
32
|
-
|
|
33
|
+
|
|
33
34
|
# .page_numbers
|
|
34
35
|
describe '.page_numbers' do
|
|
35
36
|
describe 'when nothing given' do
|
|
36
37
|
before { subject.page_numbers }
|
|
37
|
-
|
|
38
|
-
it { expect(subject.page_number_show).to eq false }
|
|
38
|
+
|
|
39
39
|
it { expect(subject.page_number_align).to eq :center }
|
|
40
|
+
it { expect(subject.page_number_label).to eq nil }
|
|
41
|
+
it { expect(subject.page_number_show).to eq false }
|
|
40
42
|
end
|
|
41
43
|
describe 'when explicitly turned off' do
|
|
42
44
|
before { subject.page_numbers false }
|
|
43
|
-
|
|
44
|
-
it { expect(subject.page_number_show).to eq false }
|
|
45
|
+
|
|
45
46
|
it { expect(subject.page_number_align).to eq :center }
|
|
47
|
+
it { expect(subject.page_number_label).to eq nil }
|
|
48
|
+
it { expect(subject.page_number_show).to eq false }
|
|
46
49
|
end
|
|
47
50
|
describe 'when options given' do
|
|
48
|
-
before { subject.page_numbers true, align: :left }
|
|
49
|
-
|
|
50
|
-
it { expect(subject.page_number_show).to eq true }
|
|
51
|
+
before { subject.page_numbers true, label: 'Custom Text', align: :left }
|
|
52
|
+
|
|
51
53
|
it { expect(subject.page_number_align).to eq :left }
|
|
54
|
+
it { expect(subject.page_number_label).to eq 'Custom Text' }
|
|
55
|
+
it { expect(subject.page_number_show).to eq true }
|
|
52
56
|
end
|
|
53
57
|
describe 'when block given' do
|
|
54
58
|
before do
|
|
55
59
|
subject.page_numbers true do
|
|
56
60
|
align :left
|
|
61
|
+
label 'More Text'
|
|
57
62
|
end
|
|
58
63
|
end
|
|
59
|
-
|
|
60
|
-
it { expect(subject.page_number_show).to eq true }
|
|
64
|
+
|
|
61
65
|
it { expect(subject.page_number_align).to eq :left }
|
|
66
|
+
it { expect(subject.page_number_label).to eq 'More Text' }
|
|
67
|
+
it { expect(subject.page_number_show).to eq true }
|
|
62
68
|
end
|
|
63
69
|
describe 'when fancy block given' do
|
|
64
70
|
subject do
|
|
65
71
|
Caracal::Document.new do |docx|
|
|
72
|
+
t = 'This is text'
|
|
66
73
|
a = :left
|
|
67
74
|
docx.page_numbers true do
|
|
75
|
+
label t
|
|
68
76
|
align a
|
|
69
77
|
end
|
|
70
78
|
end
|
|
71
79
|
end
|
|
72
|
-
|
|
73
|
-
it { expect(subject.page_number_show).to eq true }
|
|
80
|
+
|
|
74
81
|
it { expect(subject.page_number_align).to eq :left }
|
|
82
|
+
it { expect(subject.page_number_label).to eq 'This is text' }
|
|
83
|
+
it { expect(subject.page_number_show).to eq true }
|
|
75
84
|
end
|
|
76
85
|
end
|
|
77
|
-
|
|
86
|
+
|
|
78
87
|
end
|
|
79
|
-
|
|
80
|
-
end
|
|
88
|
+
|
|
89
|
+
end
|
|
@@ -2,18 +2,19 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Caracal::Core::PageSettings do
|
|
4
4
|
subject { Caracal::Document.new }
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
7
|
#-------------------------------------------------------------
|
|
8
8
|
# Configuration
|
|
9
9
|
#-------------------------------------------------------------
|
|
10
10
|
|
|
11
11
|
describe 'configuration tests' do
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
# readers
|
|
14
14
|
describe 'page size readers' do
|
|
15
15
|
it { expect(subject.page_width).to eq 12240 }
|
|
16
16
|
it { expect(subject.page_height).to eq 15840 }
|
|
17
|
+
it { expect(subject.page_orientation).to eq 'portrait' }
|
|
17
18
|
end
|
|
18
19
|
describe 'page margin readers' do
|
|
19
20
|
it { expect(subject.page_margin_top).to eq 1440 }
|
|
@@ -21,67 +22,74 @@ describe Caracal::Core::PageSettings do
|
|
|
21
22
|
it { expect(subject.page_margin_left).to eq 1440 }
|
|
22
23
|
it { expect(subject.page_margin_right).to eq 1440 }
|
|
23
24
|
end
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
end
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
|
|
28
29
|
#-------------------------------------------------------------
|
|
29
30
|
# Public Methods
|
|
30
31
|
#-------------------------------------------------------------
|
|
31
32
|
|
|
32
33
|
describe 'public methods tests' do
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
# .page_size
|
|
35
36
|
describe '.page_size' do
|
|
36
37
|
describe 'when options given' do
|
|
37
|
-
before { subject.page_size width: 10000, height: 12000 }
|
|
38
|
-
|
|
38
|
+
before { subject.page_size width: 10000, height: 12000, orientation: :landscape }
|
|
39
|
+
|
|
39
40
|
it { expect(subject.page_width).to eq 10000 }
|
|
40
41
|
it { expect(subject.page_height).to eq 12000 }
|
|
42
|
+
it { expect(subject.page_orientation).to eq 'landscape' }
|
|
41
43
|
end
|
|
42
44
|
describe 'when block given' do
|
|
43
45
|
before do
|
|
44
46
|
subject.page_size do
|
|
45
|
-
width
|
|
46
|
-
height
|
|
47
|
+
width 10000
|
|
48
|
+
height 12000
|
|
49
|
+
orientation :landscape
|
|
47
50
|
end
|
|
48
51
|
end
|
|
49
|
-
|
|
52
|
+
|
|
50
53
|
it { expect(subject.page_width).to eq 10000 }
|
|
51
54
|
it { expect(subject.page_height).to eq 12000 }
|
|
55
|
+
it { expect(subject.page_orientation).to eq 'landscape' }
|
|
52
56
|
end
|
|
53
57
|
describe 'when fancy block given' do
|
|
54
58
|
subject do
|
|
55
59
|
Caracal::Document.new do |docx|
|
|
56
60
|
w = 10000
|
|
57
61
|
h = 12000
|
|
62
|
+
o = :landscape
|
|
58
63
|
docx.page_size do
|
|
59
|
-
width
|
|
60
|
-
height
|
|
64
|
+
width w
|
|
65
|
+
height h
|
|
66
|
+
orientation o
|
|
61
67
|
end
|
|
62
68
|
end
|
|
63
69
|
end
|
|
64
|
-
|
|
70
|
+
|
|
65
71
|
it { expect(subject.page_width).to eq 10000 }
|
|
66
72
|
it { expect(subject.page_height).to eq 12000 }
|
|
73
|
+
it { expect(subject.page_orientation).to eq 'landscape' }
|
|
67
74
|
end
|
|
68
75
|
describe 'when both given' do
|
|
69
76
|
before do
|
|
70
|
-
subject.page_size width: 10000 do
|
|
77
|
+
subject.page_size width: 10000, orientation: :landscape do
|
|
71
78
|
height 12000
|
|
72
79
|
end
|
|
73
80
|
end
|
|
74
|
-
|
|
81
|
+
|
|
75
82
|
it { expect(subject.page_width).to eq 10000 }
|
|
76
83
|
it { expect(subject.page_height).to eq 12000 }
|
|
84
|
+
it { expect(subject.page_orientation).to eq 'landscape' }
|
|
77
85
|
end
|
|
78
86
|
end
|
|
79
|
-
|
|
87
|
+
|
|
80
88
|
# .page_margins
|
|
81
89
|
describe '.page_margins' do
|
|
82
90
|
describe 'when options given' do
|
|
83
91
|
before { subject.page_margins top: 1441, bottom: 1442, left: 1443, right: 1444 }
|
|
84
|
-
|
|
92
|
+
|
|
85
93
|
it { expect(subject.page_margin_top).to eq 1441 }
|
|
86
94
|
it { expect(subject.page_margin_bottom).to eq 1442 }
|
|
87
95
|
it { expect(subject.page_margin_left).to eq 1443 }
|
|
@@ -96,7 +104,7 @@ describe Caracal::Core::PageSettings do
|
|
|
96
104
|
right 1444
|
|
97
105
|
end
|
|
98
106
|
end
|
|
99
|
-
|
|
107
|
+
|
|
100
108
|
it { expect(subject.page_margin_top).to eq 1441 }
|
|
101
109
|
it { expect(subject.page_margin_bottom).to eq 1442 }
|
|
102
110
|
it { expect(subject.page_margin_left).to eq 1443 }
|
|
@@ -117,7 +125,7 @@ describe Caracal::Core::PageSettings do
|
|
|
117
125
|
end
|
|
118
126
|
end
|
|
119
127
|
end
|
|
120
|
-
|
|
128
|
+
|
|
121
129
|
it { expect(subject.page_margin_top).to eq 1441 }
|
|
122
130
|
it { expect(subject.page_margin_bottom).to eq 1442 }
|
|
123
131
|
it { expect(subject.page_margin_left).to eq 1443 }
|
|
@@ -130,14 +138,14 @@ describe Caracal::Core::PageSettings do
|
|
|
130
138
|
right 1444
|
|
131
139
|
end
|
|
132
140
|
end
|
|
133
|
-
|
|
141
|
+
|
|
134
142
|
it { expect(subject.page_margin_top).to eq 1441 }
|
|
135
143
|
it { expect(subject.page_margin_bottom).to eq 1442 }
|
|
136
144
|
it { expect(subject.page_margin_left).to eq 1443 }
|
|
137
145
|
it { expect(subject.page_margin_right).to eq 1444 }
|
|
138
146
|
end
|
|
139
147
|
end
|
|
140
|
-
|
|
148
|
+
|
|
141
149
|
end
|
|
142
|
-
|
|
143
|
-
end
|
|
150
|
+
|
|
151
|
+
end
|