caracal 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/caracal/core/models/page_number_model.rb +29 -23
- data/lib/caracal/core/page_numbers.rb +16 -14
- data/lib/caracal/renderers/footer_renderer.rb +19 -9
- data/lib/caracal/version.rb +1 -1
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +38 -29
- data/spec/lib/caracal/core/page_numbers_spec.rb +32 -23
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d2efc2b19a3ae0483703f88497fb42bbf876f9e
|
4
|
+
data.tar.gz: 2dcd3fb0074ddc334878eb00339dc27ad7ec30aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5539dbe580138147f1c3c036d2147790085178a4fd2b60dfb54e0b545fab050f52a1c10bf5ff591354c6d14712ce8ff9f8f5a31254adee2a60abf4b781be59c5
|
7
|
+
data.tar.gz: 39f1c998d281aaa798f52310c4346721e1e39e81d1c4821ad99c6d7026603a27a0c3bba8d9804a45f6977404907de3badd9b1d57c674781e458ca659405411b2
|
data/README.md
CHANGED
@@ -301,12 +301,13 @@ docx.page # starts a new page.
|
|
301
301
|
|
302
302
|
### Page Numbers
|
303
303
|
|
304
|
-
Page numbers can be added to the footer via the `page_numbers` method. The method accepts
|
304
|
+
Page numbers can be added to the footer via the `page_numbers` method. The method accepts optional parameters for controlling the label and alignment of the text.
|
305
305
|
|
306
306
|
*Page numbers are turned off by default.*
|
307
307
|
|
308
308
|
```ruby
|
309
309
|
docx.page_numbers true do
|
310
|
+
label 'Page' # sets the text that will go to the left of the page number. Defaults to nil.
|
310
311
|
align :right # sets the alignment. accepts :left, :center, and :right.
|
311
312
|
end
|
312
313
|
```
|
@@ -4,66 +4,72 @@ require 'caracal/core/models/base_model'
|
|
4
4
|
module Caracal
|
5
5
|
module Core
|
6
6
|
module Models
|
7
|
-
|
7
|
+
|
8
8
|
# This class handles block options passed to the page_numbers
|
9
9
|
# method.
|
10
10
|
#
|
11
11
|
class PageNumberModel < BaseModel
|
12
|
-
|
12
|
+
|
13
13
|
#-------------------------------------------------------------
|
14
14
|
# Configuration
|
15
15
|
#-------------------------------------------------------------
|
16
|
-
|
16
|
+
|
17
17
|
# constants
|
18
|
-
const_set(:DEFAULT_PAGE_NUMBER_SHOW, false)
|
19
18
|
const_set(:DEFAULT_PAGE_NUMBER_ALIGN, :center)
|
20
|
-
|
19
|
+
const_set(:DEFAULT_PAGE_NUMBER_SHOW, false)
|
20
|
+
|
21
21
|
# accessors
|
22
22
|
attr_reader :page_number_align
|
23
|
+
attr_reader :page_number_label
|
23
24
|
attr_reader :page_number_show
|
24
|
-
|
25
|
+
|
25
26
|
# initialization
|
26
27
|
def initialize(options={}, &block)
|
27
|
-
@page_number_show = DEFAULT_PAGE_NUMBER_SHOW
|
28
28
|
@page_number_align = DEFAULT_PAGE_NUMBER_ALIGN
|
29
|
-
|
29
|
+
@page_number_label = nil
|
30
|
+
@page_number_show = DEFAULT_PAGE_NUMBER_SHOW
|
31
|
+
|
30
32
|
super options, &block
|
31
33
|
end
|
32
|
-
|
33
|
-
|
34
|
+
|
35
|
+
|
34
36
|
#-------------------------------------------------------------
|
35
37
|
# Public Methods
|
36
38
|
#-------------------------------------------------------------
|
37
|
-
|
39
|
+
|
38
40
|
#=============== SETTERS ==============================
|
39
|
-
|
41
|
+
|
40
42
|
def align(value)
|
41
43
|
@page_number_align = value.to_s.to_sym
|
42
44
|
end
|
43
|
-
|
45
|
+
|
46
|
+
def label(value)
|
47
|
+
@page_number_label = value.to_s.strip # renderer will enforce trailing space
|
48
|
+
end
|
49
|
+
|
44
50
|
def show(value)
|
45
51
|
@page_number_show = !!value
|
46
52
|
end
|
47
|
-
|
48
|
-
|
53
|
+
|
54
|
+
|
49
55
|
#=============== VALIDATION ===========================
|
50
|
-
|
56
|
+
|
51
57
|
def valid?
|
52
58
|
(!page_number_show || [:left, :center, :right].include?(page_number_align))
|
53
59
|
end
|
54
|
-
|
55
|
-
|
60
|
+
|
61
|
+
|
56
62
|
#-------------------------------------------------------------
|
57
63
|
# Private Instance Methods
|
58
64
|
#-------------------------------------------------------------
|
59
65
|
private
|
60
|
-
|
66
|
+
|
61
67
|
def option_keys
|
62
|
-
[:align, :show]
|
68
|
+
[:align, :label, :show]
|
63
69
|
end
|
64
|
-
|
70
|
+
|
65
71
|
end
|
66
|
-
|
72
|
+
|
67
73
|
end
|
68
74
|
end
|
69
|
-
end
|
75
|
+
end
|
@@ -4,49 +4,51 @@ require 'caracal/errors'
|
|
4
4
|
|
5
5
|
module Caracal
|
6
6
|
module Core
|
7
|
-
|
8
|
-
# This module encapsulates all the functionality related to setting the
|
7
|
+
|
8
|
+
# This module encapsulates all the functionality related to setting the
|
9
9
|
# document's page number behavior.
|
10
10
|
#
|
11
11
|
module PageNumbers
|
12
12
|
def self.included(base)
|
13
13
|
base.class_eval do
|
14
|
-
|
14
|
+
|
15
15
|
#-------------------------------------------------------------
|
16
16
|
# Configuration
|
17
17
|
#-------------------------------------------------------------
|
18
|
-
|
18
|
+
|
19
19
|
# constants
|
20
20
|
const_set(:DEFAULT_PAGE_NUMBER_ALIGN, :center)
|
21
|
-
|
21
|
+
|
22
22
|
# accessors
|
23
|
-
attr_reader :page_number_show
|
24
23
|
attr_reader :page_number_align
|
25
|
-
|
26
|
-
|
24
|
+
attr_reader :page_number_label
|
25
|
+
attr_reader :page_number_show
|
26
|
+
|
27
|
+
|
27
28
|
#-------------------------------------------------------------
|
28
29
|
# Public Methods
|
29
30
|
#-------------------------------------------------------------
|
30
|
-
|
31
|
+
|
31
32
|
# This method controls whether and how page numbers are displayed
|
32
33
|
# on the document.
|
33
34
|
#
|
34
35
|
def page_numbers(*args, &block)
|
35
36
|
options = Caracal::Utilities.extract_options!(args)
|
36
37
|
options.merge!({ show: !!args.first }) unless args.first.nil? # careful: falsey value
|
37
|
-
|
38
|
+
|
38
39
|
model = Caracal::Core::Models::PageNumberModel.new(options, &block)
|
39
40
|
if model.valid?
|
40
|
-
@page_number_show = model.page_number_show
|
41
41
|
@page_number_align = model.page_number_align
|
42
|
+
@page_number_label = model.page_number_label
|
43
|
+
@page_number_show = model.page_number_show
|
42
44
|
else
|
43
45
|
raise Caracal::Errors::InvalidModelError, 'page_numbers :align parameter must be :left, :center, or :right'
|
44
46
|
end
|
45
47
|
end
|
46
|
-
|
48
|
+
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
50
|
-
|
52
|
+
|
51
53
|
end
|
52
|
-
end
|
54
|
+
end
|
@@ -6,12 +6,12 @@ require 'caracal/renderers/xml_renderer'
|
|
6
6
|
module Caracal
|
7
7
|
module Renderers
|
8
8
|
class FooterRenderer < XmlRenderer
|
9
|
-
|
9
|
+
|
10
10
|
#-------------------------------------------------------------
|
11
11
|
# Public Methods
|
12
12
|
#-------------------------------------------------------------
|
13
|
-
|
14
|
-
# This method produces the xml required for the `word/settings.xml`
|
13
|
+
|
14
|
+
# This method produces the xml required for the `word/settings.xml`
|
15
15
|
# sub-document.
|
16
16
|
#
|
17
17
|
def to_xml
|
@@ -22,6 +22,16 @@ module Caracal
|
|
22
22
|
xml.send 'w:contextualSpacing', { 'w:val' => '0' }
|
23
23
|
xml.send 'w:jc', { 'w:val' => "#{ document.page_number_align }" }
|
24
24
|
end
|
25
|
+
if document.page_number_label.present?
|
26
|
+
xml.send 'w:r', run_options do
|
27
|
+
xml.send 'w:rPr' do
|
28
|
+
xml.send 'w:rStyle', { 'w:val' => 'PageNumber' }
|
29
|
+
end
|
30
|
+
xml.send 'w:t', { 'xml:space' => 'preserve' } do
|
31
|
+
xml.text "#{ document.page_number_label } "
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
25
35
|
xml.send 'w:fldSimple', { 'w:dirty' => '0', 'w:instr' => 'PAGE', 'w:fldLock' => '0' } do
|
26
36
|
xml.send 'w:r', run_options do
|
27
37
|
xml.send 'w:rPr'
|
@@ -37,13 +47,13 @@ module Caracal
|
|
37
47
|
end
|
38
48
|
builder.to_xml(save_options)
|
39
49
|
end
|
40
|
-
|
41
|
-
|
50
|
+
|
51
|
+
|
42
52
|
#-------------------------------------------------------------
|
43
53
|
# Private Methods
|
44
|
-
#-------------------------------------------------------------
|
54
|
+
#-------------------------------------------------------------
|
45
55
|
private
|
46
|
-
|
56
|
+
|
47
57
|
def root_options
|
48
58
|
{
|
49
59
|
'xmlns:mc' => 'http://schemas.openxmlformats.org/markup-compatibility/2006',
|
@@ -63,7 +73,7 @@ module Caracal
|
|
63
73
|
'xmlns:dgm' => 'http://schemas.openxmlformats.org/drawingml/2006/diagram'
|
64
74
|
}
|
65
75
|
end
|
66
|
-
|
76
|
+
|
67
77
|
end
|
68
78
|
end
|
69
|
-
end
|
79
|
+
end
|
data/lib/caracal/version.rb
CHANGED
@@ -1,64 +1,73 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Caracal::Core::Models::PageNumberModel do
|
4
|
-
subject do
|
4
|
+
subject do
|
5
5
|
described_class.new do
|
6
6
|
show true
|
7
7
|
align :right
|
8
|
+
label 'Page'
|
8
9
|
end
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
#-------------------------------------------------------------
|
12
13
|
# Configuration
|
13
14
|
#-------------------------------------------------------------
|
14
15
|
|
15
16
|
describe 'configuration tests' do
|
16
|
-
|
17
|
+
|
17
18
|
# constants
|
18
19
|
describe 'constants' do
|
19
20
|
it { expect(described_class::DEFAULT_PAGE_NUMBER_ALIGN).to eq :center }
|
20
21
|
end
|
21
|
-
|
22
|
+
|
22
23
|
# accessors
|
23
24
|
describe 'accessors' do
|
24
25
|
it { expect(subject.page_number_align).to eq :right }
|
26
|
+
it { expect(subject.page_number_label).to eq 'Page' }
|
25
27
|
it { expect(subject.page_number_show).to eq true }
|
26
28
|
end
|
27
|
-
|
29
|
+
|
28
30
|
end
|
29
|
-
|
30
|
-
|
31
|
+
|
32
|
+
|
31
33
|
#-------------------------------------------------------------
|
32
34
|
# Public Methods
|
33
35
|
#-------------------------------------------------------------
|
34
|
-
|
36
|
+
|
35
37
|
describe 'public method tests' do
|
36
|
-
|
38
|
+
|
37
39
|
#=============== SETTERS ==============================
|
38
|
-
|
40
|
+
|
39
41
|
# .align
|
40
42
|
describe '.align' do
|
41
43
|
before { subject.align(:left) }
|
42
|
-
|
44
|
+
|
43
45
|
it { expect(subject.page_number_align).to eq :left }
|
44
46
|
end
|
45
|
-
|
47
|
+
|
48
|
+
# .label
|
49
|
+
describe '.label' do
|
50
|
+
before { subject.label('Page') }
|
51
|
+
|
52
|
+
it { expect(subject.page_number_label).to eq 'Page' }
|
53
|
+
end
|
54
|
+
|
46
55
|
# .show
|
47
56
|
describe '.show' do
|
48
57
|
before { subject.show(true) }
|
49
|
-
|
58
|
+
|
50
59
|
it { expect(subject.page_number_show).to eq true }
|
51
60
|
end
|
52
|
-
|
53
|
-
|
61
|
+
|
62
|
+
|
54
63
|
#=============== VALIDATIONS ==========================
|
55
|
-
|
64
|
+
|
56
65
|
describe '.valid?' do
|
57
66
|
describe 'when show is false' do
|
58
67
|
before do
|
59
68
|
allow(subject).to receive(:page_number_show).and_return(false)
|
60
69
|
end
|
61
|
-
|
70
|
+
|
62
71
|
it { expect(subject.valid?).to eq true }
|
63
72
|
end
|
64
73
|
describe 'when show is true and align is valid' do
|
@@ -66,7 +75,7 @@ describe Caracal::Core::Models::PageNumberModel do
|
|
66
75
|
allow(subject).to receive(:page_number_show).and_return(true)
|
67
76
|
allow(subject).to receive(:page_number_align).and_return(:left)
|
68
77
|
end
|
69
|
-
|
78
|
+
|
70
79
|
it { expect(subject.valid?).to eq true }
|
71
80
|
end
|
72
81
|
describe 'when show is true and align is invalid' do
|
@@ -74,28 +83,28 @@ describe Caracal::Core::Models::PageNumberModel do
|
|
74
83
|
allow(subject).to receive(:page_number_show).and_return(true)
|
75
84
|
allow(subject).to receive(:page_number_align).and_return(:dummy)
|
76
85
|
end
|
77
|
-
|
86
|
+
|
78
87
|
it { expect(subject.valid?).to eq false }
|
79
88
|
end
|
80
89
|
end
|
81
|
-
|
90
|
+
|
82
91
|
end
|
83
|
-
|
84
|
-
|
92
|
+
|
93
|
+
|
85
94
|
#-------------------------------------------------------------
|
86
95
|
# Private Methods
|
87
96
|
#-------------------------------------------------------------
|
88
|
-
|
97
|
+
|
89
98
|
describe 'private method tests' do
|
90
|
-
|
99
|
+
|
91
100
|
# .option_keys
|
92
101
|
describe '.option_keys' do
|
93
102
|
let(:actual) { subject.send(:option_keys).sort }
|
94
|
-
let(:expected) { [:align, :show].sort }
|
95
|
-
|
103
|
+
let(:expected) { [:align, :label, :show].sort }
|
104
|
+
|
96
105
|
it { expect(actual).to eq expected }
|
97
106
|
end
|
98
|
-
|
107
|
+
|
99
108
|
end
|
100
|
-
|
101
|
-
end
|
109
|
+
|
110
|
+
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caracal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trade Infomatics
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
version: '0'
|
221
221
|
requirements: []
|
222
222
|
rubyforge_project:
|
223
|
-
rubygems_version: 2.
|
223
|
+
rubygems_version: 2.6.12
|
224
224
|
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: Fast, professional MSWord writer for Ruby.
|
@@ -260,4 +260,3 @@ test_files:
|
|
260
260
|
- spec/lib/caracal/core/text_spec.rb
|
261
261
|
- spec/lib/caracal/errors_spec.rb
|
262
262
|
- spec/spec_helper.rb
|
263
|
-
has_rdoc:
|