caracal_the_curve 1.4.1

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 (116) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +22 -0
  3. data/.github/workflows/publish_gem.yml +40 -0
  4. data/.gitignore +25 -0
  5. data/.travis.yml +20 -0
  6. data/CHANGELOG.md +141 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +842 -0
  10. data/Rakefile +7 -0
  11. data/caracal.gemspec +28 -0
  12. data/lib/caracal/core/bookmarks.rb +52 -0
  13. data/lib/caracal/core/custom_properties.rb +49 -0
  14. data/lib/caracal/core/file_name.rb +43 -0
  15. data/lib/caracal/core/fonts.rb +75 -0
  16. data/lib/caracal/core/iframes.rb +42 -0
  17. data/lib/caracal/core/ignorables.rb +47 -0
  18. data/lib/caracal/core/images.rb +37 -0
  19. data/lib/caracal/core/list_styles.rb +93 -0
  20. data/lib/caracal/core/lists.rb +57 -0
  21. data/lib/caracal/core/models/base_model.rb +51 -0
  22. data/lib/caracal/core/models/bookmark_model.rb +86 -0
  23. data/lib/caracal/core/models/border_model.rb +120 -0
  24. data/lib/caracal/core/models/custom_property_model.rb +60 -0
  25. data/lib/caracal/core/models/font_model.rb +64 -0
  26. data/lib/caracal/core/models/iframe_model.rb +148 -0
  27. data/lib/caracal/core/models/image_model.rb +133 -0
  28. data/lib/caracal/core/models/line_break_model.rb +15 -0
  29. data/lib/caracal/core/models/link_model.rb +94 -0
  30. data/lib/caracal/core/models/list_item_model.rb +108 -0
  31. data/lib/caracal/core/models/list_model.rb +132 -0
  32. data/lib/caracal/core/models/list_style_model.rb +118 -0
  33. data/lib/caracal/core/models/margin_model.rb +76 -0
  34. data/lib/caracal/core/models/namespace_model.rb +65 -0
  35. data/lib/caracal/core/models/page_break_model.rb +61 -0
  36. data/lib/caracal/core/models/page_number_model.rb +95 -0
  37. data/lib/caracal/core/models/page_size_model.rb +79 -0
  38. data/lib/caracal/core/models/paragraph_model.rb +186 -0
  39. data/lib/caracal/core/models/relationship_model.rb +114 -0
  40. data/lib/caracal/core/models/rule_model.rb +27 -0
  41. data/lib/caracal/core/models/style_model.rb +165 -0
  42. data/lib/caracal/core/models/table_cell_model.rb +176 -0
  43. data/lib/caracal/core/models/table_model.rb +206 -0
  44. data/lib/caracal/core/models/text_model.rb +118 -0
  45. data/lib/caracal/core/namespaces.rb +89 -0
  46. data/lib/caracal/core/page_breaks.rb +29 -0
  47. data/lib/caracal/core/page_numbers.rb +58 -0
  48. data/lib/caracal/core/page_settings.rb +74 -0
  49. data/lib/caracal/core/relationships.rb +90 -0
  50. data/lib/caracal/core/rules.rb +35 -0
  51. data/lib/caracal/core/styles.rb +86 -0
  52. data/lib/caracal/core/tables.rb +42 -0
  53. data/lib/caracal/core/text.rb +75 -0
  54. data/lib/caracal/document.rb +272 -0
  55. data/lib/caracal/errors.rb +23 -0
  56. data/lib/caracal/renderers/app_renderer.rb +41 -0
  57. data/lib/caracal/renderers/content_types_renderer.rb +54 -0
  58. data/lib/caracal/renderers/core_renderer.rb +44 -0
  59. data/lib/caracal/renderers/custom_renderer.rb +64 -0
  60. data/lib/caracal/renderers/document_renderer.rb +427 -0
  61. data/lib/caracal/renderers/fonts_renderer.rb +56 -0
  62. data/lib/caracal/renderers/footer_renderer.rb +90 -0
  63. data/lib/caracal/renderers/numbering_renderer.rb +88 -0
  64. data/lib/caracal/renderers/package_relationships_renderer.rb +51 -0
  65. data/lib/caracal/renderers/relationships_renderer.rb +48 -0
  66. data/lib/caracal/renderers/settings_renderer.rb +58 -0
  67. data/lib/caracal/renderers/styles_renderer.rb +181 -0
  68. data/lib/caracal/renderers/xml_renderer.rb +83 -0
  69. data/lib/caracal/utilities.rb +23 -0
  70. data/lib/caracal/version.rb +3 -0
  71. data/lib/caracal.rb +40 -0
  72. data/lib/tilt/caracal.rb +21 -0
  73. data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
  74. data/spec/lib/caracal/core/file_name_spec.rb +54 -0
  75. data/spec/lib/caracal/core/fonts_spec.rb +119 -0
  76. data/spec/lib/caracal/core/iframes_spec.rb +29 -0
  77. data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
  78. data/spec/lib/caracal/core/images_spec.rb +25 -0
  79. data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
  80. data/spec/lib/caracal/core/lists_spec.rb +43 -0
  81. data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
  82. data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
  83. data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
  84. data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
  85. data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
  86. data/spec/lib/caracal/core/models/image_model_spec.rb +225 -0
  87. data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
  88. data/spec/lib/caracal/core/models/link_model_spec.rb +179 -0
  89. data/spec/lib/caracal/core/models/list_item_model_spec.rb +197 -0
  90. data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
  91. data/spec/lib/caracal/core/models/list_style_model_spec.rb +198 -0
  92. data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
  93. data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
  94. data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
  95. data/spec/lib/caracal/core/models/page_number_model_spec.rb +136 -0
  96. data/spec/lib/caracal/core/models/page_size_model_spec.rb +101 -0
  97. data/spec/lib/caracal/core/models/paragraph_model_spec.rb +196 -0
  98. data/spec/lib/caracal/core/models/relationship_model_spec.rb +193 -0
  99. data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
  100. data/spec/lib/caracal/core/models/style_model_spec.rb +225 -0
  101. data/spec/lib/caracal/core/models/table_cell_model_spec.rb +230 -0
  102. data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
  103. data/spec/lib/caracal/core/models/text_model_spec.rb +154 -0
  104. data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
  105. data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
  106. data/spec/lib/caracal/core/page_numbers_spec.rb +89 -0
  107. data/spec/lib/caracal/core/page_settings_spec.rb +151 -0
  108. data/spec/lib/caracal/core/relationships_spec.rb +119 -0
  109. data/spec/lib/caracal/core/rules_spec.rb +25 -0
  110. data/spec/lib/caracal/core/styles_spec.rb +129 -0
  111. data/spec/lib/caracal/core/tables_spec.rb +25 -0
  112. data/spec/lib/caracal/core/text_spec.rb +52 -0
  113. data/spec/lib/caracal/errors_spec.rb +10 -0
  114. data/spec/spec_helper.rb +8 -0
  115. data/spec/support/_fixtures/snippet.docx +0 -0
  116. metadata +292 -0
@@ -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
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::PageBreaks do
4
+ subject { Caracal::Document.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Public Methods
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'public method tests' do
12
+
13
+ # .page
14
+ describe '.page' do
15
+ let!(:size) { subject.contents.size }
16
+
17
+ before { subject.page }
18
+
19
+ it { expect(subject.contents.size).to eq size + 1 }
20
+ it { expect(subject.contents.last).to be_a(Caracal::Core::Models::PageBreakModel) }
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::PageSettings do
4
+ subject { Caracal::Document.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Configuration
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'configuration tests' do
12
+
13
+ # constants
14
+ describe 'page number constants' do
15
+ it { expect(subject.class::DEFAULT_PAGE_NUMBER_ALIGN).to eq :center }
16
+ end
17
+
18
+ # readers
19
+ describe 'page number readers' do
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 }
23
+ end
24
+
25
+ end
26
+
27
+
28
+ #-------------------------------------------------------------
29
+ # Public Methods
30
+ #-------------------------------------------------------------
31
+
32
+ describe 'public methods tests' do
33
+
34
+ # .page_numbers
35
+ describe '.page_numbers' do
36
+ describe 'when nothing given' do
37
+ before { subject.page_numbers }
38
+
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 }
42
+ end
43
+ describe 'when explicitly turned off' do
44
+ before { subject.page_numbers false }
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 }
49
+ end
50
+ describe 'when options given' do
51
+ before { subject.page_numbers true, label: 'Custom Text', align: :left }
52
+
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 }
56
+ end
57
+ describe 'when block given' do
58
+ before do
59
+ subject.page_numbers true do
60
+ align :left
61
+ label 'More Text'
62
+ end
63
+ end
64
+
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 }
68
+ end
69
+ describe 'when fancy block given' do
70
+ subject do
71
+ Caracal::Document.new do |docx|
72
+ t = 'This is text'
73
+ a = :left
74
+ docx.page_numbers true do
75
+ label t
76
+ align a
77
+ end
78
+ end
79
+ end
80
+
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 }
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::PageSettings do
4
+ subject { Caracal::Document.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Configuration
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'configuration tests' do
12
+
13
+ # readers
14
+ describe 'page size readers' do
15
+ it { expect(subject.page_width).to eq 12240 }
16
+ it { expect(subject.page_height).to eq 15840 }
17
+ it { expect(subject.page_orientation).to eq 'portrait' }
18
+ end
19
+ describe 'page margin readers' do
20
+ it { expect(subject.page_margin_top).to eq 1440 }
21
+ it { expect(subject.page_margin_bottom).to eq 1440 }
22
+ it { expect(subject.page_margin_left).to eq 1440 }
23
+ it { expect(subject.page_margin_right).to eq 1440 }
24
+ end
25
+
26
+ end
27
+
28
+
29
+ #-------------------------------------------------------------
30
+ # Public Methods
31
+ #-------------------------------------------------------------
32
+
33
+ describe 'public methods tests' do
34
+
35
+ # .page_size
36
+ describe '.page_size' do
37
+ describe 'when options given' do
38
+ before { subject.page_size width: 10000, height: 12000, orientation: :landscape }
39
+
40
+ it { expect(subject.page_width).to eq 10000 }
41
+ it { expect(subject.page_height).to eq 12000 }
42
+ it { expect(subject.page_orientation).to eq 'landscape' }
43
+ end
44
+ describe 'when block given' do
45
+ before do
46
+ subject.page_size do
47
+ width 10000
48
+ height 12000
49
+ orientation :landscape
50
+ end
51
+ end
52
+
53
+ it { expect(subject.page_width).to eq 10000 }
54
+ it { expect(subject.page_height).to eq 12000 }
55
+ it { expect(subject.page_orientation).to eq 'landscape' }
56
+ end
57
+ describe 'when fancy block given' do
58
+ subject do
59
+ Caracal::Document.new do |docx|
60
+ w = 10000
61
+ h = 12000
62
+ o = :landscape
63
+ docx.page_size do
64
+ width w
65
+ height h
66
+ orientation o
67
+ end
68
+ end
69
+ end
70
+
71
+ it { expect(subject.page_width).to eq 10000 }
72
+ it { expect(subject.page_height).to eq 12000 }
73
+ it { expect(subject.page_orientation).to eq 'landscape' }
74
+ end
75
+ describe 'when both given' do
76
+ before do
77
+ subject.page_size width: 10000, orientation: :landscape do
78
+ height 12000
79
+ end
80
+ end
81
+
82
+ it { expect(subject.page_width).to eq 10000 }
83
+ it { expect(subject.page_height).to eq 12000 }
84
+ it { expect(subject.page_orientation).to eq 'landscape' }
85
+ end
86
+ end
87
+
88
+ # .page_margins
89
+ describe '.page_margins' do
90
+ describe 'when options given' do
91
+ before { subject.page_margins top: 1441, bottom: 1442, left: 1443, right: 1444 }
92
+
93
+ it { expect(subject.page_margin_top).to eq 1441 }
94
+ it { expect(subject.page_margin_bottom).to eq 1442 }
95
+ it { expect(subject.page_margin_left).to eq 1443 }
96
+ it { expect(subject.page_margin_right).to eq 1444 }
97
+ end
98
+ describe 'when block given' do
99
+ before do
100
+ subject.page_margins do
101
+ top 1441
102
+ bottom 1442
103
+ left 1443
104
+ right 1444
105
+ end
106
+ end
107
+
108
+ it { expect(subject.page_margin_top).to eq 1441 }
109
+ it { expect(subject.page_margin_bottom).to eq 1442 }
110
+ it { expect(subject.page_margin_left).to eq 1443 }
111
+ it { expect(subject.page_margin_right).to eq 1444 }
112
+ end
113
+ describe 'when fancy block given' do
114
+ subject do
115
+ Caracal::Document.new do |docx|
116
+ t = 1441
117
+ b = 1442
118
+ l = 1443
119
+ r = 1444
120
+ docx.page_margins do
121
+ top t
122
+ bottom b
123
+ left l
124
+ right r
125
+ end
126
+ end
127
+ end
128
+
129
+ it { expect(subject.page_margin_top).to eq 1441 }
130
+ it { expect(subject.page_margin_bottom).to eq 1442 }
131
+ it { expect(subject.page_margin_left).to eq 1443 }
132
+ it { expect(subject.page_margin_right).to eq 1444 }
133
+ end
134
+ describe 'when both given' do
135
+ before do
136
+ subject.page_margins top: 1441, left: 1443 do
137
+ bottom 1442
138
+ right 1444
139
+ end
140
+ end
141
+
142
+ it { expect(subject.page_margin_top).to eq 1441 }
143
+ it { expect(subject.page_margin_bottom).to eq 1442 }
144
+ it { expect(subject.page_margin_left).to eq 1443 }
145
+ it { expect(subject.page_margin_right).to eq 1444 }
146
+ end
147
+ end
148
+
149
+ end
150
+
151
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Relationships do
4
+ let(:m1) { Caracal::Core::Models::RelationshipModel.new({ target: 'footer.xml', type: :footer }) }
5
+ let(:m2) { Caracal::Core::Models::RelationshipModel.new({ target: 'setting.xml', type: :setting }) }
6
+
7
+ subject { Caracal::Document.new }
8
+
9
+
10
+ #-------------------------------------------------------------
11
+ # Class Methods
12
+ #-------------------------------------------------------------
13
+
14
+ describe 'public class tests' do
15
+
16
+ # .default_relationships
17
+ describe '.default_relationships' do
18
+ let(:expected) { [:font, :footer, :numbering, :setting, :style] }
19
+ let(:actual) { subject.class.default_relationships.map { |r| r[:type] } }
20
+
21
+ it { expect(actual).to eq expected }
22
+ end
23
+
24
+ end
25
+
26
+
27
+ #-------------------------------------------------------------
28
+ # Public Methods
29
+ #-------------------------------------------------------------
30
+
31
+ describe 'public method tests' do
32
+
33
+ #============== ATTRIBUTES =====================
34
+
35
+ # .relationship
36
+ describe '.relationship' do
37
+ it 'delegates to registration method' do
38
+ expect(subject).to receive(:register_relationship)
39
+ subject.relationship({ target: 'new.gif', type: :image })
40
+ end
41
+ end
42
+
43
+
44
+ #============== GETTERS ========================
45
+
46
+ # .relationships
47
+ describe '.relationships' do
48
+ it { expect(subject.relationships).to be_a(Array) }
49
+ end
50
+
51
+ # .find_relationship
52
+ describe '.find_relationship' do
53
+ let(:actual) { subject.find_relationship(key) }
54
+
55
+ before do
56
+ allow(subject).to receive(:relationships).and_return([m1])
57
+ end
58
+
59
+ describe 'when key is registered' do
60
+ let(:key) { m1.relationship_key }
61
+
62
+ it { expect(actual).to eq m1 }
63
+ end
64
+ describe 'when key is not registered' do
65
+ let(:key) { m2.relationship_key }
66
+
67
+ it { expect(actual).to eq nil }
68
+ end
69
+ end
70
+
71
+
72
+ #============== REGISTRATION ========================
73
+
74
+ # .register_relationship
75
+ describe '.register_relationship' do
76
+ let(:default_length) { subject.class.default_relationships.size }
77
+
78
+ describe 'when not already registered' do
79
+ before do
80
+ subject.register_relationship(m1)
81
+ end
82
+
83
+ it { expect(subject.relationships.size).to eq default_length + 1 }
84
+ end
85
+ describe 'when already registered' do
86
+ before do
87
+ subject.register_relationship(m1)
88
+ subject.register_relationship(m1)
89
+ end
90
+
91
+ it { expect(subject.relationships.size).to eq default_length + 1 }
92
+ end
93
+ end
94
+
95
+ # .unregister_relationship
96
+ describe '.unregister_relationship' do
97
+ let(:default_length) { subject.class.default_relationships.size }
98
+
99
+ describe 'when registered' do
100
+ before do
101
+ subject.register_relationship(m1)
102
+ subject.unregister_relationship(m1.relationship_target)
103
+ end
104
+
105
+ it { expect(subject.relationships.size).to eq default_length }
106
+ end
107
+ describe 'when not registered' do
108
+ before do
109
+ subject.register_relationship(m1)
110
+ subject.unregister_relationship(m2.relationship_target)
111
+ end
112
+
113
+ it { expect(subject.relationships.size).to eq default_length + 1 }
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Rules do
4
+ subject { Caracal::Document.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Public Methods
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'public method tests' do
12
+
13
+ # .hr
14
+ describe '.hr' do
15
+ let!(:size) { subject.contents.size }
16
+
17
+ before { subject.hr }
18
+
19
+ it { expect(subject.contents.size).to eq size + 1 }
20
+ it { expect(subject.contents.last).to be_a(Caracal::Core::Models::RuleModel) }
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Styles do
4
+ let(:s1) { Caracal::Core::Models::StyleModel.new({ id: 'Dummy', name: 'dummy' }) }
5
+ let(:s2) { Caracal::Core::Models::StyleModel.new({ id: 'Fake', name: 'fake' }) }
6
+
7
+ subject { Caracal::Document.new }
8
+
9
+
10
+ #-------------------------------------------------------------
11
+ # Class Methods
12
+ #-------------------------------------------------------------
13
+
14
+ describe 'public class tests' do
15
+
16
+ # .default_styles
17
+ describe '.default_styles' do
18
+ let(:expected) { ['Normal', 'Heading1', 'Heading2', 'Heading3', 'Heading4', 'Heading5', 'Heading6', 'Title', 'Subtitle'].sort }
19
+ let(:actual) { subject.class.default_styles.map { |s| s[:id] }.sort }
20
+
21
+ it {expect(actual).to eq expected }
22
+ end
23
+
24
+ end
25
+
26
+
27
+ #-------------------------------------------------------------
28
+ # Public Methods
29
+ #-------------------------------------------------------------
30
+
31
+ describe 'public method tests' do
32
+
33
+ #============== ATTRIBUTES =====================
34
+
35
+ # .style
36
+ describe '.style' do
37
+ it 'delegates to registration method' do
38
+ expect(subject).to receive(:register_style)
39
+ subject.style({ id: 'heading2', name: 'Heading 2' })
40
+ end
41
+ end
42
+
43
+
44
+ #============== GETTERS ========================
45
+
46
+ # .styles
47
+ describe '.styles' do
48
+ it { expect(subject.styles).to be_a(Array) }
49
+ end
50
+
51
+ # .default_style
52
+ describe '.default_style' do
53
+ before do
54
+ allow(s1).to receive(:style_default).and_return(true)
55
+ allow(subject).to receive(:styles).and_return([s1,s2])
56
+ end
57
+
58
+ it { expect(subject.default_style).to eq s1 }
59
+ end
60
+
61
+ # .find_style
62
+ describe '.find_style' do
63
+ let(:actual) { subject.find_style(key) }
64
+
65
+ before do
66
+ allow(subject).to receive(:styles).and_return([s1])
67
+ end
68
+
69
+ describe 'when key is registered' do
70
+ let(:key) { s1.style_id }
71
+
72
+ it { expect(actual).to eq s1 }
73
+ end
74
+ describe 'when key is not registered' do
75
+ let(:key) { s2.style_id }
76
+
77
+ it { expect(actual).to eq nil }
78
+ end
79
+ end
80
+
81
+
82
+ #============== REGISTRATION ========================
83
+
84
+ # .register_style
85
+ describe '.register_style' do
86
+ let(:default_length) { subject.class.default_styles.size }
87
+
88
+ describe 'when not already registered' do
89
+ before do
90
+ subject.register_style(s1)
91
+ end
92
+
93
+ it { expect(subject.styles.size).to eq default_length + 1 }
94
+ end
95
+ describe 'when already registered' do
96
+ before do
97
+ subject.register_style(s1)
98
+ subject.register_style(s1)
99
+ end
100
+
101
+ it { expect(subject.styles.size).to eq default_length + 1 }
102
+ end
103
+ end
104
+
105
+ # .unregister_style
106
+ describe '.unregister_style' do
107
+ let(:default_length) { subject.class.default_styles.size }
108
+
109
+ describe 'when registered' do
110
+ before do
111
+ subject.register_style(s1)
112
+ subject.unregister_style(s1.style_id)
113
+ end
114
+
115
+ it { expect(subject.styles.size).to eq default_length }
116
+ end
117
+ describe 'when not registered' do
118
+ before do
119
+ subject.register_style(s1)
120
+ subject.unregister_style(s2.style_id)
121
+ end
122
+
123
+ it { expect(subject.styles.size).to eq default_length + 1 }
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Tables do
4
+ subject { Caracal::Document.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Public Methods
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'public method tests' do
12
+
13
+ # .table
14
+ describe '.table' do
15
+ let!(:size) { subject.contents.size }
16
+
17
+ before { subject.table [['Sample Text']] }
18
+
19
+ it { expect(subject.contents.size).to eq size + 1 }
20
+ it { expect(subject.contents.last).to be_a(Caracal::Core::Models::TableModel) }
21
+ end
22
+
23
+ end
24
+
25
+ end