caracal 1.2.0 → 1.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +53 -25
- data/lib/caracal/core/bookmarks.rb +52 -0
- data/lib/caracal/core/models/bookmark_model.rb +86 -0
- data/lib/caracal/core/models/link_model.rb +34 -17
- data/lib/caracal/core/models/paragraph_model.rb +37 -10
- data/lib/caracal/core/models/text_model.rb +13 -11
- data/lib/caracal/document.rb +2 -0
- data/lib/caracal/renderers/core_renderer.rb +1 -1
- data/lib/caracal/renderers/document_renderer.rb +16 -2
- data/lib/caracal/version.rb +1 -1
- data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
- data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
- data/spec/lib/caracal/core/models/link_model_spec.rb +41 -15
- data/spec/lib/caracal/core/models/paragraph_model_spec.rb +17 -0
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +1 -1
- data/spec/lib/caracal/core/models/text_model_spec.rb +11 -4
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52dc6e582d7e47010ca9fc90d1e02f20944d55faa485548c881bec1091c45e96
|
4
|
+
data.tar.gz: b6f22eebb075a7852b0ea30ea595ca6ca89f7b98e40564ff3ab2b68c9f004039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9651b63df3aa217d25c8ed1f9c3676a57071f3c4e7532053c76f0d07ead18e399c0dcc79c40427959bd275966c60e8be5b72ac0620f0bfd8853aff0ff1a1ddc4
|
7
|
+
data.tar.gz: 9b9bd2396372f9fe4334eccbeddee4bff14aa7f3b14acc595fe6dbdeba858f37017c3b64d38b28b9efd60f26b11351590122bff05d73f7fb3cffefa36c9dee3a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -405,15 +405,16 @@ docx.p 'Sample text.'
|
|
405
405
|
docx.p 'Sample text.', style: 'custom_style'
|
406
406
|
|
407
407
|
docx.p 'Sample text.' do
|
408
|
-
style
|
409
|
-
align
|
410
|
-
color
|
411
|
-
size
|
412
|
-
bold
|
413
|
-
italic
|
414
|
-
underline
|
415
|
-
bgcolor
|
416
|
-
|
408
|
+
style 'custom_style' # sets the paragraph style. generally used at the exclusion of other attributes.
|
409
|
+
align :left # sets the alignment. accepts :left, :center, :right, and :both.
|
410
|
+
color '333333' # sets the font color.
|
411
|
+
size 32 # sets the font size. units in 1/2 points.
|
412
|
+
bold true # sets whether or not to render the text with a bold weight.
|
413
|
+
italic false # sets whether or not render the text in italic style.
|
414
|
+
underline false # sets whether or not to underline the text.
|
415
|
+
bgcolor 'cccccc' # sets the background color.
|
416
|
+
highlight_color 'yellow' # sets the highlight color. only accepts OOXML enumerations. see http://www.datypic.com/sc/ooxml/t-w_ST_HighlightColor.html.
|
417
|
+
vertical_align 'superscript' # sets the vertical alignment.
|
417
418
|
end
|
418
419
|
```
|
419
420
|
|
@@ -436,23 +437,50 @@ end
|
|
436
437
|
|
437
438
|
Links can be added inside paragraphs using the `link` method. The method accepts several optional parameters for controlling the style and behavior of the rule.
|
438
439
|
|
439
|
-
*At present, all links are assumed to be external.*
|
440
|
-
|
441
440
|
```ruby
|
442
441
|
p do
|
443
442
|
link 'Example Text', 'https://wwww.example.com' do
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
443
|
+
internal false # sets whether or not the link references an external url. defaults to false.
|
444
|
+
font 'Courier New' # sets the font name to use. defaults to nil.
|
445
|
+
color '0000ff' # sets the color of the text. defaults to 1155cc.
|
446
|
+
size 24 # sets the font size. units in half-points. defaults to nil.
|
447
|
+
bold false # sets whether or not the text will be bold. defaults to false.
|
448
|
+
italic false # sets whether or not the text will be italic. defaults to false.
|
449
|
+
underline true # sets whether or not the text will be underlined. defaults to true.
|
450
|
+
bgcolor 'cccccc' # sets the background color.
|
451
|
+
highlight_color 'yellow' # sets the highlight color. only accepts OOXML enumerations. see http://www.datypic.com/sc/ooxml/t-w_ST_HighlightColor.html.
|
451
452
|
end
|
452
453
|
end
|
453
454
|
```
|
454
455
|
|
455
456
|
|
457
|
+
### Bookmarks
|
458
|
+
|
459
|
+
Bookmarks can be added directly to the document or inside paragraph blocks using the `bookmark_start` and `bookmark_end`
|
460
|
+
methods. Bookmarks can be inserted at the document-level to describe section headings, etc. or inside
|
461
|
+
of a paragraph block for fine-grained linking.
|
462
|
+
|
463
|
+
```ruby
|
464
|
+
# document-level bookmark
|
465
|
+
dox.bookmark_start id: 's1', name: 'section1'
|
466
|
+
docx.h2 'Section Heading'
|
467
|
+
docx.bookmark_end id: 's1'
|
468
|
+
docx.p 'Section content.'
|
469
|
+
|
470
|
+
# pargraph-level bookmark
|
471
|
+
docx.h2 'Section Heading'
|
472
|
+
docx.p do
|
473
|
+
text 'Pretend this paragraph has a lot of text and we want to bookmark '
|
474
|
+
bookmark_start id: 'p1', name: 'phrase1'
|
475
|
+
text 'a single phrase'
|
476
|
+
bookmark_end id: 'p1'
|
477
|
+
text ' inside the larger block.'
|
478
|
+
end
|
479
|
+
```
|
480
|
+
|
481
|
+
Bookmarks work in conjunction with internal links. Please see above.
|
482
|
+
|
483
|
+
|
456
484
|
### Headings
|
457
485
|
|
458
486
|
Headings can be added using the `h1`, `h2`, `h3`, `h4`, `h5`, and `h6` methods. Headings are simply paragraph commands with a specific style set, so anything you can do with a paragraph is available to a heading.
|
@@ -643,9 +671,9 @@ It is possible to merge cells vertically and horizontally using the `rowspan` an
|
|
643
671
|
|
644
672
|
```ruby
|
645
673
|
docx.table [['11', '1213', '14'], ['21', '22', '23', '24']] do
|
646
|
-
cell_style rows[0][0], rowspan: 2
|
647
|
-
cell_style rows[0][1], colspan: 2
|
648
|
-
cell_style rows[0][2], rowspan: 2
|
674
|
+
cell_style rows[0][0], rowspan: 2
|
675
|
+
cell_style rows[0][1], colspan: 2
|
676
|
+
cell_style rows[0][2], rowspan: 2
|
649
677
|
end
|
650
678
|
```
|
651
679
|
|
@@ -659,10 +687,10 @@ If your table contains more complex data (multiple paragraphs, images, lists, et
|
|
659
687
|
c1 = Caracal::Core::Models::TableCellModel.new do
|
660
688
|
background 'cccccc' # sets the background color. defaults to 'ffffff'.
|
661
689
|
margins do
|
662
|
-
top # sets the top margin. defaults to
|
663
|
-
bottom # sets the bottom margin. defaults to
|
664
|
-
left # sets the left margin. defaults to
|
665
|
-
right # sets the right margin. defaults to
|
690
|
+
top # sets the top margin. defaults to 100. units in twips.
|
691
|
+
bottom # sets the bottom margin. defaults to 100. units in twips.
|
692
|
+
left # sets the left margin. defaults to 100. units in twips.
|
693
|
+
right # sets the right margin. defaults to 100. units in twips.
|
666
694
|
end
|
667
695
|
|
668
696
|
p 'This is a sentence above an image.'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'caracal/core/models/bookmark_model'
|
2
|
+
require 'caracal/errors'
|
3
|
+
|
4
|
+
|
5
|
+
module Caracal
|
6
|
+
module Core
|
7
|
+
|
8
|
+
# This module encapsulates all the functionality related to adding
|
9
|
+
# bookmarks to the document.
|
10
|
+
#
|
11
|
+
module Bookmarks
|
12
|
+
def self.included(base)
|
13
|
+
base.class_eval do
|
14
|
+
|
15
|
+
#------------------------------------------------
|
16
|
+
# Public Methods
|
17
|
+
#------------------------------------------------
|
18
|
+
|
19
|
+
#========== BOOKMARKS ===========================
|
20
|
+
|
21
|
+
def bookmark_start(*args, &block)
|
22
|
+
options = Caracal::Utilities.extract_options!(args)
|
23
|
+
options.merge!({ start: true})
|
24
|
+
|
25
|
+
model = Caracal::Core::Models::BookmarkModel.new(options, &block)
|
26
|
+
if model.valid?
|
27
|
+
contents << model
|
28
|
+
else
|
29
|
+
raise Caracal::Errors::InvalidModelError, 'Bookmark starting tags require an id and a name.'
|
30
|
+
end
|
31
|
+
model
|
32
|
+
end
|
33
|
+
|
34
|
+
def bookmark_end(*args, &block)
|
35
|
+
options = Caracal::Utilities.extract_options!(args)
|
36
|
+
options.merge!({ start: false})
|
37
|
+
|
38
|
+
model = Caracal::Core::Models::BookmarkModel.new(options, &block)
|
39
|
+
if model.valid?
|
40
|
+
contents << model
|
41
|
+
else
|
42
|
+
raise Caracal::Errors::InvalidModelError, 'Bookmark ending tags require an id.'
|
43
|
+
end
|
44
|
+
model
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'caracal/core/models/base_model'
|
2
|
+
|
3
|
+
|
4
|
+
module Caracal
|
5
|
+
module Core
|
6
|
+
module Models
|
7
|
+
|
8
|
+
# This class encapsulates the logic needed to store and manipulate
|
9
|
+
# bookmarks.
|
10
|
+
#
|
11
|
+
class BookmarkModel < BaseModel
|
12
|
+
|
13
|
+
#--------------------------------------------------
|
14
|
+
# Configuration
|
15
|
+
#--------------------------------------------------
|
16
|
+
|
17
|
+
# accessors
|
18
|
+
attr_reader :bookmark_start
|
19
|
+
attr_reader :bookmark_id
|
20
|
+
attr_reader :bookmark_name
|
21
|
+
|
22
|
+
|
23
|
+
#--------------------------------------------------
|
24
|
+
# Public Methods
|
25
|
+
#--------------------------------------------------
|
26
|
+
|
27
|
+
#========== GETTERS ===============================
|
28
|
+
|
29
|
+
# .run_attributes
|
30
|
+
def run_attributes
|
31
|
+
{
|
32
|
+
start: bookmark_start,
|
33
|
+
id: bookmark_id,
|
34
|
+
name: bookmark_name
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
#========== SETTERS ===============================
|
40
|
+
|
41
|
+
# booleans
|
42
|
+
[:start].each do |m|
|
43
|
+
define_method "#{ m }" do |value|
|
44
|
+
instance_variable_set("@bookmark_#{ m }", !!value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# strings
|
49
|
+
[:id, :name].each do |m|
|
50
|
+
define_method "#{ m }" do |value|
|
51
|
+
instance_variable_set("@bookmark_#{ m }", value.to_s)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
#========== STATE HELPERS =========================
|
57
|
+
|
58
|
+
def start?
|
59
|
+
!!bookmark_start
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
#========== VALIDATION ============================
|
64
|
+
|
65
|
+
def valid?
|
66
|
+
a = [:id]
|
67
|
+
a << :name if start?
|
68
|
+
|
69
|
+
a.map { |m| send("bookmark_#{ m }") }.compact.size == a.size
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
#--------------------------------------------------
|
74
|
+
# Private Methods
|
75
|
+
#--------------------------------------------------
|
76
|
+
private
|
77
|
+
|
78
|
+
def option_keys
|
79
|
+
[:id, :name, :start]
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -10,9 +10,9 @@ module Caracal
|
|
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')
|
@@ -21,14 +21,17 @@ module Caracal
|
|
21
21
|
# readers (create aliases for superclass methods to conform
|
22
22
|
# to expected naming convention.)
|
23
23
|
attr_reader :link_href
|
24
|
-
|
25
|
-
alias_method :
|
26
|
-
alias_method :
|
27
|
-
alias_method :
|
28
|
-
alias_method :
|
29
|
-
alias_method :
|
30
|
-
alias_method :
|
31
|
-
alias_method :
|
24
|
+
attr_reader :link_internal
|
25
|
+
alias_method :link_content, :text_content
|
26
|
+
alias_method :link_font, :text_font
|
27
|
+
alias_method :link_color, :text_color
|
28
|
+
alias_method :link_size, :text_size
|
29
|
+
alias_method :link_bold, :text_bold
|
30
|
+
alias_method :link_italic, :text_italic
|
31
|
+
alias_method :link_underline, :text_underline
|
32
|
+
alias_method :link_bgcolor, :text_bgcolor
|
33
|
+
alias_method :link_highlight_color, :text_highlight_color
|
34
|
+
alias_method :link_vertical_align, :text_vertical_align
|
32
35
|
|
33
36
|
# initialization
|
34
37
|
def initialize(options={}, &block)
|
@@ -39,11 +42,18 @@ module Caracal
|
|
39
42
|
end
|
40
43
|
|
41
44
|
|
42
|
-
|
45
|
+
#--------------------------------------------------
|
43
46
|
# Public Instance Methods
|
44
|
-
|
47
|
+
#--------------------------------------------------
|
45
48
|
|
46
|
-
|
49
|
+
#========== SETTERS ===============================
|
50
|
+
|
51
|
+
# booleans
|
52
|
+
[:internal].each do |m|
|
53
|
+
define_method "#{ m }" do |value|
|
54
|
+
instance_variable_set("@link_#{ m }", !!value)
|
55
|
+
end
|
56
|
+
end
|
47
57
|
|
48
58
|
# strings
|
49
59
|
[:href].each do |m|
|
@@ -53,7 +63,14 @@ module Caracal
|
|
53
63
|
end
|
54
64
|
|
55
65
|
|
56
|
-
|
66
|
+
#========== STATE HELPERS =========================
|
67
|
+
|
68
|
+
def external?
|
69
|
+
!link_internal
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
#========== VALIDATION ============================
|
57
74
|
|
58
75
|
def valid?
|
59
76
|
a = [:content, :href]
|
@@ -61,13 +78,13 @@ module Caracal
|
|
61
78
|
end
|
62
79
|
|
63
80
|
|
64
|
-
|
81
|
+
#--------------------------------------------------
|
65
82
|
# Private Instance Methods
|
66
|
-
|
83
|
+
#--------------------------------------------------
|
67
84
|
private
|
68
85
|
|
69
86
|
def option_keys
|
70
|
-
(super + [:href]).flatten
|
87
|
+
(super + [:internal, :href]).flatten
|
71
88
|
end
|
72
89
|
|
73
90
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'caracal/core/models/base_model'
|
2
|
+
require 'caracal/core/models/bookmark_model'
|
2
3
|
require 'caracal/core/models/link_model'
|
3
4
|
require 'caracal/core/models/text_model'
|
4
5
|
require 'caracal/errors'
|
@@ -13,9 +14,9 @@ module Caracal
|
|
13
14
|
#
|
14
15
|
class ParagraphModel < BaseModel
|
15
16
|
|
16
|
-
|
17
|
+
#--------------------------------------------------
|
17
18
|
# Configuration
|
18
|
-
|
19
|
+
#--------------------------------------------------
|
19
20
|
|
20
21
|
# readers
|
21
22
|
attr_reader :paragraph_style
|
@@ -35,11 +36,11 @@ module Caracal
|
|
35
36
|
end
|
36
37
|
|
37
38
|
|
38
|
-
|
39
|
+
#--------------------------------------------------
|
39
40
|
# Public Instance Methods
|
40
|
-
|
41
|
+
#--------------------------------------------------
|
41
42
|
|
42
|
-
|
43
|
+
#========== GETTERS ===============================
|
43
44
|
|
44
45
|
# .runs
|
45
46
|
def runs
|
@@ -59,7 +60,7 @@ module Caracal
|
|
59
60
|
end
|
60
61
|
|
61
62
|
|
62
|
-
|
63
|
+
#========== SETTERS ===============================
|
63
64
|
|
64
65
|
# booleans
|
65
66
|
[:bold, :italic, :underline].each do |m|
|
@@ -90,7 +91,33 @@ module Caracal
|
|
90
91
|
end
|
91
92
|
|
92
93
|
|
93
|
-
|
94
|
+
#========== SUB-METHODS ===========================
|
95
|
+
|
96
|
+
# .bookmarks
|
97
|
+
def bookmark_start(*args, &block)
|
98
|
+
options = Caracal::Utilities.extract_options!(args)
|
99
|
+
options.merge!({ start: true})
|
100
|
+
|
101
|
+
model = Caracal::Core::Models::BookmarkModel.new(options, &block)
|
102
|
+
if model.valid?
|
103
|
+
runs << model
|
104
|
+
else
|
105
|
+
raise Caracal::Errors::InvalidModelError, 'Bookmark starting tags require an id and a name.'
|
106
|
+
end
|
107
|
+
model
|
108
|
+
end
|
109
|
+
def bookmark_end(*args, &block)
|
110
|
+
options = Caracal::Utilities.extract_options!(args)
|
111
|
+
options.merge!({ start: false})
|
112
|
+
|
113
|
+
model = Caracal::Core::Models::BookmarkModel.new(options, &block)
|
114
|
+
if model.valid?
|
115
|
+
runs << model
|
116
|
+
else
|
117
|
+
raise Caracal::Errors::InvalidModelError, 'Bookmark ending tags require an id.'
|
118
|
+
end
|
119
|
+
model
|
120
|
+
end
|
94
121
|
|
95
122
|
# .br
|
96
123
|
def br
|
@@ -136,16 +163,16 @@ module Caracal
|
|
136
163
|
end
|
137
164
|
|
138
165
|
|
139
|
-
|
166
|
+
#========== VALIDATION ============================
|
140
167
|
|
141
168
|
def valid?
|
142
169
|
runs.size > 0
|
143
170
|
end
|
144
171
|
|
145
172
|
|
146
|
-
|
173
|
+
#--------------------------------------------------
|
147
174
|
# Private Instance Methods
|
148
|
-
|
175
|
+
#--------------------------------------------------
|
149
176
|
private
|
150
177
|
|
151
178
|
def option_keys
|
@@ -24,6 +24,7 @@ module Caracal
|
|
24
24
|
attr_reader :text_italic
|
25
25
|
attr_reader :text_underline
|
26
26
|
attr_reader :text_bgcolor
|
27
|
+
attr_reader :text_highlight_color
|
27
28
|
attr_reader :text_vertical_align
|
28
29
|
|
29
30
|
|
@@ -37,15 +38,16 @@ module Caracal
|
|
37
38
|
# .run_attributes
|
38
39
|
def run_attributes
|
39
40
|
{
|
40
|
-
style:
|
41
|
-
font:
|
42
|
-
color:
|
43
|
-
size:
|
44
|
-
bold:
|
45
|
-
italic:
|
46
|
-
underline:
|
47
|
-
bgcolor:
|
48
|
-
|
41
|
+
style: text_style,
|
42
|
+
font: text_font,
|
43
|
+
color: text_color,
|
44
|
+
size: text_size,
|
45
|
+
bold: text_bold,
|
46
|
+
italic: text_italic,
|
47
|
+
underline: text_underline,
|
48
|
+
bgcolor: text_bgcolor,
|
49
|
+
highlight_color: text_highlight_color,
|
50
|
+
vertical_align: text_vertical_align
|
49
51
|
}
|
50
52
|
end
|
51
53
|
|
@@ -67,7 +69,7 @@ module Caracal
|
|
67
69
|
end
|
68
70
|
|
69
71
|
# strings
|
70
|
-
[:bgcolor, :color, :content, :font, :style].each do |m|
|
72
|
+
[:bgcolor, :color, :content, :font, :highlight_color, :style].each do |m|
|
71
73
|
define_method "#{ m }" do |value|
|
72
74
|
instance_variable_set("@text_#{ m }", value.to_s)
|
73
75
|
end
|
@@ -95,7 +97,7 @@ module Caracal
|
|
95
97
|
private
|
96
98
|
|
97
99
|
def option_keys
|
98
|
-
[:content, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align]
|
100
|
+
[:content, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :highlight_color, :vertical_align]
|
99
101
|
end
|
100
102
|
|
101
103
|
def method_missing(method, *args, &block)
|
data/lib/caracal/document.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'zip'
|
3
3
|
|
4
|
+
require 'caracal/core/bookmarks'
|
4
5
|
require 'caracal/core/custom_properties'
|
5
6
|
require 'caracal/core/file_name'
|
6
7
|
require 'caracal/core/fonts'
|
@@ -53,6 +54,7 @@ module Caracal
|
|
53
54
|
include Caracal::Core::Styles
|
54
55
|
include Caracal::Core::ListStyles
|
55
56
|
|
57
|
+
include Caracal::Core::Bookmarks
|
56
58
|
include Caracal::Core::IFrames
|
57
59
|
include Caracal::Core::Images
|
58
60
|
include Caracal::Core::Lists
|
@@ -82,6 +82,7 @@ module Caracal
|
|
82
82
|
xml['w'].i( { 'w:val' => (attrs[:italic] ? '1' : '0') }) unless attrs[:italic].nil?
|
83
83
|
xml['w'].u( { 'w:val' => (attrs[:underline] ? 'single' : 'none') }) unless attrs[:underline].nil?
|
84
84
|
xml['w'].shd( { 'w:fill' => attrs[:bgcolor], 'w:val' => 'clear' }) unless attrs[:bgcolor].nil?
|
85
|
+
xml['w'].highlight( { 'w:val' => attrs[:highlight_color] }) unless attrs[:highlight_color].nil?
|
85
86
|
xml['w'].vertAlign( { 'w:val' => attrs[:vertical_align] }) unless attrs[:vertical_align].nil?
|
86
87
|
unless attrs[:font].nil?
|
87
88
|
f = attrs[:font]
|
@@ -97,6 +98,14 @@ module Caracal
|
|
97
98
|
|
98
99
|
#============= MODEL RENDERERS ===========================
|
99
100
|
|
101
|
+
def render_bookmark(xml, model)
|
102
|
+
if model.start?
|
103
|
+
xml['w'].bookmarkStart({ 'w:id' => model.bookmark_id, 'w:name' => model.bookmark_name })
|
104
|
+
else
|
105
|
+
xml['w'].bookmarkEnd({ 'w:id' => model.bookmark_id })
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
100
109
|
def render_iframe(xml, model)
|
101
110
|
::Zip::File.open(model.file) do |zip|
|
102
111
|
a_href = 'http://schemas.openxmlformats.org/drawingml/2006/main'
|
@@ -195,9 +204,14 @@ module Caracal
|
|
195
204
|
end
|
196
205
|
|
197
206
|
def render_link(xml, model)
|
198
|
-
|
207
|
+
if model.external?
|
208
|
+
rel = document.relationship({ target: model.link_href, type: :link })
|
209
|
+
hyperlink_options = { 'r:id' => rel.formatted_id }
|
210
|
+
else
|
211
|
+
hyperlink_options = { 'w:anchor' => model.link_href }
|
212
|
+
end
|
199
213
|
|
200
|
-
xml['w'].hyperlink(
|
214
|
+
xml['w'].hyperlink(hyperlink_options) do
|
201
215
|
xml['w'].r run_options do
|
202
216
|
render_run_attributes(xml, model, false)
|
203
217
|
xml['w'].t({ 'xml:space' => 'preserve' }, model.link_content)
|
data/lib/caracal/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Bookmarks do
|
4
|
+
subject { Caracal::Document.new }
|
5
|
+
|
6
|
+
|
7
|
+
#-------------------------------------------------------------
|
8
|
+
# Public Methods
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
|
11
|
+
describe 'public method tests' do
|
12
|
+
|
13
|
+
# .bookmark_start
|
14
|
+
describe '.bookmark_start' do
|
15
|
+
let!(:size) { subject.contents.size }
|
16
|
+
|
17
|
+
before { subject.send('bookmark_start', id: '123', name: 'abc') }
|
18
|
+
|
19
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
20
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::BookmarkModel) }
|
21
|
+
end
|
22
|
+
|
23
|
+
# .bookmark_end
|
24
|
+
describe '.bookmark_end' do
|
25
|
+
let!(:size) { subject.contents.size }
|
26
|
+
|
27
|
+
before { subject.send('bookmark_end', id: '123') }
|
28
|
+
|
29
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
30
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::BookmarkModel) }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::BookmarkModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
id '0'
|
7
|
+
name 'myAnchor'
|
8
|
+
start false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
# Configuration
|
14
|
+
#-------------------------------------------------------------
|
15
|
+
|
16
|
+
describe 'configuration tests' do
|
17
|
+
|
18
|
+
# accessors
|
19
|
+
describe 'accessors' do
|
20
|
+
it { expect(subject.bookmark_id).to eq '0' }
|
21
|
+
it { expect(subject.bookmark_name).to eq 'myAnchor' }
|
22
|
+
it { expect(subject.bookmark_start).to eq false }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
#-------------------------------------------------------------
|
29
|
+
# Public Methods
|
30
|
+
#-------------------------------------------------------------
|
31
|
+
|
32
|
+
describe 'public method tests' do
|
33
|
+
|
34
|
+
#=============== GETTERS ==========================
|
35
|
+
|
36
|
+
# .run_attributes
|
37
|
+
describe '.run_attributes' do
|
38
|
+
let(:expected) { { id: '0', name: 'myAnchor', start: false} }
|
39
|
+
|
40
|
+
it { expect(subject.run_attributes).to eq expected }
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#=============== SETTERS ==========================
|
45
|
+
|
46
|
+
# booleans
|
47
|
+
describe '.start' do
|
48
|
+
before { subject.start(true) }
|
49
|
+
|
50
|
+
it { expect(subject.bookmark_start).to eq true }
|
51
|
+
end
|
52
|
+
|
53
|
+
# strings
|
54
|
+
describe '.id' do
|
55
|
+
before { subject.id('dddddd') }
|
56
|
+
|
57
|
+
it { expect(subject.bookmark_id).to eq 'dddddd' }
|
58
|
+
end
|
59
|
+
describe '.name' do
|
60
|
+
before { subject.name('999999') }
|
61
|
+
|
62
|
+
it { expect(subject.bookmark_name).to eq '999999' }
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
#=============== STATE HELPERS ========================
|
67
|
+
|
68
|
+
describe '.start?' do
|
69
|
+
describe 'when start is true' do
|
70
|
+
before { subject.start(true) }
|
71
|
+
|
72
|
+
it { expect(subject.start?).to eq true }
|
73
|
+
end
|
74
|
+
describe 'when start is false' do
|
75
|
+
before { subject.start(false) }
|
76
|
+
|
77
|
+
it { expect(subject.start?).to eq false }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#=============== VALIDATION ===========================
|
83
|
+
|
84
|
+
describe '.valid?' do
|
85
|
+
describe 'when required attributes provided' do
|
86
|
+
it { expect(subject.valid?).to eq true }
|
87
|
+
end
|
88
|
+
describe 'when start is true' do
|
89
|
+
before { subject.start(true) }
|
90
|
+
|
91
|
+
[:id, :name].each do |prop|
|
92
|
+
describe "when #{ prop } is empty" do
|
93
|
+
before do
|
94
|
+
allow(subject).to receive("bookmark_#{ prop }").and_return(nil)
|
95
|
+
end
|
96
|
+
|
97
|
+
it { expect(subject.valid?).to eq false }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
describe 'when start is false' do
|
102
|
+
before { subject.start(false) }
|
103
|
+
|
104
|
+
[:id].each do |prop|
|
105
|
+
describe "when #{ prop } is empty" do
|
106
|
+
before do
|
107
|
+
allow(subject).to receive("bookmark_#{ prop }").and_return(nil)
|
108
|
+
end
|
109
|
+
|
110
|
+
it { expect(subject.valid?).to eq false }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
#-------------------------------------------------------------
|
120
|
+
# Private Methods
|
121
|
+
#-------------------------------------------------------------
|
122
|
+
|
123
|
+
describe 'private method tests' do
|
124
|
+
|
125
|
+
# .option_keys
|
126
|
+
describe '.option_keys' do
|
127
|
+
let(:actual) { subject.send(:option_keys).sort }
|
128
|
+
let(:expected) { [:id, :name, :start].sort }
|
129
|
+
|
130
|
+
it { expect(actual).to eq expected }
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -3,16 +3,18 @@ require 'spec_helper'
|
|
3
3
|
describe Caracal::Core::Models::LinkModel do
|
4
4
|
subject do
|
5
5
|
described_class.new do
|
6
|
-
content
|
7
|
-
href
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
content 'Link Text'
|
7
|
+
href 'http://www.google.com'
|
8
|
+
internal false
|
9
|
+
font 'Courier New'
|
10
|
+
color '666666'
|
11
|
+
size 20
|
12
|
+
bold false
|
13
|
+
italic false
|
14
|
+
underline true
|
15
|
+
bgcolor 'cccccc'
|
16
|
+
highlight_color 'yellow'
|
17
|
+
vertical_align :top
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -32,6 +34,7 @@ describe Caracal::Core::Models::LinkModel do
|
|
32
34
|
describe 'accessors' do
|
33
35
|
it { expect(subject.link_content).to eq 'Link Text' }
|
34
36
|
it { expect(subject.link_href).to eq 'http://www.google.com' }
|
37
|
+
it { expect(subject.link_internal).to eq false }
|
35
38
|
it { expect(subject.link_font).to eq 'Courier New' }
|
36
39
|
it { expect(subject.link_color).to eq '666666' }
|
37
40
|
it { expect(subject.link_size).to eq 20 }
|
@@ -39,6 +42,8 @@ describe Caracal::Core::Models::LinkModel do
|
|
39
42
|
it { expect(subject.link_italic).to eq false }
|
40
43
|
it { expect(subject.link_underline).to eq true }
|
41
44
|
it { expect(subject.link_bgcolor).to eq 'cccccc' }
|
45
|
+
it { expect(subject.link_highlight_color).to eq 'yellow' }
|
46
|
+
it { expect(subject.link_vertical_align).to eq :top }
|
42
47
|
end
|
43
48
|
|
44
49
|
end
|
@@ -54,7 +59,7 @@ describe Caracal::Core::Models::LinkModel do
|
|
54
59
|
|
55
60
|
# .run_attributes
|
56
61
|
describe '.run_attributes' do
|
57
|
-
let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :top } }
|
62
|
+
let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', highlight_color: 'yellow', vertical_align: :top } }
|
58
63
|
|
59
64
|
it { expect(subject.run_attributes).to eq expected }
|
60
65
|
end
|
@@ -68,6 +73,11 @@ describe Caracal::Core::Models::LinkModel do
|
|
68
73
|
|
69
74
|
it { expect(subject.link_bold).to eq true }
|
70
75
|
end
|
76
|
+
describe '.internal' do
|
77
|
+
before { subject.internal(true) }
|
78
|
+
|
79
|
+
it { expect(subject.link_internal).to eq true }
|
80
|
+
end
|
71
81
|
describe '.italic' do
|
72
82
|
before { subject.italic(true) }
|
73
83
|
|
@@ -102,15 +112,31 @@ describe Caracal::Core::Models::LinkModel do
|
|
102
112
|
|
103
113
|
it { expect(subject.link_content).to eq 'Something Else' }
|
104
114
|
end
|
115
|
+
describe '.font' do
|
116
|
+
before { subject.font('Palantino') }
|
117
|
+
|
118
|
+
it { expect(subject.link_font).to eq 'Palantino' }
|
119
|
+
end
|
105
120
|
describe '.href' do
|
106
121
|
before { subject.href('http://www.google.com') }
|
107
122
|
|
108
123
|
it { expect(subject.link_href).to eq 'http://www.google.com' }
|
109
124
|
end
|
110
|
-
describe '.font' do
|
111
|
-
before { subject.font('Palantino') }
|
112
125
|
|
113
|
-
|
126
|
+
|
127
|
+
#=============== STATE HELPERS ========================
|
128
|
+
|
129
|
+
describe '.external?' do
|
130
|
+
describe 'when internal is true' do
|
131
|
+
before { subject.internal(true) }
|
132
|
+
|
133
|
+
it { expect(subject.external?).to eq false }
|
134
|
+
end
|
135
|
+
describe 'when internal is false' do
|
136
|
+
before { subject.internal(false) }
|
137
|
+
|
138
|
+
it { expect(subject.external?).to eq true }
|
139
|
+
end
|
114
140
|
end
|
115
141
|
|
116
142
|
|
@@ -143,7 +169,7 @@ describe Caracal::Core::Models::LinkModel do
|
|
143
169
|
# .option_keys
|
144
170
|
describe '.option_keys' do
|
145
171
|
let(:actual) { subject.send(:option_keys).sort }
|
146
|
-
let(:expected) { [:content, :href, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align].sort }
|
172
|
+
let(:expected) { [:content, :href, :internal, :style, :font, :color, :size, :bold, :highlight_color, :italic, :underline, :bgcolor, :vertical_align].sort }
|
147
173
|
|
148
174
|
it { expect(actual).to eq expected }
|
149
175
|
end
|
@@ -137,6 +137,23 @@ describe Caracal::Core::Models::ParagraphModel do
|
|
137
137
|
it { expect(subject.runs.size).to eq length + 1 }
|
138
138
|
end
|
139
139
|
|
140
|
+
# .bookmark
|
141
|
+
describe '.bookmark_start' do
|
142
|
+
let!(:length) { subject.runs.length }
|
143
|
+
|
144
|
+
before { subject.bookmark_start(id:'1', name:'abc')}
|
145
|
+
|
146
|
+
it { expect(subject.runs.size).to eq length + 1 }
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '.bookmark_end' do
|
150
|
+
let!(:length) { subject.runs.length }
|
151
|
+
|
152
|
+
before { subject.bookmark_end {id:'1'}}
|
153
|
+
|
154
|
+
it { expect(subject.runs.size).to eq length + 1 }
|
155
|
+
end
|
156
|
+
|
140
157
|
|
141
158
|
#=============== VALIDATION ===========================
|
142
159
|
|
@@ -220,7 +220,7 @@ describe Caracal::Core::Models::TableCellModel do
|
|
220
220
|
# .option_keys
|
221
221
|
describe '.option_keys' do
|
222
222
|
let(:actual) { subject.send(:option_keys).sort }
|
223
|
-
let(:expected) { [:background, :width, :vertical_align, :margins].sort }
|
223
|
+
let(:expected) { [:background, :colspan, :rowspan, :width, :vertical_align, :margins].sort }
|
224
224
|
|
225
225
|
it { expect(actual).to eq expected }
|
226
226
|
end
|
@@ -12,6 +12,7 @@ describe Caracal::Core::Models::TextModel do
|
|
12
12
|
underline true
|
13
13
|
bgcolor 'cccccc'
|
14
14
|
vertical_align :subscript
|
15
|
+
highlight_color 'yellow'
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -31,6 +32,7 @@ describe Caracal::Core::Models::TextModel do
|
|
31
32
|
it { expect(subject.text_italic).to eq false }
|
32
33
|
it { expect(subject.text_underline).to eq true }
|
33
34
|
it { expect(subject.text_bgcolor).to eq 'cccccc' }
|
35
|
+
it { expect(subject.text_highlight_color).to eq 'yellow' }
|
34
36
|
it { expect(subject.text_vertical_align).to eq :subscript }
|
35
37
|
end
|
36
38
|
|
@@ -47,7 +49,7 @@ describe Caracal::Core::Models::TextModel do
|
|
47
49
|
|
48
50
|
# .run_attributes
|
49
51
|
describe '.run_attributes' do
|
50
|
-
let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :subscript } }
|
52
|
+
let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', highlight_color: 'yellow', vertical_align: :subscript } }
|
51
53
|
|
52
54
|
it { expect(subject.run_attributes).to eq expected }
|
53
55
|
end
|
@@ -81,9 +83,9 @@ describe Caracal::Core::Models::TextModel do
|
|
81
83
|
|
82
84
|
# strings
|
83
85
|
describe '.bgcolor' do
|
84
|
-
before { subject.
|
86
|
+
before { subject.bgcolor('dddddd') }
|
85
87
|
|
86
|
-
it { expect(subject.
|
88
|
+
it { expect(subject.text_bgcolor).to eq 'dddddd' }
|
87
89
|
end
|
88
90
|
describe '.color' do
|
89
91
|
before { subject.color('999999') }
|
@@ -100,6 +102,11 @@ describe Caracal::Core::Models::TextModel do
|
|
100
102
|
|
101
103
|
it { expect(subject.text_font).to eq 'Palantino' }
|
102
104
|
end
|
105
|
+
describe '.hightlight_color' do
|
106
|
+
before { subject.highlight_color('green') }
|
107
|
+
|
108
|
+
it { expect(subject.text_highlight_color).to eq 'green' }
|
109
|
+
end
|
103
110
|
|
104
111
|
#symbols
|
105
112
|
describe '.vertical_align' do
|
@@ -137,7 +144,7 @@ describe Caracal::Core::Models::TextModel do
|
|
137
144
|
# .option_keys
|
138
145
|
describe '.option_keys' do
|
139
146
|
let(:actual) { subject.send(:option_keys).sort }
|
140
|
-
let(:expected) { [:bgcolor, :bold, :color, :content, :font, :italic, :size, :style, :underline, :vertical_align].sort }
|
147
|
+
let(:expected) { [:bgcolor, :bold, :color, :content, :font, :highlight_color, :italic, :size, :style, :underline, :vertical_align].sort }
|
141
148
|
|
142
149
|
it { expect(actual).to eq expected }
|
143
150
|
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: 1.
|
4
|
+
version: 1.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: 2018-
|
12
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- Rakefile
|
113
113
|
- caracal.gemspec
|
114
114
|
- lib/caracal.rb
|
115
|
+
- lib/caracal/core/bookmarks.rb
|
115
116
|
- lib/caracal/core/custom_properties.rb
|
116
117
|
- lib/caracal/core/file_name.rb
|
117
118
|
- lib/caracal/core/fonts.rb
|
@@ -121,6 +122,7 @@ files:
|
|
121
122
|
- lib/caracal/core/list_styles.rb
|
122
123
|
- lib/caracal/core/lists.rb
|
123
124
|
- lib/caracal/core/models/base_model.rb
|
125
|
+
- lib/caracal/core/models/bookmark_model.rb
|
124
126
|
- lib/caracal/core/models/border_model.rb
|
125
127
|
- lib/caracal/core/models/custom_property_model.rb
|
126
128
|
- lib/caracal/core/models/font_model.rb
|
@@ -170,6 +172,7 @@ files:
|
|
170
172
|
- lib/caracal/utilities.rb
|
171
173
|
- lib/caracal/version.rb
|
172
174
|
- lib/tilt/caracal.rb
|
175
|
+
- spec/lib/caracal/core/bookmarks_spec.rb
|
173
176
|
- spec/lib/caracal/core/file_name_spec.rb
|
174
177
|
- spec/lib/caracal/core/fonts_spec.rb
|
175
178
|
- spec/lib/caracal/core/iframes_spec.rb
|
@@ -178,6 +181,7 @@ files:
|
|
178
181
|
- spec/lib/caracal/core/list_styles_spec.rb
|
179
182
|
- spec/lib/caracal/core/lists_spec.rb
|
180
183
|
- spec/lib/caracal/core/models/base_model_spec.rb
|
184
|
+
- spec/lib/caracal/core/models/bookmark_model_spec.rb
|
181
185
|
- spec/lib/caracal/core/models/border_model_spec.rb
|
182
186
|
- spec/lib/caracal/core/models/font_model_spec.rb
|
183
187
|
- spec/lib/caracal/core/models/iframe_model_spec.rb
|
@@ -236,6 +240,7 @@ signing_key:
|
|
236
240
|
specification_version: 4
|
237
241
|
summary: Fast, professional Microsoft Word (docx) writer for Ruby.
|
238
242
|
test_files:
|
243
|
+
- spec/lib/caracal/core/bookmarks_spec.rb
|
239
244
|
- spec/lib/caracal/core/file_name_spec.rb
|
240
245
|
- spec/lib/caracal/core/fonts_spec.rb
|
241
246
|
- spec/lib/caracal/core/iframes_spec.rb
|
@@ -244,6 +249,7 @@ test_files:
|
|
244
249
|
- spec/lib/caracal/core/list_styles_spec.rb
|
245
250
|
- spec/lib/caracal/core/lists_spec.rb
|
246
251
|
- spec/lib/caracal/core/models/base_model_spec.rb
|
252
|
+
- spec/lib/caracal/core/models/bookmark_model_spec.rb
|
247
253
|
- spec/lib/caracal/core/models/border_model_spec.rb
|
248
254
|
- spec/lib/caracal/core/models/font_model_spec.rb
|
249
255
|
- spec/lib/caracal/core/models/iframe_model_spec.rb
|