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,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::TextModel do
4
+ subject do
5
+ described_class.new do
6
+ content 'Lorem ipsum dolor....'
7
+ style 'Fancy'
8
+ color '666666'
9
+ size 20
10
+ bold false
11
+ italic false
12
+ underline true
13
+ end
14
+ end
15
+
16
+ #-------------------------------------------------------------
17
+ # Configuration
18
+ #-------------------------------------------------------------
19
+
20
+ describe 'configuration tests' do
21
+
22
+ # accessors
23
+ describe 'accessors' do
24
+ it { expect(subject.text_content).to eq 'Lorem ipsum dolor....' }
25
+ it { expect(subject.text_style).to eq 'Fancy' }
26
+ it { expect(subject.text_color).to eq '666666' }
27
+ it { expect(subject.text_size).to eq 20 }
28
+ it { expect(subject.text_bold).to eq false }
29
+ it { expect(subject.text_italic).to eq false }
30
+ it { expect(subject.text_underline).to eq true }
31
+ end
32
+
33
+ end
34
+
35
+
36
+ #-------------------------------------------------------------
37
+ # Public Methods
38
+ #-------------------------------------------------------------
39
+
40
+ describe 'public method tests' do
41
+
42
+ #=============== GETTERS ==========================
43
+
44
+ # .run_attributes
45
+ describe '.run_attributes' do
46
+ let(:expected) { { style: 'Fancy', color: '666666', size: 20, bold: false, italic: false, underline: true } }
47
+
48
+ it { expect(subject.run_attributes).to eq expected }
49
+ end
50
+
51
+
52
+ #=============== SETTERS ==========================
53
+
54
+ # booleans
55
+ describe '.bold' do
56
+ before { subject.bold(true) }
57
+
58
+ it { expect(subject.text_bold).to eq true }
59
+ end
60
+ describe '.italic' do
61
+ before { subject.italic(true) }
62
+
63
+ it { expect(subject.text_italic).to eq true }
64
+ end
65
+ describe '.underline' do
66
+ before { subject.underline(true) }
67
+
68
+ it { expect(subject.text_underline).to eq true }
69
+ end
70
+
71
+ # integers
72
+ describe '.size' do
73
+ before { subject.size(24) }
74
+
75
+ it { expect(subject.text_size).to eq 24 }
76
+ end
77
+
78
+ # strings
79
+ describe '.color' do
80
+ before { subject.color('999999') }
81
+
82
+ it { expect(subject.text_color).to eq '999999' }
83
+ end
84
+ describe '.content' do
85
+ before { subject.content('Something Else') }
86
+
87
+ it { expect(subject.text_content).to eq 'Something Else' }
88
+ end
89
+ describe '.style' do
90
+ before { subject.style('Dummy') }
91
+
92
+ it { expect(subject.text_style).to eq 'Dummy' }
93
+ end
94
+
95
+
96
+ #=============== VALIDATION ===========================
97
+
98
+ describe '.valid?' do
99
+ describe 'when required attributes provided' do
100
+ it { expect(subject.valid?).to eq true }
101
+ end
102
+ [:content].each do |prop|
103
+ describe "when #{ prop } nil" do
104
+ before do
105
+ allow(subject).to receive("text_#{ prop }").and_return(nil)
106
+ end
107
+
108
+ it { expect(subject.valid?).to eq false }
109
+ end
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+
116
+ #-------------------------------------------------------------
117
+ # Private Methods
118
+ #-------------------------------------------------------------
119
+
120
+ describe 'private method tests' do
121
+
122
+ # .option_keys
123
+ describe '.option_keys' do
124
+ let(:actual) { subject.send(:option_keys).sort }
125
+ let(:expected) { [:content, :style, :color, :size, :bold, :italic, :underline].sort }
126
+
127
+ it { expect(actual).to eq expected }
128
+ end
129
+
130
+ end
131
+
132
+ 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,80 @@
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_show).to eq false }
21
+ it { expect(subject.page_number_align).to eq :center }
22
+ end
23
+
24
+ end
25
+
26
+
27
+ #-------------------------------------------------------------
28
+ # Public Methods
29
+ #-------------------------------------------------------------
30
+
31
+ describe 'public methods tests' do
32
+
33
+ # .page_numbers
34
+ describe '.page_numbers' do
35
+ describe 'when nothing given' do
36
+ before { subject.page_numbers }
37
+
38
+ it { expect(subject.page_number_show).to eq false }
39
+ it { expect(subject.page_number_align).to eq :center }
40
+ end
41
+ describe 'when explicitly turned off' do
42
+ before { subject.page_numbers false }
43
+
44
+ it { expect(subject.page_number_show).to eq false }
45
+ it { expect(subject.page_number_align).to eq :center }
46
+ end
47
+ describe 'when options given' do
48
+ before { subject.page_numbers true, align: :left }
49
+
50
+ it { expect(subject.page_number_show).to eq true }
51
+ it { expect(subject.page_number_align).to eq :left }
52
+ end
53
+ describe 'when block given' do
54
+ before do
55
+ subject.page_numbers true do
56
+ align :left
57
+ end
58
+ end
59
+
60
+ it { expect(subject.page_number_show).to eq true }
61
+ it { expect(subject.page_number_align).to eq :left }
62
+ end
63
+ describe 'when fancy block given' do
64
+ subject do
65
+ Caracal::Document.new do |docx|
66
+ a = :left
67
+ docx.page_numbers true do
68
+ align a
69
+ end
70
+ end
71
+ end
72
+
73
+ it { expect(subject.page_number_show).to eq true }
74
+ it { expect(subject.page_number_align).to eq :left }
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,143 @@
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
+ end
18
+ describe 'page margin readers' do
19
+ it { expect(subject.page_margin_top).to eq 1440 }
20
+ it { expect(subject.page_margin_bottom).to eq 1440 }
21
+ it { expect(subject.page_margin_left).to eq 1440 }
22
+ it { expect(subject.page_margin_right).to eq 1440 }
23
+ end
24
+
25
+ end
26
+
27
+
28
+ #-------------------------------------------------------------
29
+ # Public Methods
30
+ #-------------------------------------------------------------
31
+
32
+ describe 'public methods tests' do
33
+
34
+ # .page_size
35
+ describe '.page_size' do
36
+ describe 'when options given' do
37
+ before { subject.page_size width: 10000, height: 12000 }
38
+
39
+ it { expect(subject.page_width).to eq 10000 }
40
+ it { expect(subject.page_height).to eq 12000 }
41
+ end
42
+ describe 'when block given' do
43
+ before do
44
+ subject.page_size do
45
+ width 10000
46
+ height 12000
47
+ end
48
+ end
49
+
50
+ it { expect(subject.page_width).to eq 10000 }
51
+ it { expect(subject.page_height).to eq 12000 }
52
+ end
53
+ describe 'when fancy block given' do
54
+ subject do
55
+ Caracal::Document.new do |docx|
56
+ w = 10000
57
+ h = 12000
58
+ docx.page_size do
59
+ width w
60
+ height h
61
+ end
62
+ end
63
+ end
64
+
65
+ it { expect(subject.page_width).to eq 10000 }
66
+ it { expect(subject.page_height).to eq 12000 }
67
+ end
68
+ describe 'when both given' do
69
+ before do
70
+ subject.page_size width: 10000 do
71
+ height 12000
72
+ end
73
+ end
74
+
75
+ it { expect(subject.page_width).to eq 10000 }
76
+ it { expect(subject.page_height).to eq 12000 }
77
+ end
78
+ end
79
+
80
+ # .page_margins
81
+ describe '.page_margins' do
82
+ describe 'when options given' do
83
+ before { subject.page_margins top: 1441, bottom: 1442, left: 1443, right: 1444 }
84
+
85
+ it { expect(subject.page_margin_top).to eq 1441 }
86
+ it { expect(subject.page_margin_bottom).to eq 1442 }
87
+ it { expect(subject.page_margin_left).to eq 1443 }
88
+ it { expect(subject.page_margin_right).to eq 1444 }
89
+ end
90
+ describe 'when block given' do
91
+ before do
92
+ subject.page_margins do
93
+ top 1441
94
+ bottom 1442
95
+ left 1443
96
+ right 1444
97
+ end
98
+ end
99
+
100
+ it { expect(subject.page_margin_top).to eq 1441 }
101
+ it { expect(subject.page_margin_bottom).to eq 1442 }
102
+ it { expect(subject.page_margin_left).to eq 1443 }
103
+ it { expect(subject.page_margin_right).to eq 1444 }
104
+ end
105
+ describe 'when fancy block given' do
106
+ subject do
107
+ Caracal::Document.new do |docx|
108
+ t = 1441
109
+ b = 1442
110
+ l = 1443
111
+ r = 1444
112
+ docx.page_margins do
113
+ top t
114
+ bottom b
115
+ left l
116
+ right r
117
+ end
118
+ end
119
+ end
120
+
121
+ it { expect(subject.page_margin_top).to eq 1441 }
122
+ it { expect(subject.page_margin_bottom).to eq 1442 }
123
+ it { expect(subject.page_margin_left).to eq 1443 }
124
+ it { expect(subject.page_margin_right).to eq 1444 }
125
+ end
126
+ describe 'when both given' do
127
+ before do
128
+ subject.page_margins top: 1441, left: 1443 do
129
+ bottom 1442
130
+ right 1444
131
+ end
132
+ end
133
+
134
+ it { expect(subject.page_margin_top).to eq 1441 }
135
+ it { expect(subject.page_margin_bottom).to eq 1442 }
136
+ it { expect(subject.page_margin_left).to eq 1443 }
137
+ it { expect(subject.page_margin_right).to eq 1444 }
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Relationships do
4
+ let(:r1) { Caracal::Core::Models::RelationshipModel.new({ target: 'footer.xml', type: :footer }) }
5
+ let(:r2) { 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([r1])
57
+ end
58
+
59
+ describe 'when key is registered' do
60
+ let(:key) { r1.relationship_key }
61
+
62
+ it { expect(actual).to eq r1 }
63
+ end
64
+ describe 'when key is not registered' do
65
+ let(:key) { r2.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(r1)
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(r1)
88
+ subject.register_relationship(r1)
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(r1)
102
+ subject.unregister_relationship(r1.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(r1)
110
+ subject.unregister_relationship(r2.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