caracal 0.2.1 → 0.3.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: 40031dc07952a23e5f4f7f5528155f2b81d1d9e4
4
- data.tar.gz: d015ece8fef1d66888e8f2f851705b02bdb34dce
3
+ metadata.gz: d7769025e3ab813a92fc9938b135585a7fdb882e
4
+ data.tar.gz: 6de21a3c1f17285a381574a0660fd00dfdfab600
5
5
  SHA512:
6
- metadata.gz: 8ee50065caf4feaca536714e7b6b1feee99fa479986f5e9ae995cc14f3d268487db7301e1f4ee3b8bf4764d13ac3cae77c1eac9aba5792c7a5d633813cfa5996
7
- data.tar.gz: 1442f8a0e3d543a6174d7daea7d1992ae3a278c3d5ca48d141675def7ec982e799217b13306c2949517b72b8465b35f8945dfcfea761afc81161b1863f0836ab
6
+ metadata.gz: a45af91ce82098dc55b1d80762e9b8fcff6f78b1c969c86a8da8822ab94eccc8fbbd333752c8f02bbed6d35c88aaa8b1d7f6cba7d486d64114df22566142bf7c
7
+ data.tar.gz: 95bc1696fb6e774a05d3ae2fc0248c95c2f433ea0192f9075bc741075d9e4101c1b65ede67b1acaf52ea0600d0a238d4e4595baf503c7a917a673941551f47ad
@@ -1,8 +1,14 @@
1
- #### Unreleased
1
+ #### v0.3.0
2
+
3
+ * Deprecations
4
+ * The :style attribute is no longer allowed on text and link commands. Use :font, :size, etc. instead.
2
5
 
3
- * Enhancements
4
- * Added :caps attribute to paragraph styles (@jensljungblad)
5
6
 
7
+ #### v0.2.1
8
+
9
+ * Enhancements
10
+ * Added :caps attribute to paragraph styles (@jensljungblad).
11
+ * Change table model to allow TableCellModel to be subclassed (@gh4me).
6
12
 
7
13
 
8
14
  #### v0.2.0
@@ -21,4 +27,4 @@
21
27
  #### v0.1.x
22
28
 
23
29
  * Enhancements
24
- * Initial commits. (@jpdugan)
30
+ * Initial commits. (@jpdugan)
data/README.md CHANGED
@@ -374,9 +374,9 @@ More complex paragraph runs can be accomplished by using the `text` method inste
374
374
 
375
375
  ```ruby
376
376
  docx.p do
377
- text 'Here is a sentence with a ', style: 'custom_style'
377
+ text 'Here is a sentence with a '
378
378
  link 'link', 'https://www.example.com'
379
- text ' to something awesome', color: '555555', size: 32, bold: true, italic: true, underline: true
379
+ text ' to something awesome', font: 'Courier New', color: '555555', size: 32, bold: true, italic: true, underline: true
380
380
  text '.'
381
381
  br
382
382
  text 'This text follows a line break.'
@@ -393,12 +393,12 @@ Links can be added inside paragraphs using the `link` method. The method accept
393
393
  ```ruby
394
394
  p do
395
395
  link 'Example Text', 'https://wwww.example.com' do
396
- style 'my_style' # sets the style class. defaults to nil.
397
- color '0000ff' # sets the color of the text. defaults to 1155cc.
398
- size 24 # sets the font size. units in half-points. defaults to nil.
399
- bold false # sets whether or not the text will be bold. defaults to false.
400
- italic false # sets whether or not the text will be italic. defaults to false.
401
- underline true # sets whether or not the text will be underlined. defaults to true.
396
+ font 'Courier New' # sets the font name to use. defaults to nil.
397
+ color '0000ff' # sets the color of the text. defaults to 1155cc.
398
+ size 24 # sets the font size. units in half-points. defaults to nil.
399
+ bold false # sets whether or not the text will be bold. defaults to false.
400
+ italic false # sets whether or not the text will be italic. defaults to false.
401
+ underline true # sets whether or not the text will be underlined. defaults to true.
402
402
  end
403
403
  end
404
404
  ```
@@ -4,73 +4,73 @@ require 'caracal/core/models/text_model'
4
4
  module Caracal
5
5
  module Core
6
6
  module Models
7
-
7
+
8
8
  # This class encapsulates the logic needed to store and manipulate
9
9
  # link data.
10
10
  #
11
11
  class LinkModel < TextModel
12
-
12
+
13
13
  #-------------------------------------------------------------
14
14
  # Configuration
15
15
  #-------------------------------------------------------------
16
-
16
+
17
17
  # constants
18
18
  const_set(:DEFAULT_LINK_COLOR, '1155cc')
19
- const_set(:DEFAULT_LINK_UNDERLINE, true)
20
-
21
- # readers (create aliases for superclass methods to conform
19
+ const_set(:DEFAULT_LINK_UNDERLINE, true)
20
+
21
+ # readers (create aliases for superclass methods to conform
22
22
  # to expected naming convention.)
23
23
  attr_reader :link_href
24
24
  alias_method :link_content, :text_content
25
- alias_method :link_style, :text_style
25
+ alias_method :link_font, :text_font
26
26
  alias_method :link_color, :text_color
27
27
  alias_method :link_size, :text_size
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
-
31
+
32
32
  # initialization
33
33
  def initialize(options={}, &block)
34
34
  @text_color = DEFAULT_LINK_COLOR
35
35
  @text_underline = DEFAULT_LINK_UNDERLINE
36
-
36
+
37
37
  super options, &block
38
38
  end
39
-
40
-
39
+
40
+
41
41
  #-------------------------------------------------------------
42
42
  # Public Instance Methods
43
43
  #-------------------------------------------------------------
44
-
44
+
45
45
  #=============== SETTERS ==============================
46
-
46
+
47
47
  # strings
48
48
  [:href].each do |m|
49
49
  define_method "#{ m }" do |value|
50
50
  instance_variable_set("@link_#{ m }", value.to_s)
51
51
  end
52
52
  end
53
-
54
-
53
+
54
+
55
55
  #=============== VALIDATION ===========================
56
-
56
+
57
57
  def valid?
58
58
  a = [:content, :href]
59
59
  a.map { |m| send("link_#{ m }") }.compact.size == a.size
60
60
  end
61
-
62
-
61
+
62
+
63
63
  #-------------------------------------------------------------
64
64
  # Private Instance Methods
65
65
  #-------------------------------------------------------------
66
66
  private
67
-
67
+
68
68
  def option_keys
69
69
  (super + [:href]).flatten
70
70
  end
71
-
71
+
72
72
  end
73
-
73
+
74
74
  end
75
75
  end
76
- end
76
+ end
@@ -4,37 +4,37 @@ require 'caracal/core/models/base_model'
4
4
  module Caracal
5
5
  module Core
6
6
  module Models
7
-
7
+
8
8
  # This class encapsulates the logic needed to store and manipulate
9
9
  # text data.
10
10
  #
11
11
  class TextModel < BaseModel
12
-
12
+
13
13
  #-------------------------------------------------------------
14
14
  # Configuration
15
15
  #-------------------------------------------------------------
16
-
16
+
17
17
  # accessors
18
18
  attr_reader :text_content
19
- attr_reader :text_style
19
+ attr_reader :text_font
20
20
  attr_reader :text_color
21
21
  attr_reader :text_size
22
22
  attr_reader :text_bold
23
23
  attr_reader :text_italic
24
24
  attr_reader :text_underline
25
-
26
-
27
-
25
+
26
+
27
+
28
28
  #-------------------------------------------------------------
29
29
  # Public Instance Methods
30
30
  #-------------------------------------------------------------
31
-
31
+
32
32
  #=============== GETTERS ==============================
33
-
33
+
34
34
  # .run_attributes
35
35
  def run_attributes
36
36
  {
37
- style: text_style,
37
+ font: text_font,
38
38
  color: text_color,
39
39
  size: text_size,
40
40
  bold: text_bold,
@@ -42,51 +42,51 @@ module Caracal
42
42
  underline: text_underline,
43
43
  }
44
44
  end
45
-
46
-
45
+
46
+
47
47
  #=============== SETTERS ==============================
48
-
48
+
49
49
  # booleans
50
50
  [:bold, :italic, :underline].each do |m|
51
51
  define_method "#{ m }" do |value|
52
52
  instance_variable_set("@text_#{ m }", !!value)
53
53
  end
54
54
  end
55
-
55
+
56
56
  # integers
57
57
  [:size].each do |m|
58
58
  define_method "#{ m }" do |value|
59
59
  instance_variable_set("@text_#{ m }", value.to_i)
60
60
  end
61
61
  end
62
-
62
+
63
63
  # strings
64
- [:color, :content, :style].each do |m|
64
+ [:color, :content, :font].each do |m|
65
65
  define_method "#{ m }" do |value|
66
66
  instance_variable_set("@text_#{ m }", value.to_s)
67
67
  end
68
68
  end
69
-
70
-
69
+
70
+
71
71
  #=============== VALIDATION ===========================
72
-
72
+
73
73
  def valid?
74
74
  a = [:content]
75
75
  a.map { |m| send("text_#{ m }") }.compact.size == a.size
76
76
  end
77
-
78
-
77
+
78
+
79
79
  #-------------------------------------------------------------
80
80
  # Private Instance Methods
81
81
  #-------------------------------------------------------------
82
82
  private
83
-
83
+
84
84
  def option_keys
85
- [:content, :style, :color, :size, :bold, :italic, :underline]
85
+ [:content, :font, :color, :size, :bold, :italic, :underline]
86
86
  end
87
-
87
+
88
88
  end
89
-
89
+
90
90
  end
91
91
  end
92
- end
92
+ end
@@ -7,12 +7,12 @@ require 'caracal/errors'
7
7
  module Caracal
8
8
  module Renderers
9
9
  class DocumentRenderer < XmlRenderer
10
-
10
+
11
11
  #-------------------------------------------------------------
12
12
  # Public Methods
13
13
  #-------------------------------------------------------------
14
-
15
- # This method produces the xml required for the `word/document.xml`
14
+
15
+ # This method produces the xml required for the `word/document.xml`
16
16
  # sub-document.
17
17
  #
18
18
  def to_xml
@@ -20,16 +20,16 @@ module Caracal
20
20
  xml.send 'w:document', root_options do
21
21
  xml.send 'w:background', { 'w:color' => 'FFFFFF' }
22
22
  xml.send 'w:body' do
23
-
23
+
24
24
  #============= CONTENTS ===================================
25
-
25
+
26
26
  document.contents.each do |model|
27
27
  method = render_method_for_model(model)
28
28
  send(method, xml, model)
29
29
  end
30
-
30
+
31
31
  #============= PAGE SETTINGS ==============================
32
-
32
+
33
33
  xml.send 'w:sectPr' do
34
34
  if document.page_number_show
35
35
  if rel = document.find_relationship('footer1.xml')
@@ -39,37 +39,37 @@ module Caracal
39
39
  xml.send 'w:pgSz', page_size_options
40
40
  xml.send 'w:pgMar', page_margin_options
41
41
  end
42
-
42
+
43
43
  end
44
44
  end
45
45
  end
46
46
  builder.to_xml(save_options)
47
47
  end
48
-
49
-
48
+
49
+
50
50
  #-------------------------------------------------------------
51
51
  # Private Methods
52
- #-------------------------------------------------------------
52
+ #-------------------------------------------------------------
53
53
  private
54
-
54
+
55
55
  #============= COMMON RENDERERS ==========================
56
-
56
+
57
57
  # This method converts a model class name to a rendering
58
- # function on this class (e.g., Caracal::Core::Models::ParagraphModel
58
+ # function on this class (e.g., Caracal::Core::Models::ParagraphModel
59
59
  # translates to `render_paragraph`).
60
60
  #
61
61
  def render_method_for_model(model)
62
62
  type = model.class.name.split('::').last.downcase.gsub('model', '')
63
63
  "render_#{ type }"
64
64
  end
65
-
66
- # This method renders a standard node of run properties based on the
65
+
66
+ # This method renders a standard node of run properties based on the
67
67
  # model's attributes.
68
68
  #
69
69
  def render_run_attributes(xml, model, paragraph_level=false)
70
70
  if model.respond_to? :run_attributes
71
- attrs = model.run_attributes.delete_if { |k, v| v.nil? }
72
-
71
+ attrs = model.run_attributes.delete_if { |k, v| v.nil? }
72
+
73
73
  if paragraph_level && attrs.empty?
74
74
  # skip
75
75
  else
@@ -81,25 +81,29 @@ module Caracal
81
81
  xml.send 'w:b', { 'w:val' => (attrs[:bold] ? '1' : '0') } unless attrs[:bold].nil?
82
82
  xml.send 'w:i', { 'w:val' => (attrs[:italic] ? '1' : '0') } unless attrs[:italic].nil?
83
83
  xml.send 'w:u', { 'w:val' => (attrs[:underline] ? 'single' : 'none') } unless attrs[:underline].nil?
84
+ unless attrs[:font].nil?
85
+ f = attrs[:font]
86
+ xml.send 'w:rFonts', { 'w:ascii' => f, 'w:hAnsi' => f, 'w:eastAsia' => f, 'w:cs' => f }
87
+ end
84
88
  end
85
89
  xml.send 'w:rtl', { 'w:val' => '0' }
86
90
  end
87
91
  end
88
92
  end
89
93
  end
90
-
91
-
94
+
95
+
92
96
  #============= MODEL RENDERERS ===========================
93
-
97
+
94
98
  def render_image(xml, model)
95
99
  unless ds = document.default_style
96
100
  raise Caracal::Errors::NoDefaultStyleError 'Document must declare a default paragraph style.'
97
101
  end
98
-
102
+
99
103
  rel = document.relationship({ type: :image, target: model.image_url, data: model.image_data })
100
104
  rel_id = rel.relationship_id
101
105
  rel_name = rel.formatted_target
102
-
106
+
103
107
  xml.send 'w:p', paragraph_options do
104
108
  xml.send 'w:pPr' do
105
109
  xml.send 'w:spacing', { 'w:lineRule' => 'auto', 'w:line' => ds.style_line }
@@ -147,16 +151,16 @@ module Caracal
147
151
  end
148
152
  end
149
153
  end
150
-
154
+
151
155
  def render_linebreak(xml, model)
152
156
  xml.send 'w:r' do
153
157
  xml.send 'w:br'
154
158
  end
155
159
  end
156
-
160
+
157
161
  def render_link(xml, model)
158
162
  rel = document.relationship({ target: model.link_href, type: :link })
159
-
163
+
160
164
  xml.send 'w:hyperlink', { 'r:id' => rel.formatted_id } do
161
165
  xml.send 'w:r', run_options do
162
166
  render_run_attributes(xml, model, false)
@@ -164,22 +168,22 @@ module Caracal
164
168
  end
165
169
  end
166
170
  end
167
-
171
+
168
172
  def render_list(xml, model)
169
173
  if model.list_level == 0
170
174
  document.toplevel_lists << model
171
175
  list_num = document.toplevel_lists.length # numbering uses 1-based index
172
176
  end
173
-
177
+
174
178
  model.recursive_items.each do |item|
175
179
  render_listitem(xml, item, list_num)
176
180
  end
177
181
  end
178
-
182
+
179
183
  def render_listitem(xml, model, list_num)
180
184
  ls = document.find_list_style(model.list_item_type, model.list_item_level)
181
185
  hanging = ls.style_left.to_i - ls.style_indent.to_i - 1
182
-
186
+
183
187
  xml.send 'w:p', paragraph_options do
184
188
  xml.send 'w:pPr' do
185
189
  xml.send 'w:numPr' do
@@ -198,7 +202,7 @@ module Caracal
198
202
  end
199
203
  end
200
204
  end
201
-
205
+
202
206
  def render_pagebreak(xml, model)
203
207
  xml.send 'w:p', paragraph_options do
204
208
  xml.send 'w:r', run_options do
@@ -206,10 +210,10 @@ module Caracal
206
210
  end
207
211
  end
208
212
  end
209
-
213
+
210
214
  def render_paragraph(xml, model)
211
215
  run_props = [:color, :size, :bold, :italic, :underline].map { |m| model.send("paragraph_#{ m }") }.compact
212
-
216
+
213
217
  xml.send 'w:p', paragraph_options do
214
218
  xml.send 'w:pPr' do
215
219
  xml.send 'w:pStyle', { 'w:val' => model.paragraph_style } unless model.paragraph_style.nil?
@@ -221,12 +225,12 @@ module Caracal
221
225
  method = render_method_for_model(run)
222
226
  send(method, xml, run)
223
227
  end
224
- end
228
+ end
225
229
  end
226
-
230
+
227
231
  def render_rule(xml, model)
228
- options = { 'w:color' => model.rule_color, 'w:sz' => model.rule_size, 'w:val' => model.rule_line, 'w:space' => model.rule_spacing }
229
-
232
+ options = { 'w:color' => model.rule_color, 'w:sz' => model.rule_size, 'w:val' => model.rule_line, 'w:space' => model.rule_spacing }
233
+
230
234
  xml.send 'w:p', paragraph_options do
231
235
  xml.send 'w:pPr' do
232
236
  xml.send 'w:pBdr' do
@@ -235,19 +239,19 @@ module Caracal
235
239
  end
236
240
  end
237
241
  end
238
-
242
+
239
243
  def render_text(xml, model)
240
244
  xml.send 'w:r', run_options do
241
245
  render_run_attributes(xml, model, false)
242
246
  xml.send 'w:t', { 'xml:space' => 'preserve' }, model.text_content
243
247
  end
244
248
  end
245
-
249
+
246
250
  def render_table(xml, model)
247
251
  borders = %w(top left bottom right horizontal vertical).select do |m|
248
252
  model.send("table_border_#{ m }_size") > 0
249
253
  end
250
-
254
+
251
255
  xml.send 'w:tbl' do
252
256
  xml.send 'w:tblPr' do
253
257
  xml.send 'w:tblStyle', { 'w:val' => 'DefaultTable' }
@@ -304,15 +308,15 @@ module Caracal
304
308
  end
305
309
  end
306
310
  end
307
-
308
- # don't know why this is needed, but it prevents a
311
+
312
+ # don't know why this is needed, but it prevents a
309
313
  # rendering error.
310
314
  render_paragraph(xml, Caracal::Core::Models::ParagraphModel.new)
311
315
  end
312
316
 
313
-
317
+
314
318
  #============= OPTIONS ===================================
315
-
319
+
316
320
  def root_options
317
321
  {
318
322
  'xmlns:mc' => 'http://schemas.openxmlformats.org/markup-compatibility/2006',
@@ -332,23 +336,23 @@ module Caracal
332
336
  'xmlns:dgm' => 'http://schemas.openxmlformats.org/drawingml/2006/diagram'
333
337
  }
334
338
  end
335
-
339
+
336
340
  def page_margin_options
337
- {
338
- 'w:top' => document.page_margin_top,
339
- 'w:bottom' => document.page_margin_bottom,
340
- 'w:left' => document.page_margin_left,
341
- 'w:right' => document.page_margin_right
341
+ {
342
+ 'w:top' => document.page_margin_top,
343
+ 'w:bottom' => document.page_margin_bottom,
344
+ 'w:left' => document.page_margin_left,
345
+ 'w:right' => document.page_margin_right
342
346
  }
343
347
  end
344
-
348
+
345
349
  def page_size_options
346
- {
347
- 'w:w' => document.page_width,
348
- 'w:h' => document.page_height
350
+ {
351
+ 'w:w' => document.page_width,
352
+ 'w:h' => document.page_height
349
353
  }
350
354
  end
351
-
355
+
352
356
  end
353
357
  end
354
358
  end
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Caracal::Core::Models::LinkModel do
4
- subject do
4
+ subject do
5
5
  described_class.new do
6
6
  content 'Link Text'
7
7
  href 'http://www.google.com'
8
- style 'Fancy'
8
+ font 'Courier New'
9
9
  color '666666'
10
10
  size 20
11
11
  bold false
@@ -13,101 +13,101 @@ describe Caracal::Core::Models::LinkModel do
13
13
  underline true
14
14
  end
15
15
  end
16
-
16
+
17
17
  #-------------------------------------------------------------
18
18
  # Configuration
19
19
  #-------------------------------------------------------------
20
20
 
21
21
  describe 'configuration tests' do
22
-
22
+
23
23
  # constants
24
24
  describe 'constants' do
25
25
  it { expect(described_class::DEFAULT_LINK_COLOR).to eq '1155cc' }
26
26
  it { expect(described_class::DEFAULT_LINK_UNDERLINE).to eq true }
27
27
  end
28
-
28
+
29
29
  # accessors
30
30
  describe 'accessors' do
31
31
  it { expect(subject.link_content).to eq 'Link Text' }
32
32
  it { expect(subject.link_href).to eq 'http://www.google.com' }
33
- it { expect(subject.link_style).to eq 'Fancy' }
33
+ it { expect(subject.link_font).to eq 'Courier New' }
34
34
  it { expect(subject.link_color).to eq '666666' }
35
35
  it { expect(subject.link_size).to eq 20 }
36
36
  it { expect(subject.link_bold).to eq false }
37
37
  it { expect(subject.link_italic).to eq false }
38
38
  it { expect(subject.link_underline).to eq true }
39
39
  end
40
-
40
+
41
41
  end
42
-
43
-
42
+
43
+
44
44
  #-------------------------------------------------------------
45
45
  # Public Methods
46
46
  #-------------------------------------------------------------
47
-
47
+
48
48
  describe 'public method tests' do
49
-
49
+
50
50
  #=============== GETTERS ==========================
51
-
51
+
52
52
  # .run_attributes
53
53
  describe '.run_attributes' do
54
- let(:expected) { { style: 'Fancy', color: '666666', size: 20, bold: false, italic: false, underline: true } }
55
-
54
+ let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true } }
55
+
56
56
  it { expect(subject.run_attributes).to eq expected }
57
57
  end
58
-
59
-
58
+
59
+
60
60
  #=============== SETTERS ==========================
61
-
61
+
62
62
  # booleans
63
63
  describe '.bold' do
64
64
  before { subject.bold(true) }
65
-
65
+
66
66
  it { expect(subject.link_bold).to eq true }
67
67
  end
68
68
  describe '.italic' do
69
69
  before { subject.italic(true) }
70
-
70
+
71
71
  it { expect(subject.link_italic).to eq true }
72
72
  end
73
73
  describe '.underline' do
74
74
  before { subject.underline(true) }
75
-
75
+
76
76
  it { expect(subject.link_underline).to eq true }
77
77
  end
78
-
78
+
79
79
  # integers
80
80
  describe '.size' do
81
81
  before { subject.size(24) }
82
-
82
+
83
83
  it { expect(subject.link_size).to eq 24 }
84
84
  end
85
-
85
+
86
86
  # strings
87
87
  describe '.color' do
88
88
  before { subject.color('999999') }
89
-
89
+
90
90
  it { expect(subject.link_color).to eq '999999' }
91
91
  end
92
92
  describe '.content' do
93
93
  before { subject.content('Something Else') }
94
-
94
+
95
95
  it { expect(subject.link_content).to eq 'Something Else' }
96
96
  end
97
97
  describe '.href' do
98
98
  before { subject.href('http://www.google.com') }
99
-
99
+
100
100
  it { expect(subject.link_href).to eq 'http://www.google.com' }
101
101
  end
102
- describe '.style' do
103
- before { subject.style('Dummy') }
104
-
105
- it { expect(subject.link_style).to eq 'Dummy' }
102
+ describe '.font' do
103
+ before { subject.font('Palantino') }
104
+
105
+ it { expect(subject.link_font).to eq 'Palantino' }
106
106
  end
107
-
108
-
107
+
108
+
109
109
  #=============== VALIDATION ===========================
110
-
110
+
111
111
  describe '.valid?' do
112
112
  describe 'when required attributes provided' do
113
113
  it { expect(subject.valid?).to eq true }
@@ -117,29 +117,29 @@ describe Caracal::Core::Models::LinkModel do
117
117
  before do
118
118
  allow(subject).to receive("link_#{ prop }").and_return(nil)
119
119
  end
120
-
120
+
121
121
  it { expect(subject.valid?).to eq false }
122
122
  end
123
123
  end
124
124
  end
125
-
125
+
126
126
  end
127
-
128
-
127
+
128
+
129
129
  #-------------------------------------------------------------
130
130
  # Private Methods
131
131
  #-------------------------------------------------------------
132
-
132
+
133
133
  describe 'private method tests' do
134
-
134
+
135
135
  # .option_keys
136
136
  describe '.option_keys' do
137
137
  let(:actual) { subject.send(:option_keys).sort }
138
- let(:expected) { [:content, :href, :style, :color, :size, :bold, :italic, :underline].sort }
139
-
138
+ let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline].sort }
139
+
140
140
  it { expect(actual).to eq expected }
141
141
  end
142
-
142
+
143
143
  end
144
-
145
- end
144
+
145
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Caracal::Core::Models::TextModel do
4
- subject do
4
+ subject do
5
5
  described_class.new do
6
6
  content 'Lorem ipsum dolor....'
7
- style 'Fancy'
7
+ font 'Courier New'
8
8
  color '666666'
9
9
  size 20
10
10
  bold false
@@ -12,89 +12,89 @@ describe Caracal::Core::Models::TextModel do
12
12
  underline true
13
13
  end
14
14
  end
15
-
15
+
16
16
  #-------------------------------------------------------------
17
17
  # Configuration
18
18
  #-------------------------------------------------------------
19
19
 
20
20
  describe 'configuration tests' do
21
-
21
+
22
22
  # accessors
23
23
  describe 'accessors' do
24
24
  it { expect(subject.text_content).to eq 'Lorem ipsum dolor....' }
25
- it { expect(subject.text_style).to eq 'Fancy' }
25
+ it { expect(subject.text_font).to eq 'Courier New' }
26
26
  it { expect(subject.text_color).to eq '666666' }
27
27
  it { expect(subject.text_size).to eq 20 }
28
28
  it { expect(subject.text_bold).to eq false }
29
29
  it { expect(subject.text_italic).to eq false }
30
30
  it { expect(subject.text_underline).to eq true }
31
31
  end
32
-
32
+
33
33
  end
34
-
35
-
34
+
35
+
36
36
  #-------------------------------------------------------------
37
37
  # Public Methods
38
38
  #-------------------------------------------------------------
39
-
39
+
40
40
  describe 'public method tests' do
41
-
41
+
42
42
  #=============== GETTERS ==========================
43
-
43
+
44
44
  # .run_attributes
45
45
  describe '.run_attributes' do
46
- let(:expected) { { style: 'Fancy', color: '666666', size: 20, bold: false, italic: false, underline: true } }
47
-
46
+ let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true } }
47
+
48
48
  it { expect(subject.run_attributes).to eq expected }
49
49
  end
50
-
51
-
50
+
51
+
52
52
  #=============== SETTERS ==========================
53
-
53
+
54
54
  # booleans
55
55
  describe '.bold' do
56
56
  before { subject.bold(true) }
57
-
57
+
58
58
  it { expect(subject.text_bold).to eq true }
59
59
  end
60
60
  describe '.italic' do
61
61
  before { subject.italic(true) }
62
-
62
+
63
63
  it { expect(subject.text_italic).to eq true }
64
64
  end
65
65
  describe '.underline' do
66
66
  before { subject.underline(true) }
67
-
67
+
68
68
  it { expect(subject.text_underline).to eq true }
69
69
  end
70
-
70
+
71
71
  # integers
72
72
  describe '.size' do
73
73
  before { subject.size(24) }
74
-
74
+
75
75
  it { expect(subject.text_size).to eq 24 }
76
76
  end
77
-
77
+
78
78
  # strings
79
79
  describe '.color' do
80
80
  before { subject.color('999999') }
81
-
81
+
82
82
  it { expect(subject.text_color).to eq '999999' }
83
83
  end
84
84
  describe '.content' do
85
85
  before { subject.content('Something Else') }
86
-
86
+
87
87
  it { expect(subject.text_content).to eq 'Something Else' }
88
88
  end
89
- describe '.style' do
90
- before { subject.style('Dummy') }
91
-
92
- it { expect(subject.text_style).to eq 'Dummy' }
89
+ describe '.font' do
90
+ before { subject.font('Palantino') }
91
+
92
+ it { expect(subject.text_font).to eq 'Palantino' }
93
93
  end
94
-
95
-
94
+
95
+
96
96
  #=============== VALIDATION ===========================
97
-
97
+
98
98
  describe '.valid?' do
99
99
  describe 'when required attributes provided' do
100
100
  it { expect(subject.valid?).to eq true }
@@ -104,29 +104,29 @@ describe Caracal::Core::Models::TextModel do
104
104
  before do
105
105
  allow(subject).to receive("text_#{ prop }").and_return(nil)
106
106
  end
107
-
107
+
108
108
  it { expect(subject.valid?).to eq false }
109
109
  end
110
110
  end
111
111
  end
112
-
112
+
113
113
  end
114
-
115
-
114
+
115
+
116
116
  #-------------------------------------------------------------
117
117
  # Private Methods
118
118
  #-------------------------------------------------------------
119
-
119
+
120
120
  describe 'private method tests' do
121
-
121
+
122
122
  # .option_keys
123
123
  describe '.option_keys' do
124
124
  let(:actual) { subject.send(:option_keys).sort }
125
- let(:expected) { [:content, :style, :color, :size, :bold, :italic, :underline].sort }
126
-
125
+ let(:expected) { [:content, :font, :color, :size, :bold, :italic, :underline].sort }
126
+
127
127
  it { expect(actual).to eq expected }
128
128
  end
129
-
129
+
130
130
  end
131
-
132
- end
131
+
132
+ 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.2.1
4
+ version: 0.3.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: 2014-11-28 00:00:00.000000000 Z
12
+ date: 2015-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri