caracal 0.1.1 → 0.1.2
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/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/core/styles.rb
CHANGED
data/lib/caracal/core/tables.rb
CHANGED
@@ -16,8 +16,9 @@ module Caracal
|
|
16
16
|
# Public Methods
|
17
17
|
#-------------------------------------------------------------
|
18
18
|
|
19
|
-
def table(
|
20
|
-
options.
|
19
|
+
def table(*args, &block)
|
20
|
+
options = Caracal::Utilities.extract_options!(args)
|
21
|
+
options.merge!({ data: args.first }) if args.first
|
21
22
|
|
22
23
|
model = Caracal::Core::Models::TableModel.new(options, &block)
|
23
24
|
if respond_to?(:page_width)
|
data/lib/caracal/core/text.rb
CHANGED
@@ -18,8 +18,9 @@ module Caracal
|
|
18
18
|
|
19
19
|
#============== PARAGRAPHS ==========================
|
20
20
|
|
21
|
-
def p(
|
22
|
-
options.
|
21
|
+
def p(*args, &block)
|
22
|
+
options = Caracal::Utilities.extract_options!(args)
|
23
|
+
options.merge!({ content: args.first }) if args.first
|
23
24
|
|
24
25
|
model = Caracal::Core::Models::ParagraphModel.new(options, &block)
|
25
26
|
if model.valid?
|
@@ -37,9 +38,10 @@ module Caracal
|
|
37
38
|
# model with an explicitly set style class.
|
38
39
|
#
|
39
40
|
[:h1, :h2, :h3, :h4, :h5, :h6].each do |cmd|
|
40
|
-
define_method "#{ cmd }" do
|
41
|
+
define_method "#{ cmd }" do |*args, &block|
|
42
|
+
options = Caracal::Utilities.extract_options!(args)
|
41
43
|
options.merge!({ style: style_id_for_header(cmd) })
|
42
|
-
p(
|
44
|
+
p(args.first, options, &block)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
data/lib/caracal/document.rb
CHANGED
@@ -59,16 +59,6 @@ module Caracal
|
|
59
59
|
# Public Class Methods
|
60
60
|
#-------------------------------------------------------------
|
61
61
|
|
62
|
-
#============ GETTERS ===================================
|
63
|
-
|
64
|
-
# This method returns an array of models which constitute the
|
65
|
-
# set of instructions for producing the document content.
|
66
|
-
#
|
67
|
-
def contents
|
68
|
-
@contents ||= []
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
62
|
#============ OUTPUT ====================================
|
73
63
|
|
74
64
|
# This method renders a new Word document and returns it as a
|
@@ -120,6 +110,16 @@ module Caracal
|
|
120
110
|
end
|
121
111
|
|
122
112
|
|
113
|
+
#============ GETTERS ===================================
|
114
|
+
|
115
|
+
# This method returns an array of models which constitute the
|
116
|
+
# set of instructions for producing the document content.
|
117
|
+
#
|
118
|
+
def contents
|
119
|
+
@contents ||= []
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
123
|
#============ RENDERING =================================
|
124
124
|
|
125
125
|
# This method renders the word document instance into
|
@@ -183,7 +183,7 @@ module Caracal
|
|
183
183
|
|
184
184
|
def render_listitem(xml, model, list_num)
|
185
185
|
ls = document.find_list_style(model.list_item_type, model.list_item_level)
|
186
|
-
hanging = ls.style_left.to_i - ls.
|
186
|
+
hanging = ls.style_left.to_i - ls.style_indent.to_i - 1
|
187
187
|
|
188
188
|
xml.send 'w:p', paragraph_options do
|
189
189
|
xml.send 'w:pPr' do
|
@@ -28,11 +28,11 @@ module Caracal
|
|
28
28
|
xml.send 'w:lvl', { 'w:ilvl' => s.style_level } do
|
29
29
|
xml.send 'w:start', { 'w:val' => s.style_start }
|
30
30
|
xml.send 'w:numFmt', { 'w:val' => s.style_format }
|
31
|
-
xml.send 'w:lvlRestart', { 'w:val' => s.
|
31
|
+
xml.send 'w:lvlRestart', { 'w:val' => s.style_restart }
|
32
32
|
xml.send 'w:lvlText', { 'w:val' => s.style_value }
|
33
33
|
xml.send 'w:lvlJc', { 'w:val' => s.style_align }
|
34
34
|
xml.send 'w:pPr' do
|
35
|
-
xml.send 'w:ind', { 'w:left' => s.style_left, 'w:firstLine' => s.
|
35
|
+
xml.send 'w:ind', { 'w:left' => s.style_left, 'w:firstLine' => s.style_indent }
|
36
36
|
end
|
37
37
|
xml.send 'w:rPr' do
|
38
38
|
xml.send 'w:u', { 'w:val' => 'none' }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# We're using this strategy borrowed from ActiveSupport to
|
2
|
+
# make command syntax a little more flexible. In a perfect
|
3
|
+
# world we'd just use the double splat feature of Ruby, but
|
4
|
+
# support for that is pretty limited at this point, so we're
|
5
|
+
# going the extra mile to be cool.
|
6
|
+
#
|
7
|
+
module Caracal
|
8
|
+
class Utilities
|
9
|
+
|
10
|
+
#-------------------------------------------------------------
|
11
|
+
# Public Class Methods
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
|
14
|
+
def self.extract_options!(args)
|
15
|
+
if args.last.is_a?(Hash)
|
16
|
+
args.pop
|
17
|
+
else
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/caracal/version.rb
CHANGED
@@ -20,6 +20,12 @@ describe Caracal::Core::Models::LinkModel do
|
|
20
20
|
|
21
21
|
describe 'configuration tests' do
|
22
22
|
|
23
|
+
# constants
|
24
|
+
describe 'constants' do
|
25
|
+
it { expect(described_class::DEFAULT_LINK_COLOR).to eq '1155cc' }
|
26
|
+
it { expect(described_class::DEFAULT_LINK_UNDERLINE).to eq true }
|
27
|
+
end
|
28
|
+
|
23
29
|
# accessors
|
24
30
|
describe 'accessors' do
|
25
31
|
it { expect(subject.link_content).to eq 'Link Text' }
|
@@ -9,9 +9,9 @@ describe Caracal::Core::Models::ListStyleModel do
|
|
9
9
|
value '%3.'
|
10
10
|
align :right
|
11
11
|
left 800
|
12
|
-
|
12
|
+
indent 400
|
13
13
|
start 2
|
14
|
-
restart
|
14
|
+
restart 2
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -23,11 +23,11 @@ describe Caracal::Core::Models::ListStyleModel do
|
|
23
23
|
|
24
24
|
# constants
|
25
25
|
describe 'constants' do
|
26
|
-
it { expect(described_class::DEFAULT_STYLE_ALIGN).to
|
27
|
-
it { expect(described_class::DEFAULT_STYLE_LEFT).to
|
28
|
-
it { expect(described_class::
|
29
|
-
it { expect(described_class::DEFAULT_STYLE_START).to
|
30
|
-
it { expect(described_class::DEFAULT_STYLE_RESTART).to eq
|
26
|
+
it { expect(described_class::DEFAULT_STYLE_ALIGN).to eq :left }
|
27
|
+
it { expect(described_class::DEFAULT_STYLE_LEFT).to eq 720 }
|
28
|
+
it { expect(described_class::DEFAULT_STYLE_INDENT).to eq 360 }
|
29
|
+
it { expect(described_class::DEFAULT_STYLE_START).to eq 1 }
|
30
|
+
it { expect(described_class::DEFAULT_STYLE_RESTART).to eq 1 }
|
31
31
|
end
|
32
32
|
|
33
33
|
# accessors
|
@@ -38,9 +38,9 @@ describe Caracal::Core::Models::ListStyleModel do
|
|
38
38
|
it { expect(subject.style_value).to eq '%3.' }
|
39
39
|
it { expect(subject.style_align).to eq :right }
|
40
40
|
it { expect(subject.style_left).to eq 800 }
|
41
|
-
it { expect(subject.
|
41
|
+
it { expect(subject.style_indent).to eq 400 }
|
42
42
|
it { expect(subject.style_start).to eq 2 }
|
43
|
-
it { expect(subject.style_restart).to eq
|
43
|
+
it { expect(subject.style_restart).to eq 2 }
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
@@ -85,28 +85,14 @@ describe Caracal::Core::Models::ListStyleModel do
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
# .formatted_restart
|
89
|
-
describe '.formatted_restart' do
|
90
|
-
describe 'when restart true' do
|
91
|
-
before { allow(subject).to receive(:style_restart).and_return(true) }
|
92
|
-
|
93
|
-
it { expect(subject.formatted_restart).to eq '1' }
|
94
|
-
end
|
95
|
-
describe 'when unordered list' do
|
96
|
-
before { allow(subject).to receive(:style_restart).and_return(false) }
|
97
|
-
|
98
|
-
it { expect(subject.formatted_restart).to eq '0' }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
88
|
|
103
89
|
#=============== SETTERS ==========================
|
104
90
|
|
105
91
|
# booleans
|
106
92
|
describe '.restart' do
|
107
|
-
before { subject.restart(
|
93
|
+
before { subject.restart(3) }
|
108
94
|
|
109
|
-
it { expect(subject.style_restart).to eq
|
95
|
+
it { expect(subject.style_restart).to eq 3 }
|
110
96
|
end
|
111
97
|
|
112
98
|
# integers
|
@@ -120,10 +106,10 @@ describe Caracal::Core::Models::ListStyleModel do
|
|
120
106
|
|
121
107
|
it { expect(subject.style_left).to eq 800 }
|
122
108
|
end
|
123
|
-
describe '.
|
124
|
-
before { subject.
|
109
|
+
describe '.indent' do
|
110
|
+
before { subject.indent(400) }
|
125
111
|
|
126
|
-
it { expect(subject.
|
112
|
+
it { expect(subject.style_indent).to eq 400 }
|
127
113
|
end
|
128
114
|
describe '.start' do
|
129
115
|
before { subject.start(2) }
|
@@ -202,7 +188,7 @@ describe Caracal::Core::Models::ListStyleModel do
|
|
202
188
|
# .option_keys
|
203
189
|
describe '.option_keys' do
|
204
190
|
let(:actual) { subject.send(:option_keys).sort }
|
205
|
-
let(:expected) { [:type, :level, :format, :value, :align, :left, :
|
191
|
+
let(:expected) { [:type, :level, :format, :value, :align, :left, :indent, :start].sort }
|
206
192
|
|
207
193
|
it { expect(actual).to eq expected }
|
208
194
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caracal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trade Infomatics
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/caracal/renderers/settings_renderer.rb
|
160
160
|
- lib/caracal/renderers/styles_renderer.rb
|
161
161
|
- lib/caracal/renderers/xml_renderer.rb
|
162
|
+
- lib/caracal/utilities.rb
|
162
163
|
- lib/caracal/version.rb
|
163
164
|
- lib/tilt/caracal.rb
|
164
165
|
- spec/lib/caracal/core/file_name_spec.rb
|