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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +334 -702
  3. data/lib/caracal.rb +1 -0
  4. data/lib/caracal/core/file_name.rb +1 -1
  5. data/lib/caracal/core/fonts.rb +2 -2
  6. data/lib/caracal/core/images.rb +3 -2
  7. data/lib/caracal/core/list_styles.rb +20 -20
  8. data/lib/caracal/core/lists.rb +2 -2
  9. data/lib/caracal/core/models/base_model.rb +1 -1
  10. data/lib/caracal/core/models/border_model.rb +1 -1
  11. data/lib/caracal/core/models/image_model.rb +1 -1
  12. data/lib/caracal/core/models/link_model.rb +11 -0
  13. data/lib/caracal/core/models/list_item_model.rb +2 -2
  14. data/lib/caracal/core/models/list_model.rb +4 -3
  15. data/lib/caracal/core/models/list_style_model.rb +7 -18
  16. data/lib/caracal/core/models/margin_model.rb +1 -1
  17. data/lib/caracal/core/models/page_number_model.rb +1 -1
  18. data/lib/caracal/core/models/page_size_model.rb +1 -1
  19. data/lib/caracal/core/models/paragraph_model.rb +8 -6
  20. data/lib/caracal/core/models/style_model.rb +1 -1
  21. data/lib/caracal/core/models/table_cell_model.rb +3 -3
  22. data/lib/caracal/core/models/table_model.rb +2 -2
  23. data/lib/caracal/core/page_numbers.rb +4 -3
  24. data/lib/caracal/core/page_settings.rb +2 -2
  25. data/lib/caracal/core/relationships.rb +1 -1
  26. data/lib/caracal/core/rules.rb +1 -1
  27. data/lib/caracal/core/styles.rb +1 -1
  28. data/lib/caracal/core/tables.rb +3 -2
  29. data/lib/caracal/core/text.rb +6 -4
  30. data/lib/caracal/document.rb +10 -10
  31. data/lib/caracal/renderers/document_renderer.rb +1 -1
  32. data/lib/caracal/renderers/numbering_renderer.rb +2 -2
  33. data/lib/caracal/utilities.rb +23 -0
  34. data/lib/caracal/version.rb +1 -1
  35. data/spec/lib/caracal/core/models/link_model_spec.rb +6 -0
  36. data/spec/lib/caracal/core/models/list_style_model_spec.rb +15 -29
  37. metadata +3 -2
@@ -37,7 +37,7 @@ module Caracal
37
37
 
38
38
  #============== ATTRIBUTES ==========================
39
39
 
40
- def style(options = {}, &block)
40
+ def style(options={}, &block)
41
41
  model = Caracal::Core::Models::StyleModel.new(options, &block)
42
42
 
43
43
  if model.valid?
@@ -16,8 +16,9 @@ module Caracal
16
16
  # Public Methods
17
17
  #-------------------------------------------------------------
18
18
 
19
- def table(data, options = {}, &block)
20
- options.merge!({ data: data })
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)
@@ -18,8 +18,9 @@ module Caracal
18
18
 
19
19
  #============== PARAGRAPHS ==========================
20
20
 
21
- def p(text = nil, options = {}, &block)
22
- options.merge!({ content: text }) if text
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 |text = nil, options = {}, &block|
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(text, options, &block)
44
+ p(args.first, options, &block)
43
45
  end
44
46
  end
45
47
 
@@ -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.style_line.to_i - 1
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.formatted_restart }
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.style_line }
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
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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
- line 400
12
+ indent 400
13
13
  start 2
14
- restart false
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 eq :left }
27
- it { expect(described_class::DEFAULT_STYLE_LEFT).to eq 720 }
28
- it { expect(described_class::DEFAULT_STYLE_LINE).to eq 360 }
29
- it { expect(described_class::DEFAULT_STYLE_START).to eq 1 }
30
- it { expect(described_class::DEFAULT_STYLE_RESTART).to eq true }
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.style_line).to eq 400 }
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 false }
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(false) }
93
+ before { subject.restart(3) }
108
94
 
109
- it { expect(subject.style_restart).to eq false }
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 '.line' do
124
- before { subject.line(400) }
109
+ describe '.indent' do
110
+ before { subject.indent(400) }
125
111
 
126
- it { expect(subject.style_line).to eq 400 }
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, :line, :start].sort }
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.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-18 00:00:00.000000000 Z
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