caracal 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +334 -702
- data/lib/caracal.rb +1 -0
- data/lib/caracal/core/file_name.rb +1 -1
- data/lib/caracal/core/fonts.rb +2 -2
- data/lib/caracal/core/images.rb +3 -2
- data/lib/caracal/core/list_styles.rb +20 -20
- data/lib/caracal/core/lists.rb +2 -2
- data/lib/caracal/core/models/base_model.rb +1 -1
- data/lib/caracal/core/models/border_model.rb +1 -1
- data/lib/caracal/core/models/image_model.rb +1 -1
- data/lib/caracal/core/models/link_model.rb +11 -0
- data/lib/caracal/core/models/list_item_model.rb +2 -2
- data/lib/caracal/core/models/list_model.rb +4 -3
- data/lib/caracal/core/models/list_style_model.rb +7 -18
- data/lib/caracal/core/models/margin_model.rb +1 -1
- data/lib/caracal/core/models/page_number_model.rb +1 -1
- data/lib/caracal/core/models/page_size_model.rb +1 -1
- data/lib/caracal/core/models/paragraph_model.rb +8 -6
- data/lib/caracal/core/models/style_model.rb +1 -1
- data/lib/caracal/core/models/table_cell_model.rb +3 -3
- data/lib/caracal/core/models/table_model.rb +2 -2
- data/lib/caracal/core/page_numbers.rb +4 -3
- data/lib/caracal/core/page_settings.rb +2 -2
- data/lib/caracal/core/relationships.rb +1 -1
- data/lib/caracal/core/rules.rb +1 -1
- data/lib/caracal/core/styles.rb +1 -1
- data/lib/caracal/core/tables.rb +3 -2
- data/lib/caracal/core/text.rb +6 -4
- data/lib/caracal/document.rb +10 -10
- data/lib/caracal/renderers/document_renderer.rb +1 -1
- data/lib/caracal/renderers/numbering_renderer.rb +2 -2
- data/lib/caracal/utilities.rb +23 -0
- data/lib/caracal/version.rb +1 -1
- data/spec/lib/caracal/core/models/link_model_spec.rb +6 -0
- data/spec/lib/caracal/core/models/list_style_model_spec.rb +15 -29
- metadata +3 -2
data/lib/caracal.rb
CHANGED
data/lib/caracal/core/fonts.rb
CHANGED
@@ -30,8 +30,8 @@ module Caracal
|
|
30
30
|
|
31
31
|
#============== ATTRIBUTES ==========================
|
32
32
|
|
33
|
-
def font(
|
34
|
-
model = Caracal::Core::Models::FontModel.new(
|
33
|
+
def font(options={}, &block)
|
34
|
+
model = Caracal::Core::Models::FontModel.new(options, &block)
|
35
35
|
|
36
36
|
if model.valid?
|
37
37
|
register_font(model)
|
data/lib/caracal/core/images.rb
CHANGED
@@ -16,8 +16,9 @@ module Caracal
|
|
16
16
|
# Public Methods
|
17
17
|
#-------------------------------------------------------------
|
18
18
|
|
19
|
-
def img(
|
20
|
-
options.
|
19
|
+
def img(*args, &block)
|
20
|
+
options = Caracal::Utilities.extract_options!(args)
|
21
|
+
options.merge!({ url: args.first }) if args.first
|
21
22
|
|
22
23
|
model = Caracal::Core::Models::ImageModel.new(options, &block)
|
23
24
|
if model.valid?
|
@@ -19,25 +19,25 @@ module Caracal
|
|
19
19
|
|
20
20
|
def self.default_list_styles
|
21
21
|
[
|
22
|
-
{ type: :ordered, level: 0, format: 'decimal', value: '%1.', left: 720,
|
23
|
-
{ type: :ordered, level: 1, format: 'lowerLetter', value: '%2.', left: 1440,
|
24
|
-
{ type: :ordered, level: 2, format: 'lowerRoman', value: '%3.', left: 2160,
|
25
|
-
{ type: :ordered, level: 3, format: 'decimal', value: '%4.', left: 2880,
|
26
|
-
{ type: :ordered, level: 4, format: 'lowerLetter', value: '%5.', left: 3600,
|
27
|
-
{ type: :ordered, level: 5, format: 'lowerRoman', value: '%6.', left: 4320,
|
28
|
-
{ type: :ordered, level: 6, format: 'decimal', value: '%7.', left: 5040,
|
29
|
-
{ type: :ordered, level: 7, format: 'lowerLetter', value: '%8.', left: 5760,
|
30
|
-
{ type: :ordered, level: 8, format: 'lowerRoman', value: '%9.', left: 6480,
|
31
|
-
|
32
|
-
{ type: :unordered, level: 0, format: 'bullet', value: '●', left: 720,
|
33
|
-
{ type: :unordered, level: 1, format: 'bullet', value: '○', left: 1440,
|
34
|
-
{ type: :unordered, level: 2, format: 'bullet', value: '■', left: 2160,
|
35
|
-
{ type: :unordered, level: 3, format: 'bullet', value: '●', left: 2880,
|
36
|
-
{ type: :unordered, level: 4, format: 'bullet', value: '○', left: 3600,
|
37
|
-
{ type: :unordered, level: 5, format: 'bullet', value: '■', left: 4320,
|
38
|
-
{ type: :unordered, level: 6, format: 'bullet', value: '●', left: 5040,
|
39
|
-
{ type: :unordered, level: 7, format: 'bullet', value: '○', left: 5760,
|
40
|
-
{ type: :unordered, level: 8, format: 'bullet', value: '■', left: 6480,
|
22
|
+
{ type: :ordered, level: 0, format: 'decimal', value: '%1.', left: 720, indent: 360 },
|
23
|
+
{ type: :ordered, level: 1, format: 'lowerLetter', value: '%2.', left: 1440, indent: 1080 },
|
24
|
+
{ type: :ordered, level: 2, format: 'lowerRoman', value: '%3.', left: 2160, indent: 1800, align: :right },
|
25
|
+
{ type: :ordered, level: 3, format: 'decimal', value: '%4.', left: 2880, indent: 2520 },
|
26
|
+
{ type: :ordered, level: 4, format: 'lowerLetter', value: '%5.', left: 3600, indent: 3240 },
|
27
|
+
{ type: :ordered, level: 5, format: 'lowerRoman', value: '%6.', left: 4320, indent: 3960, align: :right },
|
28
|
+
{ type: :ordered, level: 6, format: 'decimal', value: '%7.', left: 5040, indent: 4680 },
|
29
|
+
{ type: :ordered, level: 7, format: 'lowerLetter', value: '%8.', left: 5760, indent: 5400 },
|
30
|
+
{ type: :ordered, level: 8, format: 'lowerRoman', value: '%9.', left: 6480, indent: 6120, align: :right },
|
31
|
+
|
32
|
+
{ type: :unordered, level: 0, format: 'bullet', value: '●', left: 720, indent: 360 },
|
33
|
+
{ type: :unordered, level: 1, format: 'bullet', value: '○', left: 1440, indent: 1080 },
|
34
|
+
{ type: :unordered, level: 2, format: 'bullet', value: '■', left: 2160, indent: 1800 },
|
35
|
+
{ type: :unordered, level: 3, format: 'bullet', value: '●', left: 2880, indent: 2520 },
|
36
|
+
{ type: :unordered, level: 4, format: 'bullet', value: '○', left: 3600, indent: 3240 },
|
37
|
+
{ type: :unordered, level: 5, format: 'bullet', value: '■', left: 4320, indent: 3960 },
|
38
|
+
{ type: :unordered, level: 6, format: 'bullet', value: '●', left: 5040, indent: 4680 },
|
39
|
+
{ type: :unordered, level: 7, format: 'bullet', value: '○', left: 5760, indent: 5400 },
|
40
|
+
{ type: :unordered, level: 8, format: 'bullet', value: '■', left: 6480, indent: 6120 }
|
41
41
|
]
|
42
42
|
end
|
43
43
|
|
@@ -48,7 +48,7 @@ module Caracal
|
|
48
48
|
|
49
49
|
#============== ATTRIBUTES ==========================
|
50
50
|
|
51
|
-
def list_style(options
|
51
|
+
def list_style(options={}, &block)
|
52
52
|
model = Caracal::Core::Models::ListStyleModel.new(options, &block)
|
53
53
|
|
54
54
|
if model.valid?
|
data/lib/caracal/core/lists.rb
CHANGED
@@ -18,7 +18,7 @@ module Caracal
|
|
18
18
|
|
19
19
|
#============== ATTRIBUTES ==========================
|
20
20
|
|
21
|
-
def ol(options
|
21
|
+
def ol(options={}, &block)
|
22
22
|
options.merge!({ type: :ordered, level: 0 })
|
23
23
|
|
24
24
|
model = Caracal::Core::Models::ListModel.new(options, &block)
|
@@ -30,7 +30,7 @@ module Caracal
|
|
30
30
|
model
|
31
31
|
end
|
32
32
|
|
33
|
-
def ul(options
|
33
|
+
def ul(options={}, &block)
|
34
34
|
options.merge!({ type: :unordered, level: 0 })
|
35
35
|
|
36
36
|
model = Caracal::Core::Models::ListModel.new(options, &block)
|
@@ -12,7 +12,7 @@ module Caracal
|
|
12
12
|
#-------------------------------------------------------------
|
13
13
|
|
14
14
|
# initialization
|
15
|
-
def initialize(options
|
15
|
+
def initialize(options={}, &block)
|
16
16
|
options.keep_if { |k,v| option_keys.include? k }
|
17
17
|
options.each do |(key, value)|
|
18
18
|
send(key, value)
|
@@ -14,6 +14,10 @@ module Caracal
|
|
14
14
|
# Configuration
|
15
15
|
#-------------------------------------------------------------
|
16
16
|
|
17
|
+
# constants
|
18
|
+
const_set(:DEFAULT_LINK_COLOR, '1155cc')
|
19
|
+
const_set(:DEFAULT_LINK_UNDERLINE, true)
|
20
|
+
|
17
21
|
# readers (create aliases for superclass methods to conform
|
18
22
|
# to expected naming convention.)
|
19
23
|
attr_reader :link_href
|
@@ -25,6 +29,13 @@ module Caracal
|
|
25
29
|
alias_method :link_italic, :text_italic
|
26
30
|
alias_method :link_underline, :text_underline
|
27
31
|
|
32
|
+
# initialization
|
33
|
+
def initialize(options={}, &block)
|
34
|
+
@text_color = DEFAULT_LINK_COLOR
|
35
|
+
@text_underline = DEFAULT_LINK_UNDERLINE
|
36
|
+
|
37
|
+
super options, &block
|
38
|
+
end
|
28
39
|
|
29
40
|
|
30
41
|
#-------------------------------------------------------------
|
@@ -56,7 +56,7 @@ module Caracal
|
|
56
56
|
#=============== SUB-METHODS ===========================
|
57
57
|
|
58
58
|
# .ol
|
59
|
-
def ol(options
|
59
|
+
def ol(options={}, &block)
|
60
60
|
options.merge!({ type: :ordered, level: list_item_level + 1 })
|
61
61
|
|
62
62
|
model = Caracal::Core::Models::ListModel.new(options, &block)
|
@@ -68,7 +68,7 @@ module Caracal
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# .ul
|
71
|
-
def ul(options
|
71
|
+
def ul(options={}, &block)
|
72
72
|
options.merge!({ type: :unordered, level: list_item_level + 1 })
|
73
73
|
|
74
74
|
model = Caracal::Core::Models::ListModel.new(options, &block)
|
@@ -26,7 +26,7 @@ module Caracal
|
|
26
26
|
|
27
27
|
|
28
28
|
# initialization
|
29
|
-
def initialize(options
|
29
|
+
def initialize(options={}, &block)
|
30
30
|
@list_type = DEFAULT_LIST_TYPE
|
31
31
|
@list_level = DEFAULT_LIST_LEVEL
|
32
32
|
|
@@ -91,8 +91,9 @@ module Caracal
|
|
91
91
|
#=============== SUB-METHODS ===========================
|
92
92
|
|
93
93
|
# .li
|
94
|
-
def li(
|
95
|
-
options.
|
94
|
+
def li(*args, &block)
|
95
|
+
options = Caracal::Utilities.extract_options!(args)
|
96
|
+
options.merge!({ content: args.first }) if args.first
|
96
97
|
options.merge!({ type: list_type })
|
97
98
|
options.merge!({ level: list_level })
|
98
99
|
|
@@ -14,10 +14,10 @@ module Caracal
|
|
14
14
|
# constants
|
15
15
|
const_set(:TYPE_MAP, { ordered: 1, unordered: 2 })
|
16
16
|
const_set(:DEFAULT_STYLE_LEFT, 720) # units in twips
|
17
|
-
const_set(:
|
17
|
+
const_set(:DEFAULT_STYLE_INDENT, 360) # units in twips
|
18
18
|
const_set(:DEFAULT_STYLE_ALIGN, :left)
|
19
19
|
const_set(:DEFAULT_STYLE_START, 1)
|
20
|
-
const_set(:DEFAULT_STYLE_RESTART,
|
20
|
+
const_set(:DEFAULT_STYLE_RESTART, 1)
|
21
21
|
|
22
22
|
# accessors
|
23
23
|
attr_reader :style_type
|
@@ -27,15 +27,15 @@ module Caracal
|
|
27
27
|
attr_reader :style_start
|
28
28
|
attr_reader :style_align
|
29
29
|
attr_reader :style_left
|
30
|
-
attr_reader :
|
30
|
+
attr_reader :style_indent
|
31
31
|
attr_reader :style_restart
|
32
32
|
|
33
33
|
|
34
34
|
# initialization
|
35
|
-
def initialize(options
|
35
|
+
def initialize(options={}, &block)
|
36
36
|
@style_align = DEFAULT_STYLE_ALIGN
|
37
37
|
@style_left = DEFAULT_STYLE_LEFT
|
38
|
-
@
|
38
|
+
@style_indent = DEFAULT_STYLE_INDENT
|
39
39
|
@style_start = DEFAULT_STYLE_START
|
40
40
|
@style_restart = DEFAULT_STYLE_RESTART
|
41
41
|
|
@@ -62,22 +62,11 @@ module Caracal
|
|
62
62
|
self.class.formatted_type(style_type)
|
63
63
|
end
|
64
64
|
|
65
|
-
def formatted_restart
|
66
|
-
v = style_restart ? '1' : '0'
|
67
|
-
end
|
68
|
-
|
69
65
|
|
70
66
|
#=============== SETTERS ==============================
|
71
67
|
|
72
|
-
# booleans
|
73
|
-
[:restart].each do |m|
|
74
|
-
define_method "#{ m }" do |value|
|
75
|
-
instance_variable_set("@style_#{ m }", !!value)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
68
|
# integers
|
80
|
-
[:level, :left, :
|
69
|
+
[:level, :left, :indent, :start, :restart].each do |m|
|
81
70
|
define_method "#{ m }" do |value|
|
82
71
|
instance_variable_set("@style_#{ m }", value.to_i)
|
83
72
|
end
|
@@ -119,7 +108,7 @@ module Caracal
|
|
119
108
|
private
|
120
109
|
|
121
110
|
def option_keys
|
122
|
-
[:type, :level, :format, :value, :align, :left, :
|
111
|
+
[:type, :level, :format, :value, :align, :left, :indent, :start]
|
123
112
|
end
|
124
113
|
|
125
114
|
end
|
@@ -27,7 +27,7 @@ module Caracal
|
|
27
27
|
attr_reader :paragraph_underline
|
28
28
|
|
29
29
|
# initialization
|
30
|
-
def initialize(options
|
30
|
+
def initialize(options={}, &block)
|
31
31
|
if content = options.delete(:content)
|
32
32
|
text content, options.dup
|
33
33
|
end
|
@@ -93,9 +93,10 @@ module Caracal
|
|
93
93
|
#=============== SUB-METHODS ===========================
|
94
94
|
|
95
95
|
# .link
|
96
|
-
def link(
|
97
|
-
options.
|
98
|
-
options.merge!({
|
96
|
+
def link(*args, &block)
|
97
|
+
options = Caracal::Utilities.extract_options!(args)
|
98
|
+
options.merge!({ content: args[0] }) if args[0]
|
99
|
+
options.merge!({ href: args[1] }) if args[1]
|
99
100
|
|
100
101
|
model = Caracal::Core::Models::LinkModel.new(options, &block)
|
101
102
|
if model.valid?
|
@@ -106,8 +107,9 @@ module Caracal
|
|
106
107
|
end
|
107
108
|
|
108
109
|
# .text
|
109
|
-
def text(
|
110
|
-
options.
|
110
|
+
def text(*args, &block)
|
111
|
+
options = Caracal::Utilities.extract_options!(args)
|
112
|
+
options.merge!({ content: args.first }) if args.first
|
111
113
|
|
112
114
|
model = Caracal::Core::Models::TextModel.new(options, &block)
|
113
115
|
if model.valid?
|
@@ -25,7 +25,7 @@ module Caracal
|
|
25
25
|
attr_reader :cell_margins
|
26
26
|
|
27
27
|
# initialization
|
28
|
-
def initialize(options
|
28
|
+
def initialize(options={}, &block)
|
29
29
|
@cell_background = DEFAULT_CELL_BACKGROUND
|
30
30
|
@cell_margins = DEFAULT_CELL_MARGINS
|
31
31
|
|
@@ -57,9 +57,9 @@ module Caracal
|
|
57
57
|
#
|
58
58
|
# In all cases, invalid options will simply be ignored.
|
59
59
|
#
|
60
|
-
def apply_styles(opts
|
60
|
+
def apply_styles(opts={})
|
61
61
|
# make dup of options so we don't
|
62
|
-
# harm
|
62
|
+
# harm args sent to sibling cells
|
63
63
|
options = opts.dup
|
64
64
|
|
65
65
|
# first, try apply to self
|
@@ -38,7 +38,7 @@ module Caracal
|
|
38
38
|
attr_reader :table_border_vertical # returns border model
|
39
39
|
|
40
40
|
# initialization
|
41
|
-
def initialize(options
|
41
|
+
def initialize(options={}, &block)
|
42
42
|
@table_align = DEFAULT_TABLE_ALIGN
|
43
43
|
@table_border_color = DEFAULT_TABLE_BORDER_COLOR
|
44
44
|
@table_border_line = DEFAULT_TABLE_BORDER_LINE
|
@@ -94,7 +94,7 @@ module Caracal
|
|
94
94
|
# t.cell_style t.rows[0], background: '3366cc', color: 'ffffff', bold: true
|
95
95
|
# end
|
96
96
|
#
|
97
|
-
def cell_style(models, options
|
97
|
+
def cell_style(models, options={})
|
98
98
|
[models].flatten.each do |m|
|
99
99
|
m.apply_styles(options)
|
100
100
|
end
|
@@ -31,10 +31,11 @@ module Caracal
|
|
31
31
|
# This method controls whether and how page numbers are displayed
|
32
32
|
# on the document.
|
33
33
|
#
|
34
|
-
def page_numbers(
|
35
|
-
options.
|
36
|
-
|
34
|
+
def page_numbers(*args, &block)
|
35
|
+
options = Caracal::Utilities.extract_options!(args)
|
36
|
+
options.merge!({ show: !!args.first }) unless args.first.nil? # careful: falsey value
|
37
37
|
|
38
|
+
model = Caracal::Core::Models::PageNumberModel.new(options, &block)
|
38
39
|
if model.valid?
|
39
40
|
@page_number_show = model.page_number_show
|
40
41
|
@page_number_align = model.page_number_align
|
@@ -33,7 +33,7 @@ module Caracal
|
|
33
33
|
# This method controls the physical margins of the printed page. Defaults
|
34
34
|
# to 1in on each side.
|
35
35
|
#
|
36
|
-
def page_margins(options
|
36
|
+
def page_margins(options={}, &block)
|
37
37
|
model = Caracal::Core::Models::MarginModel.new(options, &block)
|
38
38
|
|
39
39
|
if model.valid?
|
@@ -53,7 +53,7 @@ module Caracal
|
|
53
53
|
# This method controls the physical width and height of the printed page. Defaults
|
54
54
|
# to US standard A4 portrait size.
|
55
55
|
#
|
56
|
-
def page_size(options
|
56
|
+
def page_size(options={}, &block)
|
57
57
|
model = Caracal::Core::Models::PageSizeModel.new(options, &block)
|
58
58
|
|
59
59
|
if model.valid?
|
data/lib/caracal/core/rules.rb
CHANGED