caracal_the_curve 1.4.2 → 1.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1d56aaed7b0a4ebaa54b3e1ec9676a9b1ad7623f3731fcaf39f5b36dbfc9aa8
4
- data.tar.gz: aaee3a57ce1de0605812daf5fb1723b591df0ade1258d01e198b6fef14b7faa9
3
+ metadata.gz: e6da04caa966ebd5e16ea4750f12f96ac92671bc5398040ffac7634c0ace0430
4
+ data.tar.gz: d22baa3abb96b9a569864e414542d5aacdcff42c42cf71586c95a5c4e855afd0
5
5
  SHA512:
6
- metadata.gz: a70c88b1cb4b1ced216bbc9d2f6b30557e05a951e9021ec1996c79f8243ea3920b7b1a61cfb391e119748bf4aa3c506606b141814d906f9787d38d854da2b23f
7
- data.tar.gz: '01650682a67a3e887eef14c14c7145eebd28afec184aa75214575711a6998d8ca6048bd517ac73100b79ca53d1fd8e12c2633c881cd389b90ec4fa88ad6dc69f'
6
+ metadata.gz: 700413b3717f24148a68d6d211a817f70dbf1991871942981c8eada98be9a63d629c88c281e8bdb55b328536bccdb1e1bbec23e64057c86648973630aaa9aad9
7
+ data.tar.gz: 742d487ca24ab7f5aba5a71b844fe9ac42a3a15bde8ba327d6d3b8b7a396dbba5e62036436e71541e1ac13baf5461096164b195b3688b8b685109bbb51d896ea
@@ -15,7 +15,7 @@ module Caracal
15
15
  #--------------------------------------------------
16
16
 
17
17
  # constants
18
- const_set(:TYPE_MAP, { page: 'PAGE', numpages: 'NUMPAGES', table_of_contents: 'TOC \o "1-1" \h \z \u \t "Heading 5,1"' })
18
+ const_set(:TYPE_MAP, { page: 'PAGE', numpages: 'NUMPAGES' })
19
19
 
20
20
  # accessors
21
21
  attr_reader :field_dirty
@@ -0,0 +1,81 @@
1
+ require 'caracal/core/models/base_model'
2
+
3
+
4
+ module Caracal
5
+ module Core
6
+ module Models
7
+
8
+ # This class encapsulates the logic needed to store and manipulate
9
+ # text data.
10
+ #
11
+ class TableOfContentsModel < BaseModel
12
+
13
+ #--------------------------------------------------
14
+ # Configuration
15
+ #--------------------------------------------------
16
+
17
+ # constants
18
+ const_set(:DEFAULT_OPTS, 'TOC \o "1-1" \h \z \u \t "Heading 5,1"')
19
+ const_set(:DEFAULT_SIZE, 32)
20
+ const_set(:DEFAULT_TITLE, 'Table of Contents')
21
+
22
+ # accessors
23
+ attr_reader :toc_opts
24
+ attr_reader :toc_size
25
+ attr_reader :toc_title
26
+
27
+ #-------------------------------------------------------------
28
+ # Public Class Methods
29
+ #-------------------------------------------------------------
30
+
31
+ # initialization
32
+ def initialize(options={}, &block)
33
+ @toc_opts ||= DEFAULT_OPTS
34
+ @toc_size ||= DEFAULT_SIZE
35
+ @toc_title ||= DEFAULT_TITLE
36
+ super options, &block
37
+ end
38
+
39
+ #-------------------------------------------------------------
40
+ # Public Instance Methods
41
+ #-------------------------------------------------------------
42
+
43
+ #=============== GETTERS ==============================
44
+
45
+ #========== GETTERS ===============================
46
+
47
+ #========== SETTERS ===============================
48
+
49
+ # integers
50
+ [:size].each do |m|
51
+ define_method "#{ m }" do |value|
52
+ instance_variable_set("@toc_#{ m }", value.to_i)
53
+ end
54
+ end
55
+
56
+ # strings
57
+ [:title, :opts].each do |m|
58
+ define_method "#{ m }" do |value|
59
+ instance_variable_set("@toc_#{ m }", value.to_s)
60
+ end
61
+ end
62
+
63
+ #========== VALIDATION ============================
64
+
65
+ def valid?
66
+ a = [:opts, :size, :title]
67
+ a.map { |m| send("toc_#{ m }") }.compact.size == a.size
68
+ end
69
+
70
+ #--------------------------------------------------
71
+ # Private Methods
72
+ #--------------------------------------------------
73
+ private
74
+
75
+ def option_keys
76
+ [:opts, :size, :title]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,34 @@
1
+ require 'caracal/core/models/table_of_contents_model'
2
+ require 'caracal/errors'
3
+
4
+
5
+ module Caracal
6
+ module Core
7
+
8
+ # This module encapsulates all the functionality related to table of
9
+ # contents
10
+ #
11
+ module TableOfContents
12
+ def self.included(base)
13
+ base.class_eval do
14
+
15
+ #-------------------------------------------------------------
16
+ # Public Methods
17
+ #-------------------------------------------------------------
18
+
19
+ def table_of_contents(*args, &block)
20
+ options = Caracal::Utilities.extract_options!(args)
21
+
22
+ model = Caracal::Core::Models::TableOfContentsModel.new(options, &block)
23
+
24
+ if model.valid?
25
+ contents << model
26
+ end
27
+
28
+ model
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -22,6 +22,7 @@ require 'caracal/core/relationships'
22
22
  require 'caracal/core/rules'
23
23
  require 'caracal/core/styles'
24
24
  require 'caracal/core/tables'
25
+ require 'caracal/core/table_of_contents'
25
26
  require 'caracal/core/text'
26
27
 
27
28
  require 'caracal/renderers/app_renderer'
@@ -68,6 +69,7 @@ module Caracal
68
69
  include Caracal::Core::PageBreaks
69
70
  include Caracal::Core::Rules
70
71
  include Caracal::Core::Tables
72
+ include Caracal::Core::TableOfContents
71
73
  include Caracal::Core::Text
72
74
 
73
75
  include Caracal::Core::Footer
@@ -220,6 +220,59 @@ module Caracal
220
220
  end
221
221
  end
222
222
 
223
+ def render_tableofcontents(xml, model)
224
+ xml['w'].sdt do
225
+ xml['w'].sdtPr do
226
+ xml['w'].docPartObj do
227
+ xml['w'].docPartGallery({ 'w:val' => model.toc_title })
228
+ xml['w'].docPartUnique({ 'w:val' => true })
229
+ end
230
+ end
231
+ xml['w'].sdtContent do
232
+ xml['w'].p do
233
+ xml['w'].pPr do
234
+ xml['w'].pStyle({ 'w:val' => 'ContentsHeading' })
235
+ xml['w'].rPr do
236
+ xml['w'].b
237
+ xml['w'].b
238
+ xml['w'].bCs
239
+ xml['w'].sz({ 'w:val' => model.toc_size })
240
+ xml['w'].szCs({ 'w:val' => model.toc_size })
241
+ end
242
+ end
243
+ xml['w'].r do
244
+ xml['w'].rPr do
245
+ xml['w'].b
246
+ xml['w'].bCs
247
+ xml['w'].sz({ 'w:val' => model.toc_size })
248
+ xml['w'].szCs({ 'w:val' => model.toc_size })
249
+ end
250
+ xml['w'].t model.toc_title
251
+ end
252
+ end
253
+ xml['w'].p do
254
+ xml['w'].r do
255
+ xml['w'].fldChar({ 'w:fldCharType' => 'begin' })
256
+ end
257
+ xml['w'].r do
258
+ xml['w'].rPr do
259
+ render_run_attributes(xml, model, false)
260
+ end
261
+ xml['w'].instrText({ 'xml:space' => 'preserve' }) do
262
+ xml.text " #{model.toc_opts} "
263
+ end
264
+ end
265
+ xml['w'].r do
266
+ xml['w'].fldChar({ 'w:fldCharType' => 'separate' })
267
+ end
268
+ xml['w'].r do
269
+ xml['w'].fldChar({ 'w:fldCharType' => 'end' })
270
+ end
271
+ end
272
+ end
273
+ end
274
+ end
275
+
223
276
  def render_field(xml, model)
224
277
  xml['w'].r do
225
278
  xml['w'].fldChar({ 'w:fldCharType' => 'begin' })
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '1.4.2'
2
+ VERSION = '1.4.3'
3
3
  end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::TableOfContentsModel do
4
+ subject do
5
+ described_class.new
6
+ end
7
+
8
+
9
+ #-------------------------------------------------------------
10
+ # Configuration
11
+ #-------------------------------------------------------------
12
+
13
+ describe 'configuration tests' do
14
+
15
+ # accessors
16
+ describe 'accessors' do
17
+ it { expect(subject.toc_opts).to eq 'TOC \o "1-1" \h \z \u \t "Heading 5,1"' }
18
+ it { expect(subject.toc_size).to eq 32 }
19
+ it { expect(subject.toc_title).to eq 'Table of Contents' }
20
+ end
21
+ end
22
+
23
+
24
+ #-------------------------------------------------------------
25
+ # Public Methods
26
+ #-------------------------------------------------------------
27
+
28
+ describe 'public method tests' do
29
+ #=============== GETTERS ==========================
30
+
31
+
32
+ #=============== SETTERS ==========================
33
+
34
+ # integers
35
+ describe '.size' do
36
+ before { subject.size(24) }
37
+
38
+ it { expect(subject.toc_size).to eq 24 }
39
+ end
40
+
41
+ # strings
42
+ describe '.opts' do
43
+ before { subject.opts('TOC \o "1-1"') }
44
+
45
+ it { expect(subject.toc_opts).to eq 'TOC \o "1-1"' }
46
+ end
47
+ describe '.title' do
48
+ before { subject.title('Hello World') }
49
+
50
+ it { expect(subject.toc_title).to eq 'Hello World' }
51
+ end
52
+
53
+ #=============== VALIDATION ===========================
54
+
55
+ describe '.valid?' do
56
+ describe 'when name provided' do
57
+ it { expect(subject.valid?).to eq true }
58
+ end
59
+ [:opts, :size, :title].each do |prop|
60
+ describe "when #{ prop } nil" do
61
+ before do
62
+ allow(subject).to receive("font_#{ prop }").and_return(nil)
63
+ end
64
+
65
+ it { expect(subject.valid?).to eq true }
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+
73
+ #-------------------------------------------------------------
74
+ # Private Methods
75
+ #-------------------------------------------------------------
76
+
77
+ describe 'private method tests' do
78
+
79
+ # .option_keys
80
+ describe '.option_keys' do
81
+ let(:actual) { subject.send(:option_keys).sort }
82
+ let(:expected) { [:opts, :size, :title].sort }
83
+
84
+ it { expect(actual).to eq expected }
85
+ end
86
+
87
+ end
88
+
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caracal_the_curve
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trade Infomatics
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2024-02-06 00:00:00.000000000 Z
14
+ date: 2024-02-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: nokogiri
@@ -163,6 +163,7 @@ files:
163
163
  - lib/caracal/core/models/style_model.rb
164
164
  - lib/caracal/core/models/table_cell_model.rb
165
165
  - lib/caracal/core/models/table_model.rb
166
+ - lib/caracal/core/models/table_of_contents_model.rb
166
167
  - lib/caracal/core/models/text_model.rb
167
168
  - lib/caracal/core/namespaces.rb
168
169
  - lib/caracal/core/page_breaks.rb
@@ -172,6 +173,7 @@ files:
172
173
  - lib/caracal/core/relationships.rb
173
174
  - lib/caracal/core/rules.rb
174
175
  - lib/caracal/core/styles.rb
176
+ - lib/caracal/core/table_of_contents.rb
175
177
  - lib/caracal/core/tables.rb
176
178
  - lib/caracal/core/text.rb
177
179
  - lib/caracal/document.rb
@@ -229,6 +231,7 @@ files:
229
231
  - spec/lib/caracal/core/models/style_model_spec.rb
230
232
  - spec/lib/caracal/core/models/table_cell_model_spec.rb
231
233
  - spec/lib/caracal/core/models/table_model_spec.rb
234
+ - spec/lib/caracal/core/models/table_of_contents_model_spec.rb
232
235
  - spec/lib/caracal/core/models/text_model_spec.rb
233
236
  - spec/lib/caracal/core/namespaces_spec.rb
234
237
  - spec/lib/caracal/core/page_breaks_spec.rb
@@ -303,6 +306,7 @@ test_files:
303
306
  - spec/lib/caracal/core/models/style_model_spec.rb
304
307
  - spec/lib/caracal/core/models/table_cell_model_spec.rb
305
308
  - spec/lib/caracal/core/models/table_model_spec.rb
309
+ - spec/lib/caracal/core/models/table_of_contents_model_spec.rb
306
310
  - spec/lib/caracal/core/models/text_model_spec.rb
307
311
  - spec/lib/caracal/core/namespaces_spec.rb
308
312
  - spec/lib/caracal/core/page_breaks_spec.rb