caracal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Lists do
4
+ subject { Caracal::Document.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Public Methods
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'public method tests' do
12
+
13
+ # .ol
14
+ describe '.ol' do
15
+ let!(:size) { subject.contents.size }
16
+
17
+ before do
18
+ subject.ol do
19
+ li 'Item 1'
20
+ end
21
+ end
22
+
23
+ it { expect(subject.contents.size).to eq size + 1 }
24
+ it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
25
+ end
26
+
27
+ # .ul
28
+ describe '.ul' do
29
+ let!(:size) { subject.contents.size }
30
+
31
+ before do
32
+ subject.ul do
33
+ li 'Item 1'
34
+ end
35
+ end
36
+
37
+ it { expect(subject.contents.size).to eq size + 1 }
38
+ it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::BaseModel do
4
+ subject { described_class.new }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Public Methods
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'public method tests' do
12
+
13
+ #=============== VALIDATION ===========================
14
+
15
+ describe '.valid?' do
16
+ it { expect(subject.valid?).to eq true }
17
+ end
18
+
19
+ end
20
+
21
+
22
+ #-------------------------------------------------------------
23
+ # Private Methods
24
+ #-------------------------------------------------------------
25
+
26
+ describe 'private method tests' do
27
+
28
+ # .option_keys
29
+ describe '.option_keys' do
30
+ let(:actual) { subject.send(:option_keys).sort }
31
+ let(:expected) { [] }
32
+
33
+ it { expect(actual).to eq expected }
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::BorderModel do
4
+ subject do
5
+ described_class.new do
6
+ color '666666'
7
+ size 8
8
+ spacing 2
9
+ line :double
10
+ type :horizontal
11
+ end
12
+ end
13
+
14
+ #-------------------------------------------------------------
15
+ # Configuration
16
+ #-------------------------------------------------------------
17
+
18
+ describe 'configuration tests' do
19
+
20
+ # constants
21
+ describe 'constants' do
22
+ it { expect(described_class::DEFAULT_BORDER_COLOR).to eq 'auto' }
23
+ it { expect(described_class::DEFAULT_BORDER_LINE).to eq :single }
24
+ it { expect(described_class::DEFAULT_BORDER_SIZE).to eq 4 }
25
+ it { expect(described_class::DEFAULT_BORDER_SPACING).to eq 1 }
26
+ it { expect(described_class::DEFAULT_BORDER_TYPE).to eq :top }
27
+ end
28
+
29
+ # accessors
30
+ describe 'accessors' do
31
+ it { expect(subject.border_color).to eq '666666' }
32
+ it { expect(subject.border_line).to eq :double }
33
+ it { expect(subject.border_size).to eq 8 }
34
+ it { expect(subject.border_spacing).to eq 2 }
35
+ it { expect(subject.border_type).to eq :horizontal }
36
+ end
37
+
38
+ end
39
+
40
+
41
+ #-------------------------------------------------------------
42
+ # Public Methods
43
+ #-------------------------------------------------------------
44
+
45
+ describe 'public method tests' do
46
+
47
+ #=============== GETTERS ==========================
48
+
49
+ # .formatted_type
50
+ describe '.formatted_type' do
51
+ describe 'when horizontal' do
52
+ before do
53
+ allow(subject).to receive(:border_type).and_return(:horizontal)
54
+ end
55
+
56
+ it { expect(subject.formatted_type).to eq 'insideH'}
57
+ end
58
+ describe 'when vertical' do
59
+ before do
60
+ allow(subject).to receive(:border_type).and_return(:vertical)
61
+ end
62
+
63
+ it { expect(subject.formatted_type).to eq 'insideV'}
64
+ end
65
+ describe 'when other' do
66
+ before do
67
+ allow(subject).to receive(:border_type).and_return(:top)
68
+ end
69
+
70
+ it { expect(subject.formatted_type).to eq 'top'}
71
+ end
72
+ end
73
+
74
+ # .total_size
75
+ describe '.total_size' do
76
+ before do
77
+ allow(subject).to receive(:border_size).and_return(10)
78
+ allow(subject).to receive(:border_spacing).and_return(2)
79
+ end
80
+
81
+ it { expect(subject.total_size).to eq 14}
82
+ end
83
+
84
+
85
+ #=============== SETTERS ==========================
86
+
87
+ # .color
88
+ describe '.color' do
89
+ before { subject.color('999999') }
90
+
91
+ it { expect(subject.border_color).to eq '999999' }
92
+ end
93
+
94
+ # .line
95
+ describe '.line' do
96
+ before { subject.line(:single) }
97
+
98
+ it { expect(subject.border_line).to eq :single }
99
+ end
100
+
101
+ # .size
102
+ describe '.size' do
103
+ before { subject.size(24) }
104
+
105
+ it { expect(subject.border_size).to eq 24 }
106
+ end
107
+
108
+ # .spacing
109
+ describe '.spacing' do
110
+ before { subject.spacing(8) }
111
+
112
+ it { expect(subject.border_spacing).to eq 8 }
113
+ end
114
+
115
+ # .type
116
+ describe '.type' do
117
+ before { subject.type(:bottom) }
118
+
119
+ it { expect(subject.border_type).to eq :bottom }
120
+ end
121
+
122
+
123
+ #=============== VALIDATION ===========================
124
+
125
+ describe '.valid?' do
126
+ describe 'when all integers gt 0' do
127
+ it { expect(subject.valid?).to eq true }
128
+ end
129
+ [:size, :spacing].each do |d|
130
+ describe "when #{ d } lte 0" do
131
+ before do
132
+ allow(subject).to receive("border_#{ d }").and_return(0)
133
+ end
134
+
135
+ it { expect(subject.valid?).to eq false }
136
+ end
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+
143
+ #-------------------------------------------------------------
144
+ # Private Methods
145
+ #-------------------------------------------------------------
146
+
147
+ describe 'private method tests' do
148
+
149
+ # .option_keys
150
+ describe '.option_keys' do
151
+ let(:actual) { subject.send(:option_keys).sort }
152
+ let(:expected) { [:color, :size, :spacing, :line, :type].sort }
153
+
154
+ it { expect(actual).to eq expected }
155
+ end
156
+
157
+ end
158
+
159
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::FontModel do
4
+ subject { described_class.new({ name: 'Arial' }) }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Configuration
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'configuration tests' do
12
+
13
+ # accessors
14
+ describe 'accessors' do
15
+ it { expect(subject.font_name).to eq 'Arial' }
16
+ end
17
+
18
+ end
19
+
20
+
21
+ #-------------------------------------------------------------
22
+ # Public Methods
23
+ #-------------------------------------------------------------
24
+
25
+ describe 'public method tests' do
26
+
27
+ #=================== SETTERS =============================
28
+
29
+ # .name
30
+ describe '.name' do
31
+ before do
32
+ subject.name('Helvetica')
33
+ end
34
+
35
+ it { expect(subject.font_name).to eq 'Helvetica' }
36
+ end
37
+
38
+
39
+ #=================== STATE ===============================
40
+
41
+ # .matches?
42
+ describe '.matches?' do
43
+ describe 'when search term matches' do
44
+ let(:actual) { subject.matches?('Arial') }
45
+
46
+ it { expect(actual).to eq true }
47
+ end
48
+ describe 'when search term does not match' do
49
+ let(:actual) { subject.matches?('Dummy') }
50
+
51
+ it { expect(actual).to eq false }
52
+ end
53
+ end
54
+
55
+
56
+ #=============== VALIDATION ===========================
57
+
58
+ describe '.valid?' do
59
+ describe 'when name provided' do
60
+ it { expect(subject.valid?).to eq true }
61
+ end
62
+ [:name].each do |prop|
63
+ describe "when #{ prop } nil" do
64
+ before do
65
+ allow(subject).to receive("font_#{ prop }").and_return(nil)
66
+ end
67
+
68
+ it { expect(subject.valid?).to eq false }
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+
76
+ #-------------------------------------------------------------
77
+ # Private Methods
78
+ #-------------------------------------------------------------
79
+
80
+ describe 'private method tests' do
81
+
82
+ # .option_keys
83
+ describe '.option_keys' do
84
+ let(:actual) { subject.send(:option_keys).sort }
85
+ let(:expected) { [:name].sort }
86
+
87
+ it { expect(actual).to eq expected }
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,192 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::ImageModel do
4
+ subject do
5
+ described_class.new do
6
+ url 'https://www.google.com/images/srpr/logo11w.png'
7
+ width 250
8
+ height 200
9
+ align :right
10
+ top 12
11
+ bottom 13
12
+ left 14
13
+ right 15
14
+ end
15
+ end
16
+
17
+
18
+
19
+ #-------------------------------------------------------------
20
+ # Configuration
21
+ #-------------------------------------------------------------
22
+
23
+ describe 'configuration tests' do
24
+
25
+ # constants
26
+ describe 'constants' do
27
+ it { expect(described_class::DEFAULT_IMAGE_WIDTH).to eq 0 }
28
+ it { expect(described_class::DEFAULT_IMAGE_HEIGHT).to eq 0 }
29
+ it { expect(described_class::DEFAULT_IMAGE_ALIGN).to eq :left }
30
+ it { expect(described_class::DEFAULT_IMAGE_TOP).to eq 8 }
31
+ it { expect(described_class::DEFAULT_IMAGE_BOTTOM).to eq 8 }
32
+ it { expect(described_class::DEFAULT_IMAGE_LEFT).to eq 8 }
33
+ it { expect(described_class::DEFAULT_IMAGE_RIGHT).to eq 8 }
34
+ end
35
+
36
+ # accessors
37
+ describe 'accessors' do
38
+ it { expect(subject.image_url).to eq 'https://www.google.com/images/srpr/logo11w.png' }
39
+ it { expect(subject.image_width).to eq 250 }
40
+ it { expect(subject.image_height).to eq 200 }
41
+ it { expect(subject.image_align).to eq :right }
42
+ it { expect(subject.image_top).to eq 12 }
43
+ it { expect(subject.image_bottom).to eq 13 }
44
+ it { expect(subject.image_left).to eq 14 }
45
+ it { expect(subject.image_right).to eq 15 }
46
+ end
47
+
48
+ end
49
+
50
+
51
+ #-------------------------------------------------------------
52
+ # Public Methods
53
+ #-------------------------------------------------------------
54
+
55
+ describe 'public method tests' do
56
+
57
+ #=============== GETTERS ==========================
58
+
59
+ # emu conversions
60
+ [:width, :height, :top, :bottom, :left, :right].each do |m|
61
+ describe ".formatted_#{ m }" do
62
+ let(:actual) { subject.send("formatted_#{ m }") }
63
+
64
+ before { allow(subject).to receive("image_#{ m }").and_return(9) }
65
+
66
+ it { expect(actual).to eq 114300 }
67
+ end
68
+ end
69
+
70
+
71
+ #=============== SETTERS ==========================
72
+
73
+ # .url
74
+ describe '.color' do
75
+ before { subject.url('https://www.google.com/images/dummy.png') }
76
+
77
+ it { expect(subject.image_url).to eq 'https://www.google.com/images/dummy.png' }
78
+ end
79
+
80
+ # .width
81
+ describe '.width' do
82
+ before { subject.width(300) }
83
+
84
+ it { expect(subject.image_width).to eq 300 }
85
+ end
86
+
87
+ # .height
88
+ describe '.height' do
89
+ before { subject.height(400) }
90
+
91
+ it { expect(subject.image_height).to eq 400 }
92
+ end
93
+
94
+ # .align
95
+ describe '.align' do
96
+ before { subject.align(:center) }
97
+
98
+ it { expect(subject.image_align).to eq :center }
99
+ end
100
+
101
+ # .top
102
+ describe '.top' do
103
+ before { subject.top(12) }
104
+
105
+ it { expect(subject.image_top).to eq 12 }
106
+ end
107
+
108
+ # .bottom
109
+ describe '.bottom' do
110
+ before { subject.bottom(12) }
111
+
112
+ it { expect(subject.image_bottom).to eq 12 }
113
+ end
114
+
115
+ # .left
116
+ describe '.left' do
117
+ before { subject.left(12) }
118
+
119
+ it { expect(subject.image_left).to eq 12 }
120
+ end
121
+
122
+ # .right
123
+ describe '.right' do
124
+ before { subject.right(12) }
125
+
126
+ it { expect(subject.image_right).to eq 12 }
127
+ end
128
+
129
+
130
+ #=============== VALIDATION ===========================
131
+
132
+ describe '.valid?' do
133
+ describe 'when all values okay' do
134
+ it { expect(subject.valid?).to eq true }
135
+ end
136
+ [:width, :height, :top, :bottom, :left, :right].each do |d|
137
+ describe "when #{ d } lte 0" do
138
+ before do
139
+ allow(subject).to receive("image_#{ d }").and_return(0)
140
+ end
141
+
142
+ it { expect(subject.valid?).to eq false }
143
+ end
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+
150
+ #-------------------------------------------------------------
151
+ # Private Methods
152
+ #-------------------------------------------------------------
153
+
154
+ describe 'private method tests' do
155
+
156
+ # .option_keys
157
+ describe '.option_keys' do
158
+ let(:actual) { subject.send(:option_keys).sort }
159
+ let(:expected) { [:url, :width, :height, :align, :top, :bottom, :left, :right].sort }
160
+
161
+ it { expect(actual).to eq expected }
162
+ end
163
+
164
+ # .pixels_to_emus
165
+ describe '.pixels_to_emus' do
166
+ let(:actual) { subject.send(:pixels_to_emus, value) }
167
+
168
+ describe 'when argument is nil' do
169
+ let(:value) { nil }
170
+
171
+ it { expect(actual).to eq 0 }
172
+ end
173
+ describe 'when argument is NaN' do
174
+ let(:value) { 'a' }
175
+
176
+ it { expect(actual).to eq 0 }
177
+ end
178
+ describe 'when argument is rational' do
179
+ let(:value) { 396.1 }
180
+
181
+ it { expect(actual).to eq 5029200 }
182
+ end
183
+ describe 'when argument is integer' do
184
+ let(:value) { 396 }
185
+
186
+ it { expect(actual).to eq 5029200 }
187
+ end
188
+ end
189
+
190
+ end
191
+
192
+ end