caracal 1.0.1 → 1.2.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 +5 -5
- data/.gitignore +1 -0
- data/CHANGELOG.md +95 -5
- data/README.md +171 -35
- data/caracal.gemspec +4 -4
- data/lib/caracal/core/custom_properties.rb +49 -0
- data/lib/caracal/core/iframes.rb +42 -0
- data/lib/caracal/core/ignorables.rb +47 -0
- data/lib/caracal/core/models/custom_property_model.rb +60 -0
- data/lib/caracal/core/models/iframe_model.rb +148 -0
- data/lib/caracal/core/models/namespace_model.rb +65 -0
- data/lib/caracal/core/models/page_break_model.rb +50 -4
- data/lib/caracal/core/models/page_number_model.rb +50 -24
- data/lib/caracal/core/models/page_size_model.rb +34 -25
- data/lib/caracal/core/models/paragraph_model.rb +11 -4
- data/lib/caracal/core/models/style_model.rb +44 -15
- data/lib/caracal/core/models/table_cell_model.rb +61 -50
- data/lib/caracal/core/models/table_model.rb +1 -1
- data/lib/caracal/core/models/text_model.rb +42 -20
- data/lib/caracal/core/namespaces.rb +89 -0
- data/lib/caracal/core/page_numbers.rb +22 -16
- data/lib/caracal/core/page_settings.rb +18 -16
- data/lib/caracal/document.rb +75 -58
- data/lib/caracal/renderers/content_types_renderer.rb +18 -17
- data/lib/caracal/renderers/core_renderer.rb +1 -1
- data/lib/caracal/renderers/custom_renderer.rb +64 -0
- data/lib/caracal/renderers/document_renderer.rb +205 -118
- data/lib/caracal/renderers/fonts_renderer.rb +2 -2
- data/lib/caracal/renderers/footer_renderer.rb +41 -20
- data/lib/caracal/renderers/numbering_renderer.rb +27 -26
- data/lib/caracal/renderers/package_relationships_renderer.rb +14 -13
- data/lib/caracal/renderers/settings_renderer.rb +5 -5
- data/lib/caracal/renderers/styles_renderer.rb +88 -73
- data/lib/caracal/renderers/xml_renderer.rb +20 -20
- data/lib/caracal/version.rb +1 -1
- data/lib/caracal.rb +11 -2
- data/spec/lib/caracal/core/iframes_spec.rb +29 -0
- data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
- data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +60 -62
- data/spec/lib/caracal/core/models/link_model_spec.rb +12 -11
- data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +66 -31
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +42 -32
- data/spec/lib/caracal/core/models/style_model_spec.rb +32 -1
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +10 -1
- data/spec/lib/caracal/core/models/text_model_spec.rb +18 -10
- data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +32 -23
- data/spec/lib/caracal/core/page_settings_spec.rb +33 -25
- data/spec/lib/caracal/core/relationships_spec.rb +47 -47
- data/spec/support/_fixtures/snippet.docx +0 -0
- metadata +28 -8
|
@@ -10,11 +10,12 @@ module Caracal
|
|
|
10
10
|
#
|
|
11
11
|
class StyleModel < BaseModel
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
#--------------------------------------------------
|
|
14
14
|
# Configuration
|
|
15
|
-
|
|
15
|
+
#--------------------------------------------------
|
|
16
16
|
|
|
17
17
|
# constants
|
|
18
|
+
const_set(:DEFAULT_STYLE_TYPE, 'paragraph')
|
|
18
19
|
const_set(:DEFAULT_STYLE_COLOR, '333333')
|
|
19
20
|
const_set(:DEFAULT_STYLE_SIZE, 20)
|
|
20
21
|
const_set(:DEFAULT_STYLE_BOLD, false)
|
|
@@ -31,6 +32,7 @@ module Caracal
|
|
|
31
32
|
# accessors
|
|
32
33
|
attr_reader :style_default
|
|
33
34
|
attr_reader :style_id
|
|
35
|
+
attr_reader :style_type
|
|
34
36
|
attr_reader :style_name
|
|
35
37
|
attr_reader :style_color
|
|
36
38
|
attr_reader :style_font
|
|
@@ -45,10 +47,14 @@ module Caracal
|
|
|
45
47
|
attr_reader :style_line
|
|
46
48
|
attr_reader :style_base
|
|
47
49
|
attr_reader :style_next
|
|
50
|
+
attr_reader :style_indent_left
|
|
51
|
+
attr_reader :style_indent_right
|
|
52
|
+
attr_reader :style_indent_first
|
|
48
53
|
|
|
49
54
|
# initialization
|
|
50
55
|
def initialize(options={}, &block)
|
|
51
56
|
@style_default = false
|
|
57
|
+
@style_type = DEFAULT_STYLE_TYPE
|
|
52
58
|
@style_base = DEFAULT_STYLE_BASE
|
|
53
59
|
@style_next = DEFAULT_STYLE_NEXT
|
|
54
60
|
|
|
@@ -70,11 +76,11 @@ module Caracal
|
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
|
|
73
|
-
|
|
74
|
-
# Public
|
|
75
|
-
|
|
79
|
+
#--------------------------------------------------
|
|
80
|
+
# Public Methods
|
|
81
|
+
#--------------------------------------------------
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
#========== SETTERS ===============================
|
|
78
84
|
|
|
79
85
|
# booleans
|
|
80
86
|
[:bold, :italic, :underline, :caps].each do |m|
|
|
@@ -84,14 +90,14 @@ module Caracal
|
|
|
84
90
|
end
|
|
85
91
|
|
|
86
92
|
# integers
|
|
87
|
-
[:bottom, :size, :line, :top].each do |m|
|
|
93
|
+
[:bottom, :size, :line, :top, :indent_left, :indent_right, :indent_first].each do |m|
|
|
88
94
|
define_method "#{ m }" do |value|
|
|
89
95
|
instance_variable_set("@style_#{ m }", value.to_i)
|
|
90
96
|
end
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
# strings
|
|
94
|
-
[:id, :name, :color, :font].each do |m|
|
|
100
|
+
[:id, :type, :name, :color, :font].each do |m|
|
|
95
101
|
define_method "#{ m }" do |value|
|
|
96
102
|
instance_variable_set("@style_#{ m }", value.to_s)
|
|
97
103
|
end
|
|
@@ -104,29 +110,52 @@ module Caracal
|
|
|
104
110
|
end
|
|
105
111
|
end
|
|
106
112
|
|
|
113
|
+
# custom
|
|
114
|
+
def type(value)
|
|
115
|
+
allowed = ['character', 'paragraph']
|
|
116
|
+
given = value.to_s.downcase.strip
|
|
117
|
+
@style_type = allowed.include?(given) ? given : DEFAULT_STYLE_TYPE
|
|
118
|
+
end
|
|
119
|
+
|
|
107
120
|
|
|
108
|
-
|
|
121
|
+
#========== STATE =================================
|
|
109
122
|
|
|
110
123
|
def matches?(str)
|
|
111
124
|
style_id.downcase == str.to_s.downcase
|
|
112
125
|
end
|
|
113
126
|
|
|
114
127
|
|
|
115
|
-
|
|
128
|
+
#========== VALIDATION ============================
|
|
116
129
|
|
|
117
130
|
def valid?
|
|
118
|
-
a = [:id, :name]
|
|
131
|
+
a = [:id, :name, :type]
|
|
119
132
|
a.map { |m| send("style_#{ m }") }.compact.size == a.size
|
|
120
133
|
end
|
|
121
134
|
|
|
122
135
|
|
|
123
|
-
|
|
124
|
-
# Private
|
|
125
|
-
|
|
136
|
+
#--------------------------------------------------
|
|
137
|
+
# Private Methods
|
|
138
|
+
#--------------------------------------------------
|
|
126
139
|
private
|
|
127
140
|
|
|
128
141
|
def option_keys
|
|
129
|
-
[
|
|
142
|
+
[ :type,
|
|
143
|
+
:bold,
|
|
144
|
+
:italic,
|
|
145
|
+
:underline,
|
|
146
|
+
:caps,
|
|
147
|
+
:top,
|
|
148
|
+
:bottom,
|
|
149
|
+
:size,
|
|
150
|
+
:line,
|
|
151
|
+
:id,
|
|
152
|
+
:name,
|
|
153
|
+
:color,
|
|
154
|
+
:font,
|
|
155
|
+
:align,
|
|
156
|
+
:indent_left,
|
|
157
|
+
:indent_right,
|
|
158
|
+
:indent_first ]
|
|
130
159
|
end
|
|
131
160
|
|
|
132
161
|
end
|
|
@@ -5,54 +5,59 @@ require 'caracal/core/models/margin_model'
|
|
|
5
5
|
module Caracal
|
|
6
6
|
module Core
|
|
7
7
|
module Models
|
|
8
|
-
|
|
9
|
-
# This class handles block options passed to tables via their data
|
|
8
|
+
|
|
9
|
+
# This class handles block options passed to tables via their data
|
|
10
10
|
# collections.
|
|
11
11
|
#
|
|
12
12
|
class TableCellModel < BaseModel
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
#-------------------------------------------------------------
|
|
15
15
|
# Configuration
|
|
16
16
|
#-------------------------------------------------------------
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
# constants
|
|
19
|
-
const_set(:DEFAULT_CELL_BACKGROUND,
|
|
20
|
-
const_set(:DEFAULT_CELL_MARGINS,
|
|
21
|
-
|
|
19
|
+
const_set(:DEFAULT_CELL_BACKGROUND, 'ffffff')
|
|
20
|
+
const_set(:DEFAULT_CELL_MARGINS, Caracal::Core::Models::MarginModel.new({ top: 100, bottom: 100, left: 100, right: 100 }))
|
|
21
|
+
const_set(:DEFAULT_CELL_VERTICAL_ALIGN, :top)
|
|
22
|
+
|
|
22
23
|
# accessors
|
|
23
|
-
attr_reader :cell_background
|
|
24
|
+
attr_reader :cell_background
|
|
24
25
|
attr_reader :cell_width
|
|
25
26
|
attr_reader :cell_margins
|
|
26
|
-
|
|
27
|
+
attr_reader :cell_vertical_align
|
|
28
|
+
attr_reader :cell_rowspan
|
|
29
|
+
attr_reader :cell_colspan
|
|
30
|
+
|
|
27
31
|
# initialization
|
|
28
32
|
def initialize(options={}, &block)
|
|
29
|
-
@cell_background
|
|
30
|
-
@cell_margins
|
|
31
|
-
|
|
33
|
+
@cell_background = DEFAULT_CELL_BACKGROUND
|
|
34
|
+
@cell_margins = DEFAULT_CELL_MARGINS
|
|
35
|
+
@cell_vertical_align = DEFAULT_CELL_VERTICAL_ALIGN
|
|
36
|
+
|
|
32
37
|
if content = options.delete(:content)
|
|
33
|
-
p content, options.dup
|
|
38
|
+
p content, options.dup, &block
|
|
34
39
|
end
|
|
35
|
-
|
|
40
|
+
|
|
36
41
|
super options, &block
|
|
37
42
|
end
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
|
|
44
|
+
|
|
40
45
|
#-------------------------------------------------------------
|
|
41
46
|
# Public Methods
|
|
42
47
|
#-------------------------------------------------------------
|
|
43
|
-
|
|
48
|
+
|
|
44
49
|
#=============== DATA ACCESSORS =======================
|
|
45
|
-
|
|
50
|
+
|
|
46
51
|
def contents
|
|
47
52
|
@contents ||= []
|
|
48
53
|
end
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
|
|
55
|
+
|
|
51
56
|
#=============== STYLES ===============================
|
|
52
|
-
|
|
53
|
-
# This method allows styles to be applied to this cell
|
|
57
|
+
|
|
58
|
+
# This method allows styles to be applied to this cell
|
|
54
59
|
# from the table level. It attempts to add the style
|
|
55
|
-
# first to the instance, and then to any sub-models that
|
|
60
|
+
# first to the instance, and then to any sub-models that
|
|
56
61
|
# respond to the method.
|
|
57
62
|
#
|
|
58
63
|
# In all cases, invalid options will simply be ignored.
|
|
@@ -61,21 +66,21 @@ module Caracal
|
|
|
61
66
|
# make dup of options so we don't
|
|
62
67
|
# harm args sent to sibling cells
|
|
63
68
|
options = opts.dup
|
|
64
|
-
|
|
69
|
+
|
|
65
70
|
# first, try apply to self
|
|
66
71
|
options.each do |(k,v)|
|
|
67
72
|
send(k, v) if respond_to?(k)
|
|
68
73
|
end
|
|
69
|
-
|
|
74
|
+
|
|
70
75
|
# prevent top-level attrs from trickling down
|
|
71
|
-
options.delete_if { |(k,v)| option_keys.include?(k) }
|
|
72
|
-
|
|
76
|
+
options.delete_if { |(k,v)| option_keys.include?(k) }
|
|
77
|
+
|
|
73
78
|
# then, try apply to contents
|
|
74
79
|
contents.each do |model|
|
|
75
80
|
options.each do |k,v|
|
|
76
81
|
model.send(k, v) if model.respond_to?(k)
|
|
77
82
|
end
|
|
78
|
-
|
|
83
|
+
|
|
79
84
|
# finally, apply to runs. options do trickle down
|
|
80
85
|
# because paragraph-level styles don't seem to
|
|
81
86
|
# affect runs within tables. weirdsies.
|
|
@@ -88,72 +93,78 @@ module Caracal
|
|
|
88
93
|
end
|
|
89
94
|
end
|
|
90
95
|
end
|
|
91
|
-
|
|
96
|
+
|
|
92
97
|
def calculate_width(default_width)
|
|
93
98
|
width(default_width) unless cell_width.to_i > 0
|
|
94
|
-
|
|
99
|
+
|
|
95
100
|
container_width = cell_width - cell_margin_left - cell_margin_right
|
|
96
|
-
|
|
101
|
+
|
|
97
102
|
contents.each do |model|
|
|
98
103
|
if model.respond_to?(:calculate_width)
|
|
99
104
|
model.calculate_width(container_width) # will always be a TableModel
|
|
100
105
|
end
|
|
101
106
|
end
|
|
102
107
|
end
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
|
|
109
|
+
|
|
105
110
|
#=============== GETTERS ==============================
|
|
106
|
-
|
|
111
|
+
|
|
107
112
|
# margin attrs
|
|
108
113
|
[:top, :bottom, :left, :right].each do |m|
|
|
109
114
|
define_method "cell_margin_#{ m }" do
|
|
110
115
|
v = cell_margins ? cell_margins.send("margin_#{ m }") : 0
|
|
111
116
|
end
|
|
112
117
|
end
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
|
|
119
|
+
|
|
115
120
|
#=============== SETTERS ==============================
|
|
116
|
-
|
|
121
|
+
|
|
117
122
|
# integers
|
|
118
|
-
[:width].each do |m|
|
|
123
|
+
[:width, :colspan, :rowspan].each do |m|
|
|
119
124
|
define_method "#{ m }" do |value|
|
|
120
125
|
instance_variable_set("@cell_#{ m }", value.to_i)
|
|
121
126
|
end
|
|
122
127
|
end
|
|
123
|
-
|
|
128
|
+
|
|
124
129
|
# models
|
|
125
130
|
[:margins].each do |m|
|
|
126
131
|
define_method "#{ m }" do |options = {}, &block|
|
|
127
132
|
instance_variable_set("@cell_#{ m }", Caracal::Core::Models::MarginModel.new(options, &block))
|
|
128
133
|
end
|
|
129
134
|
end
|
|
130
|
-
|
|
135
|
+
|
|
131
136
|
# strings
|
|
132
137
|
[:background].each do |m|
|
|
133
138
|
define_method "#{ m }" do |value|
|
|
134
139
|
instance_variable_set("@cell_#{ m }", value.to_s)
|
|
135
140
|
end
|
|
136
141
|
end
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
|
|
143
|
+
#symbols
|
|
144
|
+
[:vertical_align].each do |m|
|
|
145
|
+
define_method "#{ m }" do |value|
|
|
146
|
+
instance_variable_set("@cell_#{ m }", value.to_s.to_sym)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
139
150
|
#=============== VALIDATION ===========================
|
|
140
|
-
|
|
151
|
+
|
|
141
152
|
def valid?
|
|
142
153
|
contents.size > 0
|
|
143
154
|
end
|
|
144
|
-
|
|
145
|
-
|
|
155
|
+
|
|
156
|
+
|
|
146
157
|
#-------------------------------------------------------------
|
|
147
158
|
# Private Instance Methods
|
|
148
159
|
#-------------------------------------------------------------
|
|
149
160
|
private
|
|
150
|
-
|
|
161
|
+
|
|
151
162
|
def option_keys
|
|
152
|
-
[:background, :margins, :width]
|
|
163
|
+
[:background, :margins, :width, :vertical_align, :rowspan, :colspan]
|
|
153
164
|
end
|
|
154
|
-
|
|
165
|
+
|
|
155
166
|
end
|
|
156
|
-
|
|
167
|
+
|
|
157
168
|
end
|
|
158
169
|
end
|
|
159
|
-
end
|
|
170
|
+
end
|
|
@@ -10,12 +10,13 @@ module Caracal
|
|
|
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
20
|
attr_reader :text_font
|
|
20
21
|
attr_reader :text_color
|
|
21
22
|
attr_reader :text_size
|
|
@@ -23,30 +24,33 @@ module Caracal
|
|
|
23
24
|
attr_reader :text_italic
|
|
24
25
|
attr_reader :text_underline
|
|
25
26
|
attr_reader :text_bgcolor
|
|
27
|
+
attr_reader :text_vertical_align
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
# Public
|
|
31
|
-
|
|
31
|
+
#--------------------------------------------------
|
|
32
|
+
# Public Methods
|
|
33
|
+
#--------------------------------------------------
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
#========== GETTERS ===============================
|
|
34
36
|
|
|
35
37
|
# .run_attributes
|
|
36
38
|
def run_attributes
|
|
37
39
|
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
style: text_style,
|
|
41
|
+
font: text_font,
|
|
42
|
+
color: text_color,
|
|
43
|
+
size: text_size,
|
|
44
|
+
bold: text_bold,
|
|
45
|
+
italic: text_italic,
|
|
46
|
+
underline: text_underline,
|
|
47
|
+
bgcolor: text_bgcolor,
|
|
48
|
+
vertical_align: text_vertical_align
|
|
45
49
|
}
|
|
46
50
|
end
|
|
47
51
|
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
#========== SETTERS ===============================
|
|
50
54
|
|
|
51
55
|
# booleans
|
|
52
56
|
[:bold, :italic, :underline].each do |m|
|
|
@@ -63,14 +67,21 @@ module Caracal
|
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
# strings
|
|
66
|
-
[:bgcolor, :color, :content, :font].each do |m|
|
|
70
|
+
[:bgcolor, :color, :content, :font, :style].each do |m|
|
|
67
71
|
define_method "#{ m }" do |value|
|
|
68
72
|
instance_variable_set("@text_#{ m }", value.to_s)
|
|
69
73
|
end
|
|
70
74
|
end
|
|
71
75
|
|
|
76
|
+
# symbols
|
|
77
|
+
[:vertical_align].each do |m|
|
|
78
|
+
define_method "#{ m }" do |value|
|
|
79
|
+
instance_variable_set("@text_#{ m }", value.to_s.to_sym)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
|
|
84
|
+
#========== VALIDATION ============================
|
|
74
85
|
|
|
75
86
|
def valid?
|
|
76
87
|
a = [:content]
|
|
@@ -78,13 +89,24 @@ module Caracal
|
|
|
78
89
|
end
|
|
79
90
|
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
# Private
|
|
83
|
-
|
|
92
|
+
#--------------------------------------------------
|
|
93
|
+
# Private Methods
|
|
94
|
+
#--------------------------------------------------
|
|
84
95
|
private
|
|
85
96
|
|
|
86
97
|
def option_keys
|
|
87
|
-
[:content, :font, :color, :size, :bold, :italic, :underline, :bgcolor]
|
|
98
|
+
[:content, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def method_missing(method, *args, &block)
|
|
102
|
+
# I'm on the fence with respect to this implementation. We're ignoring
|
|
103
|
+
# :method_missing errors to allow syntax flexibility for paragraph-type
|
|
104
|
+
# models. The issue is the syntax format of those models--the way we pass
|
|
105
|
+
# the content value as a special argument--coupled with the model's
|
|
106
|
+
# ability to accept nested instructions.
|
|
107
|
+
#
|
|
108
|
+
# By ignoring method missing errors here, we can pass the entire paragraph
|
|
109
|
+
# block in the initial, built-in call to :text.
|
|
88
110
|
end
|
|
89
111
|
|
|
90
112
|
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'caracal/core/models/namespace_model'
|
|
2
|
+
require 'caracal/errors'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module Caracal
|
|
6
|
+
module Core
|
|
7
|
+
|
|
8
|
+
# This module encapsulates all the functionality related to registering and
|
|
9
|
+
# retrieving namespaces.
|
|
10
|
+
#
|
|
11
|
+
module Namespaces
|
|
12
|
+
def self.included(base)
|
|
13
|
+
base.class_eval do
|
|
14
|
+
|
|
15
|
+
#-------------------------------------------------------------
|
|
16
|
+
# Class Methods
|
|
17
|
+
#-------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
def self.default_namespaces
|
|
20
|
+
[
|
|
21
|
+
{ prefix: 'xmlns:mc', href: 'http://schemas.openxmlformats.org/markup-compatibility/2006' },
|
|
22
|
+
{ prefix: 'xmlns:o', href: 'urn:schemas-microsoft-com:office:office' },
|
|
23
|
+
{ prefix: 'xmlns:r', href: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships' },
|
|
24
|
+
{ prefix: 'xmlns:m', href: 'http://schemas.openxmlformats.org/officeDocument/2006/math' },
|
|
25
|
+
{ prefix: 'xmlns:v', href: 'urn:schemas-microsoft-com:vml' },
|
|
26
|
+
{ prefix: 'xmlns:wp', href: 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing' },
|
|
27
|
+
{ prefix: 'xmlns:w10', href: 'urn:schemas-microsoft-com:office:word' },
|
|
28
|
+
{ prefix: 'xmlns:w', href: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main' },
|
|
29
|
+
{ prefix: 'xmlns:wne', href: 'http://schemas.microsoft.com/office/word/2006/wordml' },
|
|
30
|
+
{ prefix: 'xmlns:sl', href: 'http://schemas.openxmlformats.org/schemaLibrary/2006/main' },
|
|
31
|
+
{ prefix: 'xmlns:a', href: 'http://schemas.openxmlformats.org/drawingml/2006/main' },
|
|
32
|
+
{ prefix: 'xmlns:pic', href: 'http://schemas.openxmlformats.org/drawingml/2006/picture' },
|
|
33
|
+
{ prefix: 'xmlns:c', href: 'http://schemas.openxmlformats.org/drawingml/2006/chart' },
|
|
34
|
+
{ prefix: 'xmlns:lc', href: 'http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas' },
|
|
35
|
+
{ prefix: 'xmlns:dgm', href: 'http://schemas.openxmlformats.org/drawingml/2006/diagram' }
|
|
36
|
+
]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
#-------------------------------------------------------------
|
|
41
|
+
# Public Methods
|
|
42
|
+
#-------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
#============== ATTRIBUTES ==========================
|
|
45
|
+
|
|
46
|
+
def namespace(options={}, &block)
|
|
47
|
+
model = Caracal::Core::Models::NamespaceModel.new(options, &block)
|
|
48
|
+
if model.valid?
|
|
49
|
+
ns = register_namespace(model)
|
|
50
|
+
else
|
|
51
|
+
raise Caracal::Errors::InvalidModelError, 'namespace must specify the :prefix and :href attributes.'
|
|
52
|
+
end
|
|
53
|
+
ns
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#============== GETTERS =============================
|
|
58
|
+
|
|
59
|
+
def namespaces
|
|
60
|
+
@namespaces ||= []
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def find_namespace(prefix)
|
|
64
|
+
namespaces.find { |ns| ns.matches?(prefix) }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
#============== REGISTRATION ========================
|
|
69
|
+
|
|
70
|
+
def register_namespace(model)
|
|
71
|
+
unless ns = find_namespace(model.namespace_prefix)
|
|
72
|
+
namespaces << model
|
|
73
|
+
ns = model
|
|
74
|
+
end
|
|
75
|
+
ns
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def unregister_namespace(prefix)
|
|
79
|
+
if ns = find_namespace(prefix)
|
|
80
|
+
namespaces.delete(ns)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -4,49 +4,55 @@ require 'caracal/errors'
|
|
|
4
4
|
|
|
5
5
|
module Caracal
|
|
6
6
|
module Core
|
|
7
|
-
|
|
8
|
-
# This module encapsulates all the functionality related to setting the
|
|
7
|
+
|
|
8
|
+
# This module encapsulates all the functionality related to setting the
|
|
9
9
|
# document's page number behavior.
|
|
10
10
|
#
|
|
11
11
|
module PageNumbers
|
|
12
12
|
def self.included(base)
|
|
13
13
|
base.class_eval do
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
#-------------------------------------------------------------
|
|
16
16
|
# Configuration
|
|
17
17
|
#-------------------------------------------------------------
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
# constants
|
|
20
20
|
const_set(:DEFAULT_PAGE_NUMBER_ALIGN, :center)
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
# accessors
|
|
23
|
-
attr_reader :page_number_show
|
|
24
23
|
attr_reader :page_number_align
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
attr_reader :page_number_label
|
|
25
|
+
attr_reader :page_number_label_size
|
|
26
|
+
attr_reader :page_number_number_size
|
|
27
|
+
attr_reader :page_number_show
|
|
28
|
+
|
|
29
|
+
|
|
27
30
|
#-------------------------------------------------------------
|
|
28
31
|
# Public Methods
|
|
29
32
|
#-------------------------------------------------------------
|
|
30
|
-
|
|
33
|
+
|
|
31
34
|
# This method controls whether and how page numbers are displayed
|
|
32
35
|
# on the document.
|
|
33
36
|
#
|
|
34
37
|
def page_numbers(*args, &block)
|
|
35
38
|
options = Caracal::Utilities.extract_options!(args)
|
|
36
|
-
options.merge!({ show: !!args.first }) unless args.first.nil? # careful: falsey
|
|
37
|
-
|
|
39
|
+
options.merge!({ show: !!args.first }) unless args.first.nil? # careful: just `args.first` is falsey
|
|
40
|
+
|
|
38
41
|
model = Caracal::Core::Models::PageNumberModel.new(options, &block)
|
|
39
42
|
if model.valid?
|
|
40
|
-
@
|
|
41
|
-
@
|
|
43
|
+
@page_number_align = model.page_number_align
|
|
44
|
+
@page_number_label = model.page_number_label
|
|
45
|
+
@page_number_label_size = model.page_number_label_size
|
|
46
|
+
@page_number_number_size = model.page_number_number_size
|
|
47
|
+
@page_number_show = model.page_number_show
|
|
42
48
|
else
|
|
43
49
|
raise Caracal::Errors::InvalidModelError, 'page_numbers :align parameter must be :left, :center, or :right'
|
|
44
50
|
end
|
|
45
51
|
end
|
|
46
|
-
|
|
52
|
+
|
|
47
53
|
end
|
|
48
54
|
end
|
|
49
55
|
end
|
|
50
|
-
|
|
56
|
+
|
|
51
57
|
end
|
|
52
|
-
end
|
|
58
|
+
end
|