caracal 0.1.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 (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +941 -0
  6. data/Rakefile +2 -0
  7. data/caracal.gemspec +27 -0
  8. data/lib/caracal.rb +31 -0
  9. data/lib/caracal/core/file_name.rb +39 -0
  10. data/lib/caracal/core/fonts.rb +75 -0
  11. data/lib/caracal/core/images.rb +37 -0
  12. data/lib/caracal/core/line_breaks.rb +29 -0
  13. data/lib/caracal/core/list_styles.rb +92 -0
  14. data/lib/caracal/core/lists.rb +57 -0
  15. data/lib/caracal/core/models/base_model.rb +51 -0
  16. data/lib/caracal/core/models/border_model.rb +120 -0
  17. data/lib/caracal/core/models/font_model.rb +64 -0
  18. data/lib/caracal/core/models/image_model.rb +118 -0
  19. data/lib/caracal/core/models/line_break_model.rb +15 -0
  20. data/lib/caracal/core/models/link_model.rb +65 -0
  21. data/lib/caracal/core/models/list_item_model.rb +105 -0
  22. data/lib/caracal/core/models/list_model.rb +130 -0
  23. data/lib/caracal/core/models/list_style_model.rb +129 -0
  24. data/lib/caracal/core/models/margin_model.rb +76 -0
  25. data/lib/caracal/core/models/page_break_model.rb +15 -0
  26. data/lib/caracal/core/models/page_number_model.rb +69 -0
  27. data/lib/caracal/core/models/page_size_model.rb +70 -0
  28. data/lib/caracal/core/models/paragraph_model.rb +141 -0
  29. data/lib/caracal/core/models/relationship_model.rb +108 -0
  30. data/lib/caracal/core/models/rule_model.rb +27 -0
  31. data/lib/caracal/core/models/style_model.rb +134 -0
  32. data/lib/caracal/core/models/table_cell_model.rb +155 -0
  33. data/lib/caracal/core/models/table_model.rb +206 -0
  34. data/lib/caracal/core/models/text_model.rb +92 -0
  35. data/lib/caracal/core/page_breaks.rb +29 -0
  36. data/lib/caracal/core/page_numbers.rb +51 -0
  37. data/lib/caracal/core/page_settings.rb +72 -0
  38. data/lib/caracal/core/relationships.rb +90 -0
  39. data/lib/caracal/core/rules.rb +35 -0
  40. data/lib/caracal/core/styles.rb +86 -0
  41. data/lib/caracal/core/tables.rb +41 -0
  42. data/lib/caracal/core/text.rb +73 -0
  43. data/lib/caracal/document.rb +242 -0
  44. data/lib/caracal/errors.rb +23 -0
  45. data/lib/caracal/renderers/app_renderer.rb +41 -0
  46. data/lib/caracal/renderers/content_types_renderer.rb +53 -0
  47. data/lib/caracal/renderers/core_renderer.rb +44 -0
  48. data/lib/caracal/renderers/document_renderer.rb +349 -0
  49. data/lib/caracal/renderers/fonts_renderer.rb +56 -0
  50. data/lib/caracal/renderers/footer_renderer.rb +69 -0
  51. data/lib/caracal/renderers/numbering_renderer.rb +87 -0
  52. data/lib/caracal/renderers/package_relationships_renderer.rb +50 -0
  53. data/lib/caracal/renderers/relationships_renderer.rb +48 -0
  54. data/lib/caracal/renderers/settings_renderer.rb +58 -0
  55. data/lib/caracal/renderers/styles_renderer.rb +163 -0
  56. data/lib/caracal/renderers/xml_renderer.rb +83 -0
  57. data/lib/caracal/version.rb +3 -0
  58. data/lib/tilt/caracal.rb +21 -0
  59. data/spec/lib/caracal/core/file_name_spec.rb +54 -0
  60. data/spec/lib/caracal/core/fonts_spec.rb +119 -0
  61. data/spec/lib/caracal/core/images_spec.rb +25 -0
  62. data/spec/lib/caracal/core/line_breaks_spec.rb +25 -0
  63. data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
  64. data/spec/lib/caracal/core/lists_spec.rb +43 -0
  65. data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
  66. data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
  67. data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
  68. data/spec/lib/caracal/core/models/image_model_spec.rb +192 -0
  69. data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
  70. data/spec/lib/caracal/core/models/link_model_spec.rb +139 -0
  71. data/spec/lib/caracal/core/models/list_item_model_spec.rb +190 -0
  72. data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
  73. data/spec/lib/caracal/core/models/list_style_model_spec.rb +212 -0
  74. data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
  75. data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
  76. data/spec/lib/caracal/core/models/page_number_model_spec.rb +101 -0
  77. data/spec/lib/caracal/core/models/page_size_model_spec.rb +91 -0
  78. data/spec/lib/caracal/core/models/paragraph_model_spec.rb +162 -0
  79. data/spec/lib/caracal/core/models/relationship_model_spec.rb +183 -0
  80. data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
  81. data/spec/lib/caracal/core/models/style_model_spec.rb +187 -0
  82. data/spec/lib/caracal/core/models/table_cell_model_spec.rb +221 -0
  83. data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
  84. data/spec/lib/caracal/core/models/text_model_spec.rb +132 -0
  85. data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
  86. data/spec/lib/caracal/core/page_numbers_spec.rb +80 -0
  87. data/spec/lib/caracal/core/page_settings_spec.rb +143 -0
  88. data/spec/lib/caracal/core/relationships_spec.rb +119 -0
  89. data/spec/lib/caracal/core/rules_spec.rb +25 -0
  90. data/spec/lib/caracal/core/styles_spec.rb +129 -0
  91. data/spec/lib/caracal/core/tables_spec.rb +25 -0
  92. data/spec/lib/caracal/core/text_spec.rb +52 -0
  93. data/spec/lib/caracal/errors_spec.rb +10 -0
  94. data/spec/spec_helper.rb +8 -0
  95. metadata +245 -0
@@ -0,0 +1,212 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::ListStyleModel do
4
+ subject do
5
+ described_class.new do
6
+ type :ordered
7
+ level 2
8
+ format 'decimal'
9
+ value '%3.'
10
+ align :right
11
+ left 800
12
+ line 400
13
+ start 2
14
+ restart false
15
+ end
16
+ end
17
+
18
+ #-------------------------------------------------------------
19
+ # Configuration
20
+ #-------------------------------------------------------------
21
+
22
+ describe 'configuration tests' do
23
+
24
+ # constants
25
+ describe 'constants' do
26
+ it { expect(described_class::DEFAULT_STYLE_ALIGN).to eq :left }
27
+ it { expect(described_class::DEFAULT_STYLE_LEFT).to eq 720 }
28
+ it { expect(described_class::DEFAULT_STYLE_LINE).to eq 360 }
29
+ it { expect(described_class::DEFAULT_STYLE_START).to eq 1 }
30
+ it { expect(described_class::DEFAULT_STYLE_RESTART).to eq true }
31
+ end
32
+
33
+ # accessors
34
+ describe 'accessors' do
35
+ it { expect(subject.style_type).to eq :ordered }
36
+ it { expect(subject.style_level).to eq 2 }
37
+ it { expect(subject.style_format).to eq 'decimal' }
38
+ it { expect(subject.style_value).to eq '%3.' }
39
+ it { expect(subject.style_align).to eq :right }
40
+ it { expect(subject.style_left).to eq 800 }
41
+ it { expect(subject.style_line).to eq 400 }
42
+ it { expect(subject.style_start).to eq 2 }
43
+ it { expect(subject.style_restart).to eq false }
44
+ end
45
+
46
+ end
47
+
48
+
49
+ #-------------------------------------------------------------
50
+ # Class Methods
51
+ #-------------------------------------------------------------
52
+
53
+ describe 'class method tests' do
54
+ subject { described_class }
55
+
56
+ # .formatted_type
57
+ describe '.formatted_type' do
58
+ it { expect(subject.formatted_type(:ordered)).to eq 1 }
59
+ it { expect(subject.formatted_type(:unordered)).to eq 2 }
60
+ end
61
+
62
+ end
63
+
64
+
65
+
66
+ #-------------------------------------------------------------
67
+ # Public Methods
68
+ #-------------------------------------------------------------
69
+
70
+ describe 'public method tests' do
71
+
72
+ #=============== GETTERS ==========================
73
+
74
+ # .formatted_type
75
+ describe '.formatted_type' do
76
+ describe 'when ordered list' do
77
+ before { allow(subject).to receive(:style_type).and_return(:ordered) }
78
+
79
+ it { expect(subject.formatted_type).to eq 1 }
80
+ end
81
+ describe 'when unordered list' do
82
+ before { allow(subject).to receive(:style_type).and_return(:unordered) }
83
+
84
+ it { expect(subject.formatted_type).to eq 2 }
85
+ end
86
+ end
87
+
88
+ # .formatted_restart
89
+ describe '.formatted_restart' do
90
+ describe 'when restart true' do
91
+ before { allow(subject).to receive(:style_restart).and_return(true) }
92
+
93
+ it { expect(subject.formatted_restart).to eq '1' }
94
+ end
95
+ describe 'when unordered list' do
96
+ before { allow(subject).to receive(:style_restart).and_return(false) }
97
+
98
+ it { expect(subject.formatted_restart).to eq '0' }
99
+ end
100
+ end
101
+
102
+
103
+ #=============== SETTERS ==========================
104
+
105
+ # booleans
106
+ describe '.restart' do
107
+ before { subject.restart(false) }
108
+
109
+ it { expect(subject.style_restart).to eq false }
110
+ end
111
+
112
+ # integers
113
+ describe '.level' do
114
+ before { subject.level(2) }
115
+
116
+ it { expect(subject.style_level).to eq 2 }
117
+ end
118
+ describe '.left' do
119
+ before { subject.left(800) }
120
+
121
+ it { expect(subject.style_left).to eq 800 }
122
+ end
123
+ describe '.line' do
124
+ before { subject.line(400) }
125
+
126
+ it { expect(subject.style_line).to eq 400 }
127
+ end
128
+ describe '.start' do
129
+ before { subject.start(2) }
130
+
131
+ it { expect(subject.style_start).to eq 2 }
132
+ end
133
+
134
+ # strings
135
+ describe '.format' do
136
+ before { subject.format('decimal') }
137
+
138
+ it { expect(subject.style_format).to eq 'decimal' }
139
+ end
140
+ describe '.value' do
141
+ before { subject.value('%3.') }
142
+
143
+ it { expect(subject.style_value).to eq '%3.' }
144
+ end
145
+
146
+ # symbols
147
+ describe '.type' do
148
+ before { subject.type(:ordered) }
149
+
150
+ it { expect(subject.style_type).to eq :ordered }
151
+ end
152
+ describe '.align' do
153
+ before { subject.align(:right) }
154
+
155
+ it { expect(subject.style_align).to eq :right }
156
+ end
157
+
158
+
159
+ #=================== STATE ===============================
160
+
161
+ # .matches?
162
+ describe '.matches?' do
163
+ describe 'when search terms match' do
164
+ let(:actual) { subject.matches?(:ordered, 2) }
165
+
166
+ it { expect(actual).to eq true }
167
+ end
168
+ describe 'when search term does not match' do
169
+ let(:actual) { subject.matches?(:unordered, 4) }
170
+
171
+ it { expect(actual).to eq false }
172
+ end
173
+ end
174
+
175
+
176
+ #=============== VALIDATION ===========================
177
+
178
+ describe '.valid?' do
179
+ describe 'when required attributes provided' do
180
+ it { expect(subject.valid?).to eq true }
181
+ end
182
+ [:type, :level, :format, :value].each do |prop|
183
+ describe "when #{ prop } nil" do
184
+ before do
185
+ allow(subject).to receive("style_#{ prop }").and_return(nil)
186
+ end
187
+
188
+ it { expect(subject.valid?).to eq false }
189
+ end
190
+ end
191
+ end
192
+
193
+ end
194
+
195
+
196
+ #-------------------------------------------------------------
197
+ # Private Methods
198
+ #-------------------------------------------------------------
199
+
200
+ describe 'private method tests' do
201
+
202
+ # .option_keys
203
+ describe '.option_keys' do
204
+ let(:actual) { subject.send(:option_keys).sort }
205
+ let(:expected) { [:type, :level, :format, :value, :align, :left, :line, :start].sort }
206
+
207
+ it { expect(actual).to eq expected }
208
+ end
209
+
210
+ end
211
+
212
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::MarginModel do
4
+ subject do
5
+ described_class.new do
6
+ top 1441
7
+ bottom 1442
8
+ left 1443
9
+ right 1444
10
+ end
11
+ end
12
+
13
+ #-------------------------------------------------------------
14
+ # Configuration
15
+ #-------------------------------------------------------------
16
+
17
+ describe 'configuration tests' do
18
+
19
+ # constants
20
+ describe 'constants' do
21
+ it { expect(described_class::DEFAULT_MARGIN_TOP).to eq 0 }
22
+ it { expect(described_class::DEFAULT_MARGIN_BOTTOM).to eq 0 }
23
+ it { expect(described_class::DEFAULT_MARGIN_LEFT).to eq 0 }
24
+ it { expect(described_class::DEFAULT_MARGIN_RIGHT).to eq 0 }
25
+ end
26
+
27
+ # accessors
28
+ describe 'accessors' do
29
+ it { expect(subject.margin_top).to eq 1441 }
30
+ it { expect(subject.margin_bottom).to eq 1442 }
31
+ it { expect(subject.margin_left).to eq 1443 }
32
+ it { expect(subject.margin_right).to eq 1444 }
33
+ end
34
+
35
+ end
36
+
37
+
38
+ #-------------------------------------------------------------
39
+ # Public Methods
40
+ #-------------------------------------------------------------
41
+
42
+ describe 'public method tests' do
43
+
44
+ #=============== SETTERS ==========================
45
+
46
+ # .top
47
+ describe '.top' do
48
+ before { subject.top(1000) }
49
+
50
+ it { expect(subject.margin_top).to eq 1000 }
51
+ end
52
+
53
+ # .bottom
54
+ describe '.bottom' do
55
+ before { subject.bottom(1000) }
56
+
57
+ it { expect(subject.margin_bottom).to eq 1000 }
58
+ end
59
+
60
+ # .left
61
+ describe '.left' do
62
+ before { subject.left(1000) }
63
+
64
+ it { expect(subject.margin_left).to eq 1000 }
65
+ end
66
+
67
+ # .right
68
+ describe '.right' do
69
+ before { subject.right(1000) }
70
+
71
+ it { expect(subject.margin_right).to eq 1000 }
72
+ end
73
+
74
+
75
+ #=============== VALIDATION ===========================
76
+
77
+ describe '.valid?' do
78
+ describe 'when all margins gt 0' do
79
+ it { expect(subject.valid?).to eq true }
80
+ end
81
+ [:top, :bottom, :left, :right].each do |d|
82
+ describe "when #{ d } lte 0" do
83
+ before do
84
+ allow(subject).to receive("margin_#{ d }").and_return(0)
85
+ end
86
+
87
+ it { expect(subject.valid?).to eq false }
88
+ end
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+
95
+ #-------------------------------------------------------------
96
+ # Private Methods
97
+ #-------------------------------------------------------------
98
+
99
+ describe 'private method tests' do
100
+
101
+ # .option_keys
102
+ describe '.option_keys' do
103
+ let(:actual) { subject.send(:option_keys).sort }
104
+ let(:expected) { [:top, :bottom, :left, :right].sort }
105
+
106
+ it { expect(actual).to eq expected }
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::PageBreakModel do
4
+ let(:name) { 'Arial' }
5
+
6
+ subject { described_class.new }
7
+
8
+
9
+ #-------------------------------------------------------------
10
+ # Configuration
11
+ #-------------------------------------------------------------
12
+
13
+ describe 'configuration tests' do
14
+
15
+ describe 'inheritance' do
16
+ it { expect(subject).to be_a(Caracal::Core::Models::BaseModel) }
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::PageNumberModel do
4
+ subject do
5
+ described_class.new do
6
+ show true
7
+ align :right
8
+ end
9
+ end
10
+
11
+ #-------------------------------------------------------------
12
+ # Configuration
13
+ #-------------------------------------------------------------
14
+
15
+ describe 'configuration tests' do
16
+
17
+ # constants
18
+ describe 'constants' do
19
+ it { expect(described_class::DEFAULT_PAGE_NUMBER_ALIGN).to eq :center }
20
+ end
21
+
22
+ # accessors
23
+ describe 'accessors' do
24
+ it { expect(subject.page_number_align).to eq :right }
25
+ it { expect(subject.page_number_show).to eq true }
26
+ end
27
+
28
+ end
29
+
30
+
31
+ #-------------------------------------------------------------
32
+ # Public Methods
33
+ #-------------------------------------------------------------
34
+
35
+ describe 'public method tests' do
36
+
37
+ #=============== SETTERS ==============================
38
+
39
+ # .align
40
+ describe '.align' do
41
+ before { subject.align(:left) }
42
+
43
+ it { expect(subject.page_number_align).to eq :left }
44
+ end
45
+
46
+ # .show
47
+ describe '.show' do
48
+ before { subject.show(true) }
49
+
50
+ it { expect(subject.page_number_show).to eq true }
51
+ end
52
+
53
+
54
+ #=============== VALIDATIONS ==========================
55
+
56
+ describe '.valid?' do
57
+ describe 'when show is false' do
58
+ before do
59
+ allow(subject).to receive(:page_number_show).and_return(false)
60
+ end
61
+
62
+ it { expect(subject.valid?).to eq true }
63
+ end
64
+ describe 'when show is true and align is valid' do
65
+ before do
66
+ allow(subject).to receive(:page_number_show).and_return(true)
67
+ allow(subject).to receive(:page_number_align).and_return(:left)
68
+ end
69
+
70
+ it { expect(subject.valid?).to eq true }
71
+ end
72
+ describe 'when show is true and align is invalid' do
73
+ before do
74
+ allow(subject).to receive(:page_number_show).and_return(true)
75
+ allow(subject).to receive(:page_number_align).and_return(:dummy)
76
+ end
77
+
78
+ it { expect(subject.valid?).to eq false }
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+
85
+ #-------------------------------------------------------------
86
+ # Private Methods
87
+ #-------------------------------------------------------------
88
+
89
+ describe 'private method tests' do
90
+
91
+ # .option_keys
92
+ describe '.option_keys' do
93
+ let(:actual) { subject.send(:option_keys).sort }
94
+ let(:expected) { [:align, :show].sort }
95
+
96
+ it { expect(actual).to eq expected }
97
+ end
98
+
99
+ end
100
+
101
+ end