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.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +95 -5
  4. data/README.md +171 -35
  5. data/caracal.gemspec +4 -4
  6. data/lib/caracal/core/custom_properties.rb +49 -0
  7. data/lib/caracal/core/iframes.rb +42 -0
  8. data/lib/caracal/core/ignorables.rb +47 -0
  9. data/lib/caracal/core/models/custom_property_model.rb +60 -0
  10. data/lib/caracal/core/models/iframe_model.rb +148 -0
  11. data/lib/caracal/core/models/namespace_model.rb +65 -0
  12. data/lib/caracal/core/models/page_break_model.rb +50 -4
  13. data/lib/caracal/core/models/page_number_model.rb +50 -24
  14. data/lib/caracal/core/models/page_size_model.rb +34 -25
  15. data/lib/caracal/core/models/paragraph_model.rb +11 -4
  16. data/lib/caracal/core/models/style_model.rb +44 -15
  17. data/lib/caracal/core/models/table_cell_model.rb +61 -50
  18. data/lib/caracal/core/models/table_model.rb +1 -1
  19. data/lib/caracal/core/models/text_model.rb +42 -20
  20. data/lib/caracal/core/namespaces.rb +89 -0
  21. data/lib/caracal/core/page_numbers.rb +22 -16
  22. data/lib/caracal/core/page_settings.rb +18 -16
  23. data/lib/caracal/document.rb +75 -58
  24. data/lib/caracal/renderers/content_types_renderer.rb +18 -17
  25. data/lib/caracal/renderers/core_renderer.rb +1 -1
  26. data/lib/caracal/renderers/custom_renderer.rb +64 -0
  27. data/lib/caracal/renderers/document_renderer.rb +205 -118
  28. data/lib/caracal/renderers/fonts_renderer.rb +2 -2
  29. data/lib/caracal/renderers/footer_renderer.rb +41 -20
  30. data/lib/caracal/renderers/numbering_renderer.rb +27 -26
  31. data/lib/caracal/renderers/package_relationships_renderer.rb +14 -13
  32. data/lib/caracal/renderers/settings_renderer.rb +5 -5
  33. data/lib/caracal/renderers/styles_renderer.rb +88 -73
  34. data/lib/caracal/renderers/xml_renderer.rb +20 -20
  35. data/lib/caracal/version.rb +1 -1
  36. data/lib/caracal.rb +11 -2
  37. data/spec/lib/caracal/core/iframes_spec.rb +29 -0
  38. data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
  39. data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
  40. data/spec/lib/caracal/core/models/image_model_spec.rb +60 -62
  41. data/spec/lib/caracal/core/models/link_model_spec.rb +12 -11
  42. data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
  43. data/spec/lib/caracal/core/models/page_number_model_spec.rb +66 -31
  44. data/spec/lib/caracal/core/models/page_size_model_spec.rb +42 -32
  45. data/spec/lib/caracal/core/models/style_model_spec.rb +32 -1
  46. data/spec/lib/caracal/core/models/table_cell_model_spec.rb +10 -1
  47. data/spec/lib/caracal/core/models/text_model_spec.rb +18 -10
  48. data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
  49. data/spec/lib/caracal/core/page_numbers_spec.rb +32 -23
  50. data/spec/lib/caracal/core/page_settings_spec.rb +33 -25
  51. data/spec/lib/caracal/core/relationships_spec.rb +47 -47
  52. data/spec/support/_fixtures/snippet.docx +0 -0
  53. metadata +28 -8
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::IFrameModel do
4
+ subject do
5
+ described_class.new do
6
+ url 'https://www.example.com/snippet.docx'
7
+ end
8
+ end
9
+
10
+
11
+
12
+ #-------------------------------------------------------------
13
+ # Configuration
14
+ #-------------------------------------------------------------
15
+
16
+ describe 'configuration tests' do
17
+
18
+ # accessors
19
+ describe 'accessors' do
20
+ it { expect(subject.iframe_url).to eq 'https://www.example.com/snippet.docx' }
21
+ end
22
+
23
+ end
24
+
25
+
26
+ #-------------------------------------------------------------
27
+ # Public Methods
28
+ #-------------------------------------------------------------
29
+
30
+ describe 'public method tests' do
31
+
32
+ #=============== SETTERS ==========================
33
+
34
+ # .url
35
+ describe '.url' do
36
+ before { subject.url('https://www.example.com/sample.docx') }
37
+
38
+ it { expect(subject.iframe_url).to eq 'https://www.example.com/sample.docx' }
39
+ end
40
+
41
+ # .data
42
+ describe '.data' do
43
+ before { subject.data('DOCX data follows here') }
44
+
45
+ it { expect(subject.iframe_data).to eq 'DOCX data follows here' }
46
+ end
47
+
48
+
49
+ #=============== VALIDATION ===========================
50
+
51
+ describe '.valid?' do
52
+ describe 'when either value present' do
53
+ it { expect(subject.valid?).to eq true }
54
+ end
55
+ describe 'when neither value present' do
56
+ before do
57
+ subject.url(nil)
58
+ subject.data(nil)
59
+ end
60
+ it { expect(subject.valid?).to eq false }
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+
67
+ #-------------------------------------------------------------
68
+ # Private Methods
69
+ #-------------------------------------------------------------
70
+
71
+ describe 'private method tests' do
72
+
73
+ # .option_keys
74
+ describe '.option_keys' do
75
+ let(:actual) { subject.send(:option_keys).sort }
76
+ let(:expected) { [:url, :data].sort }
77
+
78
+ it { expect(actual).to eq expected }
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Caracal::Core::Models::ImageModel do
4
- subject do
4
+ subject do
5
5
  described_class.new do
6
6
  url 'https://www.google.com/images/srpr/logo11w.png'
7
7
  ppi 96
@@ -14,15 +14,15 @@ describe Caracal::Core::Models::ImageModel do
14
14
  right 15
15
15
  end
16
16
  end
17
-
18
-
19
-
17
+
18
+
19
+
20
20
  #-------------------------------------------------------------
21
21
  # Configuration
22
22
  #-------------------------------------------------------------
23
23
 
24
24
  describe 'configuration tests' do
25
-
25
+
26
26
  # constants
27
27
  describe 'constants' do
28
28
  it { expect(described_class::DEFAULT_IMAGE_PPI).to eq 72 }
@@ -34,7 +34,7 @@ describe Caracal::Core::Models::ImageModel do
34
34
  it { expect(described_class::DEFAULT_IMAGE_LEFT).to eq 8 }
35
35
  it { expect(described_class::DEFAULT_IMAGE_RIGHT).to eq 8 }
36
36
  end
37
-
37
+
38
38
  # accessors
39
39
  describe 'accessors' do
40
40
  it { expect(subject.image_url).to eq 'https://www.google.com/images/srpr/logo11w.png' }
@@ -48,122 +48,120 @@ describe Caracal::Core::Models::ImageModel do
48
48
  it { expect(subject.image_left).to eq 14 }
49
49
  it { expect(subject.image_right).to eq 15 }
50
50
  end
51
-
51
+
52
52
  end
53
-
54
-
53
+
54
+
55
55
  #-------------------------------------------------------------
56
56
  # Public Methods
57
57
  #-------------------------------------------------------------
58
-
58
+
59
59
  describe 'public method tests' do
60
-
60
+
61
61
  #=============== GETTERS ==========================
62
-
62
+
63
63
  # emu conversions (dimensions)
64
64
  [:width, :height].each do |m|
65
65
  describe ".formatted_#{ m }" do
66
66
  let(:actual) { subject.send("formatted_#{ m }") }
67
-
67
+
68
68
  before do
69
69
  allow(subject).to receive("image_#{ m }").and_return(540)
70
70
  allow(subject).to receive("image_ppi").and_return(96)
71
71
  end
72
-
72
+
73
73
  it { expect(actual).to eq 5143500 }
74
74
  end
75
75
  end
76
-
76
+
77
77
  # emu conversions (margins)
78
78
  [:top, :bottom, :left, :right].each do |m|
79
79
  describe ".formatted_#{ m }" do
80
80
  let(:actual) { subject.send("formatted_#{ m }") }
81
-
81
+
82
82
  before { allow(subject).to receive("image_#{ m }").and_return(9) }
83
-
83
+
84
84
  it { expect(actual).to eq 114300 }
85
85
  end
86
86
  end
87
-
88
- # .relationship_target
89
-
90
-
91
-
87
+
88
+
89
+
92
90
  #=============== SETTERS ==========================
93
-
91
+
94
92
  # .url
95
- describe '.color' do
93
+ describe '.url' do
96
94
  before { subject.url('https://www.google.com/images/dummy.png') }
97
-
95
+
98
96
  it { expect(subject.image_url).to eq 'https://www.google.com/images/dummy.png' }
99
97
  end
100
-
98
+
101
99
  # .data
102
100
  describe '.data' do
103
101
  before { subject.data('PNG Data follows here') }
104
-
102
+
105
103
  it { expect(subject.image_data).to eq 'PNG Data follows here' }
106
104
  end
107
-
105
+
108
106
  # .ppi
109
107
  describe '.ppi' do
110
108
  before { subject.ppi(108) }
111
-
109
+
112
110
  it { expect(subject.image_ppi).to eq 108 }
113
111
  end
114
-
112
+
115
113
  # .width
116
114
  describe '.width' do
117
115
  before { subject.width(300) }
118
-
116
+
119
117
  it { expect(subject.image_width).to eq 300 }
120
118
  end
121
-
119
+
122
120
  # .height
123
121
  describe '.height' do
124
122
  before { subject.height(400) }
125
-
123
+
126
124
  it { expect(subject.image_height).to eq 400 }
127
125
  end
128
-
126
+
129
127
  # .align
130
128
  describe '.align' do
131
129
  before { subject.align(:center) }
132
-
130
+
133
131
  it { expect(subject.image_align).to eq :center }
134
132
  end
135
-
133
+
136
134
  # .top
137
135
  describe '.top' do
138
136
  before { subject.top(12) }
139
-
137
+
140
138
  it { expect(subject.image_top).to eq 12 }
141
139
  end
142
-
140
+
143
141
  # .bottom
144
142
  describe '.bottom' do
145
143
  before { subject.bottom(12) }
146
-
144
+
147
145
  it { expect(subject.image_bottom).to eq 12 }
148
146
  end
149
-
147
+
150
148
  # .left
151
149
  describe '.left' do
152
150
  before { subject.left(12) }
153
-
151
+
154
152
  it { expect(subject.image_left).to eq 12 }
155
153
  end
156
-
154
+
157
155
  # .right
158
156
  describe '.right' do
159
157
  before { subject.right(12) }
160
-
158
+
161
159
  it { expect(subject.image_right).to eq 12 }
162
160
  end
163
-
164
-
161
+
162
+
165
163
  #=============== VALIDATION ===========================
166
-
164
+
167
165
  describe '.valid?' do
168
166
  describe 'when all values okay' do
169
167
  it { expect(subject.valid?).to eq true }
@@ -173,55 +171,55 @@ describe Caracal::Core::Models::ImageModel do
173
171
  before do
174
172
  allow(subject).to receive("image_#{ d }").and_return(0)
175
173
  end
176
-
174
+
177
175
  it { expect(subject.valid?).to eq false }
178
176
  end
179
177
  end
180
178
  end
181
-
179
+
182
180
  end
183
-
184
-
181
+
182
+
185
183
  #-------------------------------------------------------------
186
184
  # Private Methods
187
185
  #-------------------------------------------------------------
188
-
186
+
189
187
  describe 'private method tests' do
190
-
188
+
191
189
  # .option_keys
192
190
  describe '.option_keys' do
193
191
  let(:actual) { subject.send(:option_keys).sort }
194
192
  let(:expected) { [:url, :width, :height, :align, :top, :bottom, :left, :right].sort }
195
-
193
+
196
194
  it { expect(actual).to eq expected }
197
195
  end
198
-
196
+
199
197
  # .pixels_to_emus
200
198
  describe '.pixels_to_emus' do
201
199
  let(:actual) { subject.send(:pixels_to_emus, value, 72) }
202
-
200
+
203
201
  describe 'when argument is nil' do
204
202
  let(:value) { nil }
205
-
203
+
206
204
  it { expect(actual).to eq 0 }
207
205
  end
208
206
  describe 'when argument is NaN' do
209
207
  let(:value) { 'a' }
210
-
208
+
211
209
  it { expect(actual).to eq 0 }
212
210
  end
213
211
  describe 'when argument is rational' do
214
212
  let(:value) { 396.1 }
215
-
213
+
216
214
  it { expect(actual).to eq 5029200 }
217
215
  end
218
216
  describe 'when argument is integer' do
219
217
  let(:value) { 396 }
220
-
218
+
221
219
  it { expect(actual).to eq 5029200 }
222
220
  end
223
221
  end
224
-
222
+
225
223
  end
226
-
227
- end
224
+
225
+ end
@@ -3,15 +3,16 @@ require 'spec_helper'
3
3
  describe Caracal::Core::Models::LinkModel do
4
4
  subject do
5
5
  described_class.new do
6
- content 'Link Text'
7
- href 'http://www.google.com'
8
- font 'Courier New'
9
- color '666666'
10
- size 20
11
- bold false
12
- italic false
13
- underline true
14
- bgcolor 'cccccc'
6
+ content 'Link Text'
7
+ href 'http://www.google.com'
8
+ font 'Courier New'
9
+ color '666666'
10
+ size 20
11
+ bold false
12
+ italic false
13
+ underline true
14
+ bgcolor 'cccccc'
15
+ vertical_align :top
15
16
  end
16
17
  end
17
18
 
@@ -53,7 +54,7 @@ describe Caracal::Core::Models::LinkModel do
53
54
 
54
55
  # .run_attributes
55
56
  describe '.run_attributes' do
56
- let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
57
+ let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :top } }
57
58
 
58
59
  it { expect(subject.run_attributes).to eq expected }
59
60
  end
@@ -142,7 +143,7 @@ describe Caracal::Core::Models::LinkModel do
142
143
  # .option_keys
143
144
  describe '.option_keys' do
144
145
  let(:actual) { subject.send(:option_keys).sort }
145
- let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline, :bgcolor].sort }
146
+ let(:expected) { [:content, :href, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align].sort }
146
147
 
147
148
  it { expect(actual).to eq expected }
148
149
  end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::NamespaceModel do
4
+ subject do
5
+ described_class.new do
6
+ prefix 'com'
7
+ href 'http://www.example.com'
8
+ end
9
+ end
10
+
11
+
12
+ #-------------------------------------------------------------
13
+ # Configuration
14
+ #-------------------------------------------------------------
15
+
16
+ describe 'configuration tests' do
17
+
18
+ # accessors
19
+ describe 'accessors' do
20
+ it { expect(subject.namespace_prefix).to eq 'com' }
21
+ it { expect(subject.namespace_href).to eq 'http://www.example.com' }
22
+ end
23
+
24
+ end
25
+
26
+
27
+ #-------------------------------------------------------------
28
+ # Public Methods
29
+ #-------------------------------------------------------------
30
+
31
+ describe 'public method tests' do
32
+
33
+ #=================== ATTRIBUTES ==========================
34
+
35
+ # .prefix
36
+ describe '.prefix' do
37
+ before do
38
+ subject.prefix('org')
39
+ end
40
+
41
+ it { expect(subject.namespace_prefix).to eq 'org' }
42
+ end
43
+
44
+ # .href
45
+ describe '.href' do
46
+ before do
47
+ subject.href('http://www.example.org')
48
+ end
49
+
50
+ it { expect(subject.namespace_href).to eq 'http://www.example.org' }
51
+ end
52
+
53
+
54
+ #=================== STATE ===============================
55
+
56
+ # .matches?
57
+ describe '.matches?' do
58
+ describe 'when search term matches key' do
59
+ let(:actual) { subject.matches?('com') }
60
+
61
+ it { expect(actual).to eq true }
62
+ end
63
+ describe 'when search term does not match key' do
64
+ let(:actual) { subject.matches?('org') }
65
+
66
+ it { expect(actual).to eq false }
67
+ end
68
+ end
69
+
70
+
71
+ #=============== VALIDATION ===========================
72
+
73
+ describe '.valid?' do
74
+ describe 'when prefix and href provided' do
75
+ it { expect(subject.valid?).to eq true }
76
+ end
77
+ [:prefix, :href].each do |prop|
78
+ describe "when #{ prop } nil" do
79
+ before do
80
+ allow(subject).to receive("namespace_#{ prop }").and_return(nil)
81
+ end
82
+
83
+ it { expect(subject.valid?).to eq false }
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+
91
+ #-------------------------------------------------------------
92
+ # Private Methods
93
+ #-------------------------------------------------------------
94
+
95
+ describe 'private method tests' do
96
+
97
+ # .option_keys
98
+ describe '.option_keys' do
99
+ let(:actual) { subject.send(:option_keys).sort }
100
+ let(:expected) { [:prefix, :href].sort }
101
+
102
+ it { expect(actual).to eq expected }
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -1,64 +1,99 @@
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
- show true
7
- align :right
6
+ show true
7
+ align :right
8
+ label 'Page'
9
+ label_size 24
10
+ number_size 20
8
11
  end
9
12
  end
10
-
13
+
11
14
  #-------------------------------------------------------------
12
15
  # Configuration
13
16
  #-------------------------------------------------------------
14
17
 
15
18
  describe 'configuration tests' do
16
-
19
+
17
20
  # constants
18
21
  describe 'constants' do
19
22
  it { expect(described_class::DEFAULT_PAGE_NUMBER_ALIGN).to eq :center }
20
23
  end
21
-
24
+
22
25
  # accessors
23
26
  describe 'accessors' do
24
27
  it { expect(subject.page_number_align).to eq :right }
28
+ it { expect(subject.page_number_label).to eq 'Page' }
29
+ it { expect(subject.page_number_label_size).to eq 24 }
30
+ it { expect(subject.page_number_number_size).to eq 20 }
25
31
  it { expect(subject.page_number_show).to eq true }
26
32
  end
27
-
33
+
28
34
  end
29
-
30
-
35
+
36
+
31
37
  #-------------------------------------------------------------
32
38
  # Public Methods
33
39
  #-------------------------------------------------------------
34
-
40
+
35
41
  describe 'public method tests' do
36
-
42
+
37
43
  #=============== SETTERS ==============================
38
-
44
+
39
45
  # .align
40
46
  describe '.align' do
41
47
  before { subject.align(:left) }
42
-
48
+
43
49
  it { expect(subject.page_number_align).to eq :left }
44
50
  end
45
-
51
+
52
+ # .label
53
+ describe '.label' do
54
+ before { subject.label('Page') }
55
+
56
+ it { expect(subject.page_number_label).to eq 'Page' }
57
+ end
58
+
59
+ # .label_size
60
+ describe '.label_size' do
61
+ before { subject.label_size(28) }
62
+
63
+ it { expect(subject.page_number_label_size).to eq 28 }
64
+ end
65
+
66
+ # .number_size
67
+ describe '.number_size' do
68
+ before { subject.number_size(28) }
69
+
70
+ it { expect(subject.page_number_number_size).to eq 28 }
71
+ end
72
+
46
73
  # .show
47
74
  describe '.show' do
48
75
  before { subject.show(true) }
49
-
76
+
50
77
  it { expect(subject.page_number_show).to eq true }
51
78
  end
52
-
53
-
79
+
80
+ # .size
81
+ describe '.size' do
82
+ before { subject.size(32) }
83
+
84
+ it { expect(subject.page_number_label_size).to eq 32 }
85
+ it { expect(subject.page_number_number_size).to eq 32 }
86
+ end
87
+
88
+
54
89
  #=============== VALIDATIONS ==========================
55
-
90
+
56
91
  describe '.valid?' do
57
92
  describe 'when show is false' do
58
93
  before do
59
94
  allow(subject).to receive(:page_number_show).and_return(false)
60
95
  end
61
-
96
+
62
97
  it { expect(subject.valid?).to eq true }
63
98
  end
64
99
  describe 'when show is true and align is valid' do
@@ -66,7 +101,7 @@ describe Caracal::Core::Models::PageNumberModel do
66
101
  allow(subject).to receive(:page_number_show).and_return(true)
67
102
  allow(subject).to receive(:page_number_align).and_return(:left)
68
103
  end
69
-
104
+
70
105
  it { expect(subject.valid?).to eq true }
71
106
  end
72
107
  describe 'when show is true and align is invalid' do
@@ -74,28 +109,28 @@ describe Caracal::Core::Models::PageNumberModel do
74
109
  allow(subject).to receive(:page_number_show).and_return(true)
75
110
  allow(subject).to receive(:page_number_align).and_return(:dummy)
76
111
  end
77
-
112
+
78
113
  it { expect(subject.valid?).to eq false }
79
114
  end
80
115
  end
81
-
116
+
82
117
  end
83
-
84
-
118
+
119
+
85
120
  #-------------------------------------------------------------
86
121
  # Private Methods
87
122
  #-------------------------------------------------------------
88
-
123
+
89
124
  describe 'private method tests' do
90
-
125
+
91
126
  # .option_keys
92
127
  describe '.option_keys' do
93
128
  let(:actual) { subject.send(:option_keys).sort }
94
- let(:expected) { [:align, :show].sort }
95
-
129
+ let(:expected) { [:align, :label, :label_size, :number_size, :show].sort }
130
+
96
131
  it { expect(actual).to eq expected }
97
132
  end
98
-
133
+
99
134
  end
100
-
101
- end
135
+
136
+ end