caracal_the_curve 1.4.1
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 +7 -0
- data/.github/workflows/main.yml +22 -0
- data/.github/workflows/publish_gem.yml +40 -0
- data/.gitignore +25 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +141 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +842 -0
- data/Rakefile +7 -0
- data/caracal.gemspec +28 -0
- data/lib/caracal/core/bookmarks.rb +52 -0
- data/lib/caracal/core/custom_properties.rb +49 -0
- data/lib/caracal/core/file_name.rb +43 -0
- data/lib/caracal/core/fonts.rb +75 -0
- data/lib/caracal/core/iframes.rb +42 -0
- data/lib/caracal/core/ignorables.rb +47 -0
- data/lib/caracal/core/images.rb +37 -0
- data/lib/caracal/core/list_styles.rb +93 -0
- data/lib/caracal/core/lists.rb +57 -0
- data/lib/caracal/core/models/base_model.rb +51 -0
- data/lib/caracal/core/models/bookmark_model.rb +86 -0
- data/lib/caracal/core/models/border_model.rb +120 -0
- data/lib/caracal/core/models/custom_property_model.rb +60 -0
- data/lib/caracal/core/models/font_model.rb +64 -0
- data/lib/caracal/core/models/iframe_model.rb +148 -0
- data/lib/caracal/core/models/image_model.rb +133 -0
- data/lib/caracal/core/models/line_break_model.rb +15 -0
- data/lib/caracal/core/models/link_model.rb +94 -0
- data/lib/caracal/core/models/list_item_model.rb +108 -0
- data/lib/caracal/core/models/list_model.rb +132 -0
- data/lib/caracal/core/models/list_style_model.rb +118 -0
- data/lib/caracal/core/models/margin_model.rb +76 -0
- data/lib/caracal/core/models/namespace_model.rb +65 -0
- data/lib/caracal/core/models/page_break_model.rb +61 -0
- data/lib/caracal/core/models/page_number_model.rb +95 -0
- data/lib/caracal/core/models/page_size_model.rb +79 -0
- data/lib/caracal/core/models/paragraph_model.rb +186 -0
- data/lib/caracal/core/models/relationship_model.rb +114 -0
- data/lib/caracal/core/models/rule_model.rb +27 -0
- data/lib/caracal/core/models/style_model.rb +165 -0
- data/lib/caracal/core/models/table_cell_model.rb +176 -0
- data/lib/caracal/core/models/table_model.rb +206 -0
- data/lib/caracal/core/models/text_model.rb +118 -0
- data/lib/caracal/core/namespaces.rb +89 -0
- data/lib/caracal/core/page_breaks.rb +29 -0
- data/lib/caracal/core/page_numbers.rb +58 -0
- data/lib/caracal/core/page_settings.rb +74 -0
- data/lib/caracal/core/relationships.rb +90 -0
- data/lib/caracal/core/rules.rb +35 -0
- data/lib/caracal/core/styles.rb +86 -0
- data/lib/caracal/core/tables.rb +42 -0
- data/lib/caracal/core/text.rb +75 -0
- data/lib/caracal/document.rb +272 -0
- data/lib/caracal/errors.rb +23 -0
- data/lib/caracal/renderers/app_renderer.rb +41 -0
- data/lib/caracal/renderers/content_types_renderer.rb +54 -0
- data/lib/caracal/renderers/core_renderer.rb +44 -0
- data/lib/caracal/renderers/custom_renderer.rb +64 -0
- data/lib/caracal/renderers/document_renderer.rb +427 -0
- data/lib/caracal/renderers/fonts_renderer.rb +56 -0
- data/lib/caracal/renderers/footer_renderer.rb +90 -0
- data/lib/caracal/renderers/numbering_renderer.rb +88 -0
- data/lib/caracal/renderers/package_relationships_renderer.rb +51 -0
- data/lib/caracal/renderers/relationships_renderer.rb +48 -0
- data/lib/caracal/renderers/settings_renderer.rb +58 -0
- data/lib/caracal/renderers/styles_renderer.rb +181 -0
- data/lib/caracal/renderers/xml_renderer.rb +83 -0
- data/lib/caracal/utilities.rb +23 -0
- data/lib/caracal/version.rb +3 -0
- data/lib/caracal.rb +40 -0
- data/lib/tilt/caracal.rb +21 -0
- data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
- data/spec/lib/caracal/core/file_name_spec.rb +54 -0
- data/spec/lib/caracal/core/fonts_spec.rb +119 -0
- 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/images_spec.rb +25 -0
- data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
- data/spec/lib/caracal/core/lists_spec.rb +43 -0
- data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
- data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
- data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
- data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
- data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +225 -0
- data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/link_model_spec.rb +179 -0
- data/spec/lib/caracal/core/models/list_item_model_spec.rb +197 -0
- data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
- data/spec/lib/caracal/core/models/list_style_model_spec.rb +198 -0
- data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
- data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
- data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +136 -0
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +101 -0
- data/spec/lib/caracal/core/models/paragraph_model_spec.rb +196 -0
- data/spec/lib/caracal/core/models/relationship_model_spec.rb +193 -0
- data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
- data/spec/lib/caracal/core/models/style_model_spec.rb +225 -0
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +230 -0
- data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
- data/spec/lib/caracal/core/models/text_model_spec.rb +154 -0
- data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
- data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +89 -0
- data/spec/lib/caracal/core/page_settings_spec.rb +151 -0
- data/spec/lib/caracal/core/relationships_spec.rb +119 -0
- data/spec/lib/caracal/core/rules_spec.rb +25 -0
- data/spec/lib/caracal/core/styles_spec.rb +129 -0
- data/spec/lib/caracal/core/tables_spec.rb +25 -0
- data/spec/lib/caracal/core/text_spec.rb +52 -0
- data/spec/lib/caracal/errors_spec.rb +10 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/_fixtures/snippet.docx +0 -0
- metadata +292 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'caracal/core/models/list_model'
|
2
|
+
require 'caracal/core/models/paragraph_model'
|
3
|
+
require 'caracal/errors'
|
4
|
+
|
5
|
+
|
6
|
+
module Caracal
|
7
|
+
module Core
|
8
|
+
module Models
|
9
|
+
|
10
|
+
# This class encapsulates the logic needed to store and manipulate
|
11
|
+
# list item data.
|
12
|
+
#
|
13
|
+
class ListItemModel < ParagraphModel
|
14
|
+
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
# Configuration
|
17
|
+
#-------------------------------------------------------------
|
18
|
+
|
19
|
+
# accessors
|
20
|
+
attr_accessor :nested_list
|
21
|
+
|
22
|
+
# readers (create aliases for superclass methods to conform
|
23
|
+
# to expected naming convention.)
|
24
|
+
attr_reader :list_item_type
|
25
|
+
attr_reader :list_item_level
|
26
|
+
alias_method :list_item_style, :paragraph_style
|
27
|
+
alias_method :list_item_color, :paragraph_color
|
28
|
+
alias_method :list_item_size, :paragraph_size
|
29
|
+
alias_method :list_item_bold, :paragraph_bold
|
30
|
+
alias_method :list_item_italic, :paragraph_italic
|
31
|
+
alias_method :list_item_underline, :paragraph_underline
|
32
|
+
alias_method :list_item_bgcolor, :paragraph_bgcolor
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
#-------------------------------------------------------------
|
37
|
+
# Public Instance Methods
|
38
|
+
#-------------------------------------------------------------
|
39
|
+
|
40
|
+
#=============== SETTERS ==============================
|
41
|
+
|
42
|
+
# integers
|
43
|
+
[:level].each do |m|
|
44
|
+
define_method "#{ m }" do |value|
|
45
|
+
instance_variable_set("@list_item_#{ m }", value.to_i)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# symbols
|
50
|
+
[:type].each do |m|
|
51
|
+
define_method "#{ m }" do |value|
|
52
|
+
instance_variable_set("@list_item_#{ m }", value.to_s.to_sym)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
#=============== SUB-METHODS ===========================
|
58
|
+
|
59
|
+
# .ol
|
60
|
+
def ol(options={}, &block)
|
61
|
+
options.merge!({ type: :ordered, level: list_item_level + 1 })
|
62
|
+
|
63
|
+
model = Caracal::Core::Models::ListModel.new(options, &block)
|
64
|
+
if model.valid?
|
65
|
+
@nested_list = model
|
66
|
+
else
|
67
|
+
raise Caracal::Errors::InvalidModelError, 'Ordered lists require at least one list item.'
|
68
|
+
end
|
69
|
+
model
|
70
|
+
end
|
71
|
+
|
72
|
+
# .ul
|
73
|
+
def ul(options={}, &block)
|
74
|
+
options.merge!({ type: :unordered, level: list_item_level + 1 })
|
75
|
+
|
76
|
+
model = Caracal::Core::Models::ListModel.new(options, &block)
|
77
|
+
if model.valid?
|
78
|
+
@nested_list = model
|
79
|
+
else
|
80
|
+
raise Caracal::Errors::InvalidModelError, 'Unordered lists require at least one list item.'
|
81
|
+
end
|
82
|
+
model
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
#=============== VALIDATION ===========================
|
87
|
+
|
88
|
+
def valid?
|
89
|
+
a = [:type, :level]
|
90
|
+
required = a.map { |m| send("list_item_#{ m }") }.compact.size == a.size
|
91
|
+
required && !runs.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
#-------------------------------------------------------------
|
96
|
+
# Private Instance Methods
|
97
|
+
#-------------------------------------------------------------
|
98
|
+
private
|
99
|
+
|
100
|
+
def option_keys
|
101
|
+
[:type, :level, :content, :style, :color, :size, :bold, :italic, :underline, :bgcolor]
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'caracal/core/models/base_model'
|
2
|
+
require 'caracal/core/models/list_item_model'
|
3
|
+
require 'caracal/errors'
|
4
|
+
|
5
|
+
|
6
|
+
module Caracal
|
7
|
+
module Core
|
8
|
+
module Models
|
9
|
+
|
10
|
+
# This class encapsulates the logic needed to store and manipulate
|
11
|
+
# list data.
|
12
|
+
#
|
13
|
+
class ListModel < BaseModel
|
14
|
+
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
# Configuration
|
17
|
+
#-------------------------------------------------------------
|
18
|
+
|
19
|
+
# constants
|
20
|
+
const_set(:DEFAULT_LIST_TYPE, :unordered)
|
21
|
+
const_set(:DEFAULT_LIST_LEVEL, 0)
|
22
|
+
|
23
|
+
# accessors
|
24
|
+
attr_reader :list_type
|
25
|
+
attr_reader :list_level
|
26
|
+
|
27
|
+
|
28
|
+
# initialization
|
29
|
+
def initialize(options={}, &block)
|
30
|
+
@list_type = DEFAULT_LIST_TYPE
|
31
|
+
@list_level = DEFAULT_LIST_LEVEL
|
32
|
+
|
33
|
+
super options, &block
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
#-------------------------------------------------------------
|
38
|
+
# Public Instance Methods
|
39
|
+
#-------------------------------------------------------------
|
40
|
+
|
41
|
+
#=============== GETTERS ==============================
|
42
|
+
|
43
|
+
# This method returns only those items owned directly
|
44
|
+
# by this list.
|
45
|
+
#
|
46
|
+
def items
|
47
|
+
@items ||= []
|
48
|
+
end
|
49
|
+
|
50
|
+
# This method returns a hash, where the keys are levels
|
51
|
+
# and the values are the list type at that level.
|
52
|
+
#
|
53
|
+
def level_map
|
54
|
+
recursive_items.reduce({}) do |hash, item|
|
55
|
+
hash[item.list_item_level] = item.list_item_type
|
56
|
+
hash
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# This method returns a flattened array containing every
|
61
|
+
# item within this list's tree.
|
62
|
+
#
|
63
|
+
def recursive_items
|
64
|
+
items.map do |model|
|
65
|
+
if model.nested_list.nil?
|
66
|
+
model
|
67
|
+
else
|
68
|
+
[model, model.nested_list.recursive_items]
|
69
|
+
end
|
70
|
+
end.flatten
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
#=============== SETTERS ==============================
|
75
|
+
|
76
|
+
# integers
|
77
|
+
[:level].each do |m|
|
78
|
+
define_method "#{ m }" do |value|
|
79
|
+
instance_variable_set("@list_#{ m }", value.to_i)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# symbols
|
84
|
+
[:type].each do |m|
|
85
|
+
define_method "#{ m }" do |value|
|
86
|
+
instance_variable_set("@list_#{ m }", value.to_s.to_sym)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
#=============== SUB-METHODS ===========================
|
92
|
+
|
93
|
+
# .li
|
94
|
+
def li(*args, &block)
|
95
|
+
options = Caracal::Utilities.extract_options!(args)
|
96
|
+
options.merge!({ content: args.first }) if args.first
|
97
|
+
options.merge!({ type: list_type })
|
98
|
+
options.merge!({ level: list_level })
|
99
|
+
|
100
|
+
model = Caracal::Core::Models::ListItemModel.new(options, &block)
|
101
|
+
if model.valid?
|
102
|
+
items << model
|
103
|
+
else
|
104
|
+
raise Caracal::Errors::InvalidModelError, 'List item must have at least one run.'
|
105
|
+
end
|
106
|
+
model
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
#=============== VALIDATION ===========================
|
111
|
+
|
112
|
+
def valid?
|
113
|
+
a = [:type, :level]
|
114
|
+
required = a.map { |m| send("list_#{ m }") }.compact.size == a.size
|
115
|
+
required && !items.empty?
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
#-------------------------------------------------------------
|
120
|
+
# Private Instance Methods
|
121
|
+
#-------------------------------------------------------------
|
122
|
+
private
|
123
|
+
|
124
|
+
def option_keys
|
125
|
+
[:type, :level]
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module Caracal
|
2
|
+
module Core
|
3
|
+
module Models
|
4
|
+
|
5
|
+
# This class encapsulates the logic needed to store and manipulate
|
6
|
+
# list style data.
|
7
|
+
#
|
8
|
+
class ListStyleModel < BaseModel
|
9
|
+
|
10
|
+
#-------------------------------------------------------------
|
11
|
+
# Configuration
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
|
14
|
+
# constants
|
15
|
+
const_set(:TYPE_MAP, { ordered: 1, unordered: 2 })
|
16
|
+
const_set(:DEFAULT_STYLE_LEFT, 720) # units in twips
|
17
|
+
const_set(:DEFAULT_STYLE_INDENT, 360) # units in twips
|
18
|
+
const_set(:DEFAULT_STYLE_ALIGN, :left)
|
19
|
+
const_set(:DEFAULT_STYLE_START, 1)
|
20
|
+
const_set(:DEFAULT_STYLE_RESTART, 1)
|
21
|
+
|
22
|
+
# accessors
|
23
|
+
attr_reader :style_type
|
24
|
+
attr_reader :style_level
|
25
|
+
attr_reader :style_format
|
26
|
+
attr_reader :style_value
|
27
|
+
attr_reader :style_start
|
28
|
+
attr_reader :style_align
|
29
|
+
attr_reader :style_left
|
30
|
+
attr_reader :style_indent
|
31
|
+
attr_reader :style_restart
|
32
|
+
|
33
|
+
|
34
|
+
# initialization
|
35
|
+
def initialize(options={}, &block)
|
36
|
+
@style_align = DEFAULT_STYLE_ALIGN
|
37
|
+
@style_left = DEFAULT_STYLE_LEFT
|
38
|
+
@style_indent = DEFAULT_STYLE_INDENT
|
39
|
+
@style_start = DEFAULT_STYLE_START
|
40
|
+
@style_restart = DEFAULT_STYLE_RESTART
|
41
|
+
|
42
|
+
super options, &block
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
#-------------------------------------------------------------
|
47
|
+
# Public Class Methods
|
48
|
+
#-------------------------------------------------------------
|
49
|
+
|
50
|
+
def self.formatted_type(type)
|
51
|
+
TYPE_MAP.fetch(type.to_s.to_sym)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
#-------------------------------------------------------------
|
56
|
+
# Public Instance Methods
|
57
|
+
#-------------------------------------------------------------
|
58
|
+
|
59
|
+
#=============== GETTERS ==============================
|
60
|
+
|
61
|
+
def formatted_type
|
62
|
+
self.class.formatted_type(style_type)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
#=============== SETTERS ==============================
|
67
|
+
|
68
|
+
# integers
|
69
|
+
[:level, :left, :indent, :start, :restart].each do |m|
|
70
|
+
define_method "#{ m }" do |value|
|
71
|
+
instance_variable_set("@style_#{ m }", value.to_i)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# strings
|
76
|
+
[:format, :value].each do |m|
|
77
|
+
define_method "#{ m }" do |value|
|
78
|
+
instance_variable_set("@style_#{ m }", value.to_s)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# symbols
|
83
|
+
[:type, :align].each do |m|
|
84
|
+
define_method "#{ m }" do |value|
|
85
|
+
instance_variable_set("@style_#{ m }", value.to_s.to_sym)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
#=============== STATE ================================
|
91
|
+
|
92
|
+
def matches?(type, level)
|
93
|
+
style_type == type.to_s.to_sym && style_level == level.to_i
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
#=============== VALIDATION ===========================
|
98
|
+
|
99
|
+
def valid?
|
100
|
+
a = [:type, :level, :format, :value]
|
101
|
+
a.map { |m| send("style_#{ m }") }.compact.size == a.size
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
#-------------------------------------------------------------
|
106
|
+
# Private Instance Methods
|
107
|
+
#-------------------------------------------------------------
|
108
|
+
private
|
109
|
+
|
110
|
+
def option_keys
|
111
|
+
[:type, :level, :format, :value, :align, :left, :indent, :start]
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'caracal/core/models/base_model'
|
2
|
+
|
3
|
+
|
4
|
+
module Caracal
|
5
|
+
module Core
|
6
|
+
module Models
|
7
|
+
|
8
|
+
# This class handles block options passed to the margins
|
9
|
+
# method.
|
10
|
+
#
|
11
|
+
class MarginModel < BaseModel
|
12
|
+
|
13
|
+
#-------------------------------------------------------------
|
14
|
+
# Configuration
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
|
17
|
+
# constants
|
18
|
+
const_set(:DEFAULT_MARGIN_TOP, 0) # units in twips
|
19
|
+
const_set(:DEFAULT_MARGIN_BOTTOM, 0) # units in twips
|
20
|
+
const_set(:DEFAULT_MARGIN_LEFT, 0) # units in twips
|
21
|
+
const_set(:DEFAULT_MARGIN_RIGHT, 0) # units in twips
|
22
|
+
|
23
|
+
# accessors
|
24
|
+
attr_reader :margin_top
|
25
|
+
attr_reader :margin_bottom
|
26
|
+
attr_reader :margin_left
|
27
|
+
attr_reader :margin_right
|
28
|
+
|
29
|
+
|
30
|
+
# initialization
|
31
|
+
def initialize(options={}, &block)
|
32
|
+
@margin_top = DEFAULT_MARGIN_TOP
|
33
|
+
@margin_bottom = DEFAULT_MARGIN_BOTTOM
|
34
|
+
@margin_left = DEFAULT_MARGIN_LEFT
|
35
|
+
@margin_right = DEFAULT_MARGIN_RIGHT
|
36
|
+
|
37
|
+
super options, &block
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
#-------------------------------------------------------------
|
42
|
+
# Public Methods
|
43
|
+
#-------------------------------------------------------------
|
44
|
+
|
45
|
+
#=============== SETTERS ==============================
|
46
|
+
|
47
|
+
# integers
|
48
|
+
[:bottom, :left, :right, :top].each do |m|
|
49
|
+
define_method "#{ m }" do |value|
|
50
|
+
instance_variable_set("@margin_#{ m }", value.to_i)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
#=============== VALIDATION ==============================
|
56
|
+
|
57
|
+
def valid?
|
58
|
+
dims = [:bottom, :left, :right, :top]
|
59
|
+
dims.map { |d| send("margin_#{ d }") }.all? { |d| d > 0 }
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
#-------------------------------------------------------------
|
64
|
+
# Private Instance Methods
|
65
|
+
#-------------------------------------------------------------
|
66
|
+
private
|
67
|
+
|
68
|
+
def option_keys
|
69
|
+
[:top, :bottom, :left, :right]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
# namespace data.
|
10
|
+
#
|
11
|
+
class NamespaceModel < BaseModel
|
12
|
+
|
13
|
+
#-------------------------------------------------------------
|
14
|
+
# Configuration
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
|
17
|
+
# accessors
|
18
|
+
attr_reader :namespace_prefix
|
19
|
+
attr_reader :namespace_href
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
#-------------------------------------------------------------
|
24
|
+
# Public Instance Methods
|
25
|
+
#-------------------------------------------------------------
|
26
|
+
|
27
|
+
#=================== SETTERS =============================
|
28
|
+
|
29
|
+
# strings
|
30
|
+
[:href, :prefix].each do |m|
|
31
|
+
define_method "#{ m }" do |value|
|
32
|
+
instance_variable_set("@namespace_#{ m }", value.to_s)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
#=================== STATE ===============================
|
38
|
+
|
39
|
+
def matches?(str)
|
40
|
+
namespace_prefix == str.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#=============== VALIDATION ===========================
|
45
|
+
|
46
|
+
def valid?
|
47
|
+
required = [:href, :prefix]
|
48
|
+
required.all? { |m| !send("namespace_#{ m }").nil? }
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
#-------------------------------------------------------------
|
53
|
+
# Private Instance Methods
|
54
|
+
#-------------------------------------------------------------
|
55
|
+
private
|
56
|
+
|
57
|
+
def option_keys
|
58
|
+
[:prefix, :href]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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
|
+
# page break data.
|
10
|
+
#
|
11
|
+
# The :wrap option is not described in the project's README because
|
12
|
+
# it exists purely as an internal Caracal concern. Page breaks
|
13
|
+
# at the document level must be wrapped in a paragraph node; page breaks
|
14
|
+
# within paragraph-like container simply add a run. There's no need to
|
15
|
+
# trouble end users with this issue.
|
16
|
+
#
|
17
|
+
class PageBreakModel < BaseModel
|
18
|
+
|
19
|
+
#-------------------------------------------------------------
|
20
|
+
# Configuration
|
21
|
+
#-------------------------------------------------------------
|
22
|
+
|
23
|
+
# constants
|
24
|
+
const_set(:DEFAULT_PAGE_BREAK_WRAP, true)
|
25
|
+
|
26
|
+
# accessors
|
27
|
+
attr_reader :page_break_wrap
|
28
|
+
|
29
|
+
# initialization
|
30
|
+
def initialize(options={}, &block)
|
31
|
+
@page_break_wrap = DEFAULT_PAGE_BREAK_WRAP
|
32
|
+
|
33
|
+
super options, &block
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
#-------------------------------------------------------------
|
38
|
+
# Public Methods
|
39
|
+
#-------------------------------------------------------------
|
40
|
+
|
41
|
+
#=============== SETTERS ==============================
|
42
|
+
|
43
|
+
def wrap(value)
|
44
|
+
@page_break_wrap = !!value
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
#-------------------------------------------------------------
|
49
|
+
# Private Instance Methods
|
50
|
+
#-------------------------------------------------------------
|
51
|
+
private
|
52
|
+
|
53
|
+
def option_keys
|
54
|
+
[:wrap]
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'caracal/core/models/base_model'
|
2
|
+
|
3
|
+
|
4
|
+
module Caracal
|
5
|
+
module Core
|
6
|
+
module Models
|
7
|
+
|
8
|
+
# This class handles block options passed to the page_numbers
|
9
|
+
# method.
|
10
|
+
#
|
11
|
+
class PageNumberModel < BaseModel
|
12
|
+
|
13
|
+
#-------------------------------------------------------------
|
14
|
+
# Configuration
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
|
17
|
+
# constants
|
18
|
+
const_set(:DEFAULT_PAGE_NUMBER_ALIGN, :center)
|
19
|
+
const_set(:DEFAULT_PAGE_NUMBER_SHOW, false)
|
20
|
+
|
21
|
+
# accessors
|
22
|
+
attr_reader :page_number_align
|
23
|
+
attr_reader :page_number_label
|
24
|
+
attr_reader :page_number_label_size
|
25
|
+
attr_reader :page_number_number_size
|
26
|
+
attr_reader :page_number_show
|
27
|
+
|
28
|
+
# initialization
|
29
|
+
def initialize(options={}, &block)
|
30
|
+
@page_number_align = DEFAULT_PAGE_NUMBER_ALIGN
|
31
|
+
@page_number_label = nil
|
32
|
+
@page_number_label_size = nil
|
33
|
+
@page_number_number_size = nil
|
34
|
+
@page_number_show = DEFAULT_PAGE_NUMBER_SHOW
|
35
|
+
|
36
|
+
super options, &block
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
#-------------------------------------------------------------
|
41
|
+
# Public Methods
|
42
|
+
#-------------------------------------------------------------
|
43
|
+
|
44
|
+
#=============== SETTERS ==============================
|
45
|
+
|
46
|
+
def align(value)
|
47
|
+
@page_number_align = value.to_s.to_sym
|
48
|
+
end
|
49
|
+
|
50
|
+
def label(value)
|
51
|
+
@page_number_label = value.to_s.strip # renderer will enforce trailing space
|
52
|
+
end
|
53
|
+
|
54
|
+
def label_size(value)
|
55
|
+
v = value.to_i
|
56
|
+
@page_number_label_size = (v == 0) ? nil : v
|
57
|
+
end
|
58
|
+
|
59
|
+
def number_size(value)
|
60
|
+
v = value.to_i
|
61
|
+
@page_number_number_size = (v == 0) ? nil : v
|
62
|
+
end
|
63
|
+
|
64
|
+
def show(value)
|
65
|
+
@page_number_show = !!value
|
66
|
+
end
|
67
|
+
|
68
|
+
def size(value)
|
69
|
+
v = value.to_i
|
70
|
+
@page_number_label_size = (v == 0) ? nil : v
|
71
|
+
@page_number_number_size = (v == 0) ? nil : v
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
#=============== VALIDATION ===========================
|
76
|
+
|
77
|
+
def valid?
|
78
|
+
(!page_number_show || [:left, :center, :right].include?(page_number_align))
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#-------------------------------------------------------------
|
83
|
+
# Private Instance Methods
|
84
|
+
#-------------------------------------------------------------
|
85
|
+
private
|
86
|
+
|
87
|
+
def option_keys
|
88
|
+
[:align, :label, :label_size, :number_size, :show]
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|