caracal 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7769025e3ab813a92fc9938b135585a7fdb882e
4
- data.tar.gz: 6de21a3c1f17285a381574a0660fd00dfdfab600
3
+ metadata.gz: 4d107834127a296986fca0b7b876148eab9d2be3
4
+ data.tar.gz: af3634f58a24cca519c544a33163cd2b6dc5832a
5
5
  SHA512:
6
- metadata.gz: a45af91ce82098dc55b1d80762e9b8fcff6f78b1c969c86a8da8822ab94eccc8fbbd333752c8f02bbed6d35c88aaa8b1d7f6cba7d486d64114df22566142bf7c
7
- data.tar.gz: 95bc1696fb6e774a05d3ae2fc0248c95c2f433ea0192f9075bc741075d9e4101c1b65ede67b1acaf52ea0600d0a238d4e4595baf503c7a917a673941551f47ad
6
+ metadata.gz: 7b3796c09560aeefe321644ab86150da646409851e97c8d98d25db4533129d4039811efe28680bb4cb9f1d0eac5997cd210700359029302ccd725bd64e971dc3
7
+ data.tar.gz: a5f930dafe4e88dedec2229f1ecf969a81e2d7265e63ead0f9ce562ff6b261f74b54ba2b7fc74effe6347a017a03abe442a12d4d39b9a6fb55ab268621619660
data/README.md CHANGED
@@ -367,6 +367,7 @@ docx.p 'Sample text.' do
367
367
  bold true # sets whether or not to render the text with a bold weight.
368
368
  italic false # sets whether or not render the text in italic style.
369
369
  underline false # sets whether or not to underline the text.
370
+ bgcolor 'cccccc' # sets the background color.
370
371
  end
371
372
  ```
372
373
 
@@ -376,7 +377,7 @@ More complex paragraph runs can be accomplished by using the `text` method inste
376
377
  docx.p do
377
378
  text 'Here is a sentence with a '
378
379
  link 'link', 'https://www.example.com'
379
- text ' to something awesome', font: 'Courier New', color: '555555', size: 32, bold: true, italic: true, underline: true
380
+ text ' to something awesome', font: 'Courier New', color: '555555', size: 32, bold: true, italic: true, underline: true, bgcolor: 'cccccc'
380
381
  text '.'
381
382
  br
382
383
  text 'This text follows a line break.'
@@ -399,6 +400,7 @@ p do
399
400
  bold false # sets whether or not the text will be bold. defaults to false.
400
401
  italic false # sets whether or not the text will be italic. defaults to false.
401
402
  underline true # sets whether or not the text will be underlined. defaults to true.
403
+ bgcolor 'cccccc' # sets the background color.
402
404
  end
403
405
  end
404
406
  ```
@@ -28,6 +28,7 @@ module Caracal
28
28
  alias_method :link_bold, :text_bold
29
29
  alias_method :link_italic, :text_italic
30
30
  alias_method :link_underline, :text_underline
31
+ alias_method :link_bgcolor, :text_bgcolor
31
32
 
32
33
  # initialization
33
34
  def initialize(options={}, &block)
@@ -6,20 +6,20 @@ require 'caracal/errors'
6
6
  module Caracal
7
7
  module Core
8
8
  module Models
9
-
9
+
10
10
  # This class encapsulates the logic needed to store and manipulate
11
11
  # list item data.
12
12
  #
13
13
  class ListItemModel < ParagraphModel
14
-
14
+
15
15
  #-------------------------------------------------------------
16
16
  # Configuration
17
17
  #-------------------------------------------------------------
18
-
18
+
19
19
  # accessors
20
20
  attr_accessor :nested_list
21
-
22
- # readers (create aliases for superclass methods to conform
21
+
22
+ # readers (create aliases for superclass methods to conform
23
23
  # to expected naming convention.)
24
24
  attr_reader :list_item_type
25
25
  attr_reader :list_item_level
@@ -29,15 +29,16 @@ module Caracal
29
29
  alias_method :list_item_bold, :paragraph_bold
30
30
  alias_method :list_item_italic, :paragraph_italic
31
31
  alias_method :list_item_underline, :paragraph_underline
32
-
33
-
34
-
32
+ alias_method :list_item_bgcolor, :paragraph_bgcolor
33
+
34
+
35
+
35
36
  #-------------------------------------------------------------
36
37
  # Public Instance Methods
37
38
  #-------------------------------------------------------------
38
-
39
+
39
40
  #=============== SETTERS ==============================
40
-
41
+
41
42
  # integers
42
43
  [:level].each do |m|
43
44
  define_method "#{ m }" do |value|
@@ -51,14 +52,14 @@ module Caracal
51
52
  instance_variable_set("@list_item_#{ m }", value.to_s.to_sym)
52
53
  end
53
54
  end
54
-
55
-
55
+
56
+
56
57
  #=============== SUB-METHODS ===========================
57
-
58
+
58
59
  # .ol
59
60
  def ol(options={}, &block)
60
61
  options.merge!({ type: :ordered, level: list_item_level + 1 })
61
-
62
+
62
63
  model = Caracal::Core::Models::ListModel.new(options, &block)
63
64
  if model.valid?
64
65
  @nested_list = model
@@ -67,11 +68,11 @@ module Caracal
67
68
  end
68
69
  model
69
70
  end
70
-
71
+
71
72
  # .ul
72
73
  def ul(options={}, &block)
73
74
  options.merge!({ type: :unordered, level: list_item_level + 1 })
74
-
75
+
75
76
  model = Caracal::Core::Models::ListModel.new(options, &block)
76
77
  if model.valid?
77
78
  @nested_list = model
@@ -80,28 +81,28 @@ module Caracal
80
81
  end
81
82
  model
82
83
  end
83
-
84
-
84
+
85
+
85
86
  #=============== VALIDATION ===========================
86
-
87
+
87
88
  def valid?
88
89
  a = [:type, :level]
89
90
  required = a.map { |m| send("list_item_#{ m }") }.compact.size == a.size
90
91
  required && !runs.empty?
91
92
  end
92
-
93
-
93
+
94
+
94
95
  #-------------------------------------------------------------
95
96
  # Private Instance Methods
96
97
  #-------------------------------------------------------------
97
98
  private
98
-
99
+
99
100
  def option_keys
100
- [:type, :level, :content, :style, :color, :size, :bold, :italic, :underline]
101
+ [:type, :level, :content, :style, :color, :size, :bold, :italic, :underline, :bgcolor]
101
102
  end
102
-
103
+
103
104
  end
104
-
105
+
105
106
  end
106
107
  end
107
- end
108
+ end
@@ -7,16 +7,16 @@ require 'caracal/errors'
7
7
  module Caracal
8
8
  module Core
9
9
  module Models
10
-
10
+
11
11
  # This class encapsulates the logic needed to store and manipulate
12
12
  # paragraph data.
13
13
  #
14
14
  class ParagraphModel < BaseModel
15
-
15
+
16
16
  #-------------------------------------------------------------
17
17
  # Configuration
18
18
  #-------------------------------------------------------------
19
-
19
+
20
20
  # readers
21
21
  attr_reader :paragraph_style
22
22
  attr_reader :paragraph_align
@@ -25,26 +25,27 @@ module Caracal
25
25
  attr_reader :paragraph_bold
26
26
  attr_reader :paragraph_italic
27
27
  attr_reader :paragraph_underline
28
-
28
+ attr_reader :paragraph_bgcolor
29
+
29
30
  # initialization
30
31
  def initialize(options={}, &block)
31
32
  content = options.delete(:content) { "" }
32
33
  text content, options.dup
33
34
  super options, &block
34
35
  end
35
-
36
-
36
+
37
+
37
38
  #-------------------------------------------------------------
38
39
  # Public Instance Methods
39
40
  #-------------------------------------------------------------
40
-
41
+
41
42
  #=============== GETTERS ==============================
42
-
43
+
43
44
  # .runs
44
45
  def runs
45
46
  @runs ||= []
46
47
  end
47
-
48
+
48
49
  # .run_attributes
49
50
  def run_attributes
50
51
  {
@@ -53,49 +54,50 @@ module Caracal
53
54
  bold: paragraph_bold,
54
55
  italic: paragraph_italic,
55
56
  underline: paragraph_underline,
57
+ bgcolor: paragraph_bgcolor
56
58
  }
57
59
  end
58
-
59
-
60
+
61
+
60
62
  #=============== SETTERS ==============================
61
-
63
+
62
64
  # booleans
63
65
  [:bold, :italic, :underline].each do |m|
64
66
  define_method "#{ m }" do |value|
65
67
  instance_variable_set("@paragraph_#{ m }", !!value)
66
68
  end
67
69
  end
68
-
70
+
69
71
  # integers
70
72
  [:size].each do |m|
71
73
  define_method "#{ m }" do |value|
72
74
  instance_variable_set("@paragraph_#{ m }", value.to_i)
73
75
  end
74
76
  end
75
-
77
+
76
78
  # strings
77
- [:color, :style].each do |m|
79
+ [:bgcolor, :color, :style].each do |m|
78
80
  define_method "#{ m }" do |value|
79
81
  instance_variable_set("@paragraph_#{ m }", value.to_s)
80
82
  end
81
83
  end
82
-
84
+
83
85
  # symbols
84
86
  [:align].each do |m|
85
87
  define_method "#{ m }" do |value|
86
88
  instance_variable_set("@paragraph_#{ m }", value.to_s.to_sym)
87
89
  end
88
90
  end
89
-
90
-
91
+
92
+
91
93
  #=============== SUB-METHODS ===========================
92
-
94
+
93
95
  # .link
94
96
  def link(*args, &block)
95
97
  options = Caracal::Utilities.extract_options!(args)
96
98
  options.merge!({ content: args[0] }) if args[0]
97
99
  options.merge!({ href: args[1] }) if args[1]
98
-
100
+
99
101
  model = Caracal::Core::Models::LinkModel.new(options, &block)
100
102
  if model.valid?
101
103
  runs << model
@@ -111,12 +113,12 @@ module Caracal
111
113
  runs << model
112
114
  model
113
115
  end
114
-
116
+
115
117
  # .text
116
118
  def text(*args, &block)
117
119
  options = Caracal::Utilities.extract_options!(args)
118
120
  options.merge!({ content: args.first }) if args.first
119
-
121
+
120
122
  model = Caracal::Core::Models::TextModel.new(options, &block)
121
123
  if model.valid?
122
124
  runs << model
@@ -125,26 +127,26 @@ module Caracal
125
127
  end
126
128
  model
127
129
  end
128
-
129
-
130
+
131
+
130
132
  #=============== VALIDATION ===========================
131
-
133
+
132
134
  def valid?
133
135
  runs.size > 0
134
136
  end
135
-
136
-
137
+
138
+
137
139
  #-------------------------------------------------------------
138
140
  # Private Instance Methods
139
141
  #-------------------------------------------------------------
140
142
  private
141
-
143
+
142
144
  def option_keys
143
- [:content, :style, :align, :color, :size, :bold, :italic, :underline]
145
+ [:content, :style, :align, :color, :size, :bold, :italic, :underline, :bgcolor]
144
146
  end
145
-
147
+
146
148
  end
147
-
149
+
148
150
  end
149
151
  end
150
152
  end
@@ -22,6 +22,7 @@ module Caracal
22
22
  attr_reader :text_bold
23
23
  attr_reader :text_italic
24
24
  attr_reader :text_underline
25
+ attr_reader :text_bgcolor
25
26
 
26
27
 
27
28
 
@@ -40,6 +41,7 @@ module Caracal
40
41
  bold: text_bold,
41
42
  italic: text_italic,
42
43
  underline: text_underline,
44
+ bgcolor: text_bgcolor
43
45
  }
44
46
  end
45
47
 
@@ -61,7 +63,7 @@ module Caracal
61
63
  end
62
64
 
63
65
  # strings
64
- [:color, :content, :font].each do |m|
66
+ [:bgcolor, :color, :content, :font].each do |m|
65
67
  define_method "#{ m }" do |value|
66
68
  instance_variable_set("@text_#{ m }", value.to_s)
67
69
  end
@@ -82,7 +84,7 @@ module Caracal
82
84
  private
83
85
 
84
86
  def option_keys
85
- [:content, :font, :color, :size, :bold, :italic, :underline]
87
+ [:content, :font, :color, :size, :bold, :italic, :underline, :bgcolor]
86
88
  end
87
89
 
88
90
  end
@@ -74,13 +74,17 @@ module Caracal
74
74
  # skip
75
75
  else
76
76
  xml.send 'w:rPr' do
77
+ puts '='*80
78
+ puts attrs.inspect
79
+ puts '='*80
77
80
  unless attrs.empty?
78
- xml.send 'w:rStyle', { 'w:val' => attrs[:style] } unless attrs[:style].nil?
79
- xml.send 'w:color', { 'w:val' => attrs[:color] } unless attrs[:color].nil?
80
- xml.send 'w:sz', { 'w:val' => attrs[:size] } unless attrs[:size].nil?
81
- xml.send 'w:b', { 'w:val' => (attrs[:bold] ? '1' : '0') } unless attrs[:bold].nil?
82
- xml.send 'w:i', { 'w:val' => (attrs[:italic] ? '1' : '0') } unless attrs[:italic].nil?
83
- xml.send 'w:u', { 'w:val' => (attrs[:underline] ? 'single' : 'none') } unless attrs[:underline].nil?
81
+ xml.send 'w:rStyle', { 'w:val' => attrs[:style] } unless attrs[:style].nil?
82
+ xml.send 'w:color', { 'w:val' => attrs[:color] } unless attrs[:color].nil?
83
+ xml.send 'w:sz', { 'w:val' => attrs[:size] } unless attrs[:size].nil?
84
+ xml.send 'w:b', { 'w:val' => (attrs[:bold] ? '1' : '0') } unless attrs[:bold].nil?
85
+ xml.send 'w:i', { 'w:val' => (attrs[:italic] ? '1' : '0') } unless attrs[:italic].nil?
86
+ xml.send 'w:u', { 'w:val' => (attrs[:underline] ? 'single' : 'none') } unless attrs[:underline].nil?
87
+ xml.send 'w:shd', { 'w:fill' => attrs[:bgcolor], 'w:val' => 'clear' } unless attrs[:bgcolor].nil?
84
88
  unless attrs[:font].nil?
85
89
  f = attrs[:font]
86
90
  xml.send 'w:rFonts', { 'w:ascii' => f, 'w:hAnsi' => f, 'w:eastAsia' => f, 'w:cs' => f }
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -11,6 +11,7 @@ describe Caracal::Core::Models::LinkModel do
11
11
  bold false
12
12
  italic false
13
13
  underline true
14
+ bgcolor 'cccccc'
14
15
  end
15
16
  end
16
17
 
@@ -36,6 +37,7 @@ describe Caracal::Core::Models::LinkModel do
36
37
  it { expect(subject.link_bold).to eq false }
37
38
  it { expect(subject.link_italic).to eq false }
38
39
  it { expect(subject.link_underline).to eq true }
40
+ it { expect(subject.link_bgcolor).to eq 'cccccc' }
39
41
  end
40
42
 
41
43
  end
@@ -51,7 +53,7 @@ describe Caracal::Core::Models::LinkModel do
51
53
 
52
54
  # .run_attributes
53
55
  describe '.run_attributes' do
54
- let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true } }
56
+ let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
55
57
 
56
58
  it { expect(subject.run_attributes).to eq expected }
57
59
  end
@@ -84,6 +86,11 @@ describe Caracal::Core::Models::LinkModel do
84
86
  end
85
87
 
86
88
  # strings
89
+ describe '.bgcolor' do
90
+ before { subject.bgcolor('dddddd') }
91
+
92
+ it { expect(subject.link_bgcolor).to eq 'dddddd' }
93
+ end
87
94
  describe '.color' do
88
95
  before { subject.color('999999') }
89
96
 
@@ -135,7 +142,7 @@ describe Caracal::Core::Models::LinkModel do
135
142
  # .option_keys
136
143
  describe '.option_keys' do
137
144
  let(:actual) { subject.send(:option_keys).sort }
138
- let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline].sort }
145
+ let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline, :bgcolor].sort }
139
146
 
140
147
  it { expect(actual).to eq expected }
141
148
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Caracal::Core::Models::ListItemModel do
4
- subject do
5
- described_class.new content: 'Lorem ipsum dolor....' do
4
+ subject do
5
+ described_class.new content: 'Lorem ipsum dolor....' do
6
6
  type :ordered
7
7
  level 2
8
8
  style 'Fancy'
@@ -11,15 +11,16 @@ describe Caracal::Core::Models::ListItemModel do
11
11
  bold false
12
12
  italic false
13
13
  underline true
14
+ bgcolor 'cccccc'
14
15
  end
15
16
  end
16
-
17
+
17
18
  #-------------------------------------------------------------
18
19
  # Configuration
19
20
  #-------------------------------------------------------------
20
21
 
21
22
  describe 'configuration tests' do
22
-
23
+
23
24
  # accessors
24
25
  describe 'accessors' do
25
26
  it { expect(subject.respond_to? :nested_list).to eq true }
@@ -32,96 +33,102 @@ describe Caracal::Core::Models::ListItemModel do
32
33
  it { expect(subject.list_item_bold).to eq false }
33
34
  it { expect(subject.list_item_italic).to eq false }
34
35
  it { expect(subject.list_item_underline).to eq true }
36
+ it { expect(subject.list_item_bgcolor).to eq 'cccccc' }
35
37
  end
36
-
38
+
37
39
  end
38
-
39
-
40
+
41
+
40
42
  #-------------------------------------------------------------
41
43
  # Public Methods
42
44
  #-------------------------------------------------------------
43
-
45
+
44
46
  describe 'public method tests' do
45
-
47
+
46
48
  #=============== GETTERS ==========================
47
-
49
+
48
50
  # .runs
49
51
  describe '.runs' do
50
52
  it { expect(subject.runs).to be_a(Array) }
51
53
  end
52
-
53
-
54
+
55
+
54
56
  #=============== SETTERS ==========================
55
-
57
+
56
58
  # booleans
57
59
  describe '.bold' do
58
60
  before { subject.bold(true) }
59
-
61
+
60
62
  it { expect(subject.list_item_bold).to eq true }
61
63
  end
62
64
  describe '.italic' do
63
65
  before { subject.italic(true) }
64
-
66
+
65
67
  it { expect(subject.list_item_italic).to eq true }
66
68
  end
67
69
  describe '.underline' do
68
70
  before { subject.underline(true) }
69
-
71
+
70
72
  it { expect(subject.list_item_underline).to eq true }
71
73
  end
72
-
74
+
73
75
  # integers
74
76
  describe '.level' do
75
77
  before { subject.level(3) }
76
-
78
+
77
79
  it { expect(subject.list_item_level).to eq 3 }
78
80
  end
79
81
  describe '.size' do
80
82
  before { subject.size(24) }
81
-
83
+
82
84
  it { expect(subject.list_item_size).to eq 24 }
83
85
  end
84
-
86
+
85
87
  # strings
88
+ describe '.bgcolor' do
89
+ before { subject.bgcolor('dddddd') }
90
+
91
+ it { expect(subject.list_item_bgcolor).to eq 'dddddd' }
92
+ end
86
93
  describe '.color' do
87
94
  before { subject.color('999999') }
88
-
95
+
89
96
  it { expect(subject.list_item_color).to eq '999999' }
90
97
  end
91
98
  describe '.style' do
92
99
  before { subject.style('Dummy') }
93
-
100
+
94
101
  it { expect(subject.list_item_style).to eq 'Dummy' }
95
102
  end
96
-
103
+
97
104
  # symbols
98
105
  describe '.type' do
99
106
  before { subject.type(:ordered) }
100
-
107
+
101
108
  it { expect(subject.list_item_type).to eq :ordered }
102
109
  end
103
-
104
-
110
+
111
+
105
112
  #=============== SUB-METHODS ==========================
106
-
113
+
107
114
  # .link
108
115
  describe '.link' do
109
116
  let!(:length) { subject.runs.length }
110
-
117
+
111
118
  before { subject.link 'Text', 'http://www.google.com' }
112
-
119
+
113
120
  it { expect(subject.runs.size).to eq length + 1 }
114
121
  end
115
-
122
+
116
123
  # .text
117
124
  describe '.text' do
118
125
  let!(:length) { subject.runs.length }
119
-
126
+
120
127
  before { subject.text 'Text' }
121
-
128
+
122
129
  it { expect(subject.runs.size).to eq length + 1 }
123
130
  end
124
-
131
+
125
132
  # .ol
126
133
  describe '.ol' do
127
134
  describe 'when no nested list provided' do
@@ -130,7 +137,7 @@ describe Caracal::Core::Models::ListItemModel do
130
137
  text 'Item text.'
131
138
  end
132
139
  end
133
-
140
+
134
141
  it { expect(subject.nested_list).to eq nil }
135
142
  end
136
143
  describe 'when nested list provided' do
@@ -142,49 +149,49 @@ describe Caracal::Core::Models::ListItemModel do
142
149
  end
143
150
  end
144
151
  end
145
-
152
+
146
153
  it { expect(subject.nested_list).to be_a(Caracal::Core::Models::ListModel) }
147
154
  end
148
155
  end
149
-
150
-
151
-
156
+
157
+
158
+
152
159
  #=============== VALIDATION ===========================
153
-
160
+
154
161
  describe '.valid?' do
155
162
  describe 'when at least one run exists' do
156
163
  before do
157
164
  allow(subject).to receive(:runs).and_return(['a'])
158
165
  end
159
-
166
+
160
167
  it { expect(subject.valid?).to eq true }
161
168
  end
162
169
  describe 'when no runs exist' do
163
170
  before do
164
171
  allow(subject).to receive(:runs).and_return([])
165
172
  end
166
-
173
+
167
174
  it { expect(subject.valid?).to eq false }
168
175
  end
169
176
  end
170
-
177
+
171
178
  end
172
-
173
-
179
+
180
+
174
181
  #-------------------------------------------------------------
175
182
  # Private Methods
176
183
  #-------------------------------------------------------------
177
-
184
+
178
185
  describe 'private method tests' do
179
-
186
+
180
187
  # .option_keys
181
188
  describe '.option_keys' do
182
189
  let(:actual) { subject.send(:option_keys).sort }
183
- let(:expected) { [:type, :level, :content, :style, :color, :size, :bold, :italic, :underline].sort }
184
-
190
+ let(:expected) { [:type, :level, :content, :style, :color, :size, :bold, :italic, :underline, :bgcolor].sort }
191
+
185
192
  it { expect(actual).to eq expected }
186
193
  end
187
-
194
+
188
195
  end
189
-
190
- end
196
+
197
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Caracal::Core::Models::ParagraphModel do
4
- subject do
5
- described_class.new content: 'Lorem ipsum dolor....' do
4
+ subject do
5
+ described_class.new content: 'Lorem ipsum dolor....' do
6
6
  style 'Fancy'
7
7
  align :right
8
8
  color '666666'
@@ -10,16 +10,17 @@ describe Caracal::Core::Models::ParagraphModel do
10
10
  bold false
11
11
  italic false
12
12
  underline true
13
+ bgcolor 'cccccc'
13
14
  end
14
15
  end
15
-
16
+
16
17
 
17
18
  #-------------------------------------------------------------
18
19
  # Configuration
19
20
  #-------------------------------------------------------------
20
21
 
21
22
  describe 'configuration tests' do
22
-
23
+
23
24
  # accessors
24
25
  describe 'accessors' do
25
26
  it { expect(subject.paragraph_style).to eq 'Fancy' }
@@ -29,144 +30,150 @@ describe Caracal::Core::Models::ParagraphModel do
29
30
  it { expect(subject.paragraph_bold).to eq false }
30
31
  it { expect(subject.paragraph_italic).to eq false }
31
32
  it { expect(subject.paragraph_underline).to eq true }
33
+ it { expect(subject.paragraph_bgcolor).to eq 'cccccc' }
32
34
  end
33
35
 
34
36
  end
35
37
 
36
-
38
+
37
39
  #-------------------------------------------------------------
38
40
  # Public Methods
39
41
  #-------------------------------------------------------------
40
-
42
+
41
43
  describe 'public method tests' do
42
-
44
+
43
45
  #=============== GETTERS ==========================
44
-
46
+
45
47
  # .runs
46
48
  describe '.runs' do
47
49
  it { expect(subject.runs).to be_a(Array) }
48
50
  end
49
-
51
+
50
52
  # .run_attributes
51
53
  describe '.run_attributes' do
52
- let(:expected) { { color: '666666', size: 20, bold: false, italic: false, underline: true } }
53
-
54
+ let(:expected) { { color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
55
+
54
56
  it { expect(subject.run_attributes).to eq expected }
55
57
  end
56
-
57
-
58
+
59
+
58
60
  #=============== SETTERS ==========================
59
-
61
+
60
62
  # booleans
61
63
  describe '.bold' do
62
64
  before { subject.bold(true) }
63
-
65
+
64
66
  it { expect(subject.paragraph_bold).to eq true }
65
67
  end
66
68
  describe '.italic' do
67
69
  before { subject.italic(true) }
68
-
70
+
69
71
  it { expect(subject.paragraph_italic).to eq true }
70
72
  end
71
73
  describe '.underline' do
72
74
  before { subject.underline(true) }
73
-
75
+
74
76
  it { expect(subject.paragraph_underline).to eq true }
75
77
  end
76
-
78
+
77
79
  # integers
78
80
  describe '.size' do
79
81
  before { subject.size(24) }
80
-
82
+
81
83
  it { expect(subject.paragraph_size).to eq 24 }
82
84
  end
83
-
85
+
84
86
  # strings
87
+ describe '.bgcolor' do
88
+ before { subject.bgcolor('dddddd') }
89
+
90
+ it { expect(subject.paragraph_bgcolor).to eq 'dddddd' }
91
+ end
85
92
  describe '.color' do
86
93
  before { subject.color('999999') }
87
-
94
+
88
95
  it { expect(subject.paragraph_color).to eq '999999' }
89
96
  end
90
97
  describe '.style' do
91
98
  before { subject.style('Dummy') }
92
-
99
+
93
100
  it { expect(subject.paragraph_style).to eq 'Dummy' }
94
101
  end
95
-
102
+
96
103
  # symbols
97
104
  describe '.align' do
98
105
  before { subject.align(:center) }
99
-
106
+
100
107
  it { expect(subject.paragraph_align).to eq :center }
101
108
  end
102
-
103
-
109
+
110
+
104
111
  #=============== SUB-METHODS ==========================
105
-
112
+
106
113
  # .link
107
114
  describe '.link' do
108
115
  let!(:length) { subject.runs.length }
109
-
116
+
110
117
  before { subject.link 'Text', 'http://www.google.com' }
111
-
118
+
112
119
  it { expect(subject.runs.size).to eq length + 1 }
113
120
  end
114
121
 
115
122
  # .br
116
123
  describe '.br' do
117
124
  let!(:length) { subject.runs.length }
118
-
125
+
119
126
  before { subject.br }
120
-
127
+
121
128
  it { expect(subject.runs.size).to eq length + 1 }
122
129
  end
123
-
130
+
124
131
  # .text
125
132
  describe '.text' do
126
133
  let!(:length) { subject.runs.length }
127
-
134
+
128
135
  before { subject.text 'Text' }
129
-
136
+
130
137
  it { expect(subject.runs.size).to eq length + 1 }
131
138
  end
132
-
133
-
139
+
140
+
134
141
  #=============== VALIDATION ===========================
135
-
142
+
136
143
  describe '.valid?' do
137
144
  describe 'when at least one run exists' do
138
145
  before do
139
146
  allow(subject).to receive(:runs).and_return(['a'])
140
147
  end
141
-
148
+
142
149
  it { expect(subject.valid?).to eq true }
143
150
  end
144
151
  describe 'when no runs exist' do
145
152
  before do
146
153
  allow(subject).to receive(:runs).and_return([])
147
154
  end
148
-
155
+
149
156
  it { expect(subject.valid?).to eq false }
150
157
  end
151
158
  end
152
-
159
+
153
160
  end
154
-
155
-
161
+
162
+
156
163
  #-------------------------------------------------------------
157
164
  # Private Methods
158
165
  #-------------------------------------------------------------
159
-
166
+
160
167
  describe 'private method tests' do
161
-
168
+
162
169
  # .option_keys
163
170
  describe '.option_keys' do
164
171
  let(:actual) { subject.send(:option_keys).sort }
165
- let(:expected) { [:content, :style, :align, :color, :size, :bold, :italic, :underline].sort }
166
-
172
+ let(:expected) { [:content, :style, :align, :color, :size, :bold, :italic, :underline, :bgcolor].sort }
173
+
167
174
  it { expect(actual).to eq expected }
168
175
  end
169
-
176
+
170
177
  end
171
-
178
+
172
179
  end
@@ -10,6 +10,7 @@ describe Caracal::Core::Models::TextModel do
10
10
  bold false
11
11
  italic false
12
12
  underline true
13
+ bgcolor 'cccccc'
13
14
  end
14
15
  end
15
16
 
@@ -28,6 +29,7 @@ describe Caracal::Core::Models::TextModel do
28
29
  it { expect(subject.text_bold).to eq false }
29
30
  it { expect(subject.text_italic).to eq false }
30
31
  it { expect(subject.text_underline).to eq true }
32
+ it { expect(subject.text_bgcolor).to eq 'cccccc' }
31
33
  end
32
34
 
33
35
  end
@@ -43,7 +45,7 @@ describe Caracal::Core::Models::TextModel do
43
45
 
44
46
  # .run_attributes
45
47
  describe '.run_attributes' do
46
- let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true } }
48
+ let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
47
49
 
48
50
  it { expect(subject.run_attributes).to eq expected }
49
51
  end
@@ -76,6 +78,11 @@ describe Caracal::Core::Models::TextModel do
76
78
  end
77
79
 
78
80
  # strings
81
+ describe '.bgcolor' do
82
+ before { subject.color('dddddd') }
83
+
84
+ it { expect(subject.text_color).to eq 'dddddd' }
85
+ end
79
86
  describe '.color' do
80
87
  before { subject.color('999999') }
81
88
 
@@ -122,7 +129,7 @@ describe Caracal::Core::Models::TextModel do
122
129
  # .option_keys
123
130
  describe '.option_keys' do
124
131
  let(:actual) { subject.send(:option_keys).sort }
125
- let(:expected) { [:content, :font, :color, :size, :bold, :italic, :underline].sort }
132
+ let(:expected) { [:bgcolor, :bold, :color, :content, :font, :italic, :size, :underline].sort }
126
133
 
127
134
  it { expect(actual).to eq expected }
128
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caracal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trade Infomatics
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-29 00:00:00.000000000 Z
12
+ date: 2015-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.2.2
220
+ rubygems_version: 2.4.8
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: Fast, professional MSWord writer for Ruby.
@@ -257,3 +257,4 @@ test_files:
257
257
  - spec/lib/caracal/core/text_spec.rb
258
258
  - spec/lib/caracal/errors_spec.rb
259
259
  - spec/spec_helper.rb
260
+ has_rdoc: