caracal 1.0.7 → 1.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aeb4bbbf23d57b58d105f3cb14e93721476dccb
4
- data.tar.gz: 24a30fd6c194b1ce00d29277a62937c956307494
3
+ metadata.gz: b18e4eda1bbb02a4efb9191d1c65d99701e54800
4
+ data.tar.gz: 5720059a89acdabe4f278fff2abb6c08c40ffb99
5
5
  SHA512:
6
- metadata.gz: 22d42de924ae632ff309b1c74254331d34ab37502a8115960964277657c5b655342439bac025f7ac3b9465126ee3ac1214bc2d8ba6b81f06576eed6d7ffd7feb
7
- data.tar.gz: 75e87e2efd8f69ed0803316c5f84fb56812fb768457b6ac4a6d91ce0a16ea6e673f84ba42836314ae8fe3c4253e9998050d51a1bb022a934f9fa0fc03475d53e
6
+ metadata.gz: 707f70ec9a572317a0bef6d04cb44c7247b9e7d7b1d5baa7d8176eb4297eedfb5a405d8aeeebf7af29827b98955e5582fadb77bdafadce38fa399c15b65d5888
7
+ data.tar.gz: ef395004b3eef312499f6ea2db4465ec50409f0a75580289d41cd10a98ccec0d0e6942bd651b4059387560dcbf4254488e0dadcdf4338836a2cf204c301e3adc
data/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
- #### v1.0.5
1
+ #### v1.0.8
2
+
3
+ * Enhancements
4
+ * Added indentation controls to paragraph commands (@avolochnev).
5
+
6
+
7
+ #### v1.0.7
8
+
9
+ * Enhancements
10
+ * Added an :orientation option to :page_size so print jobs work as expected (@jdugan h/t @swedishpotato).
11
+
12
+
13
+ #### v1.0.6
2
14
 
3
15
  * Bug Fixes
4
16
  * Changed Paragraph and Table Cell Models slightly to allow syntax flexibility with respect to options (@jdugan).
data/README.md CHANGED
@@ -331,19 +331,22 @@ Paragraph style classes can be defined using the `style` method. The method acc
331
331
 
332
332
  ```ruby
333
333
  docx.style do
334
- id 'Heading1' # sets the internal identifier for the style.
335
- name 'heading 1' # sets the friendly name of the style.
336
- font 'Palantino' # sets the font family.
337
- color '333333' # sets the text color. accepts hex RGB.
338
- size 28 # sets the font size. units in half points.
339
- bold false # sets the font weight.
340
- italic false # sets the font style.
341
- underline false # sets whether or not to underline the text.
342
- caps false # sets whether or not text should be rendered in all capital letters.
343
- align :left # sets the alignment. accepts :left, :center, :right, and :both.
344
- line 360 # sets the line height. units in twips.
345
- top 100 # sets the spacing above the paragraph. units in twips.
346
- bottom 0 # sets the spacing below the paragraph. units in twips.
334
+ id 'Heading1' # sets the internal identifier for the style.
335
+ name 'heading 1' # sets the friendly name of the style.
336
+ font 'Palantino' # sets the font family.
337
+ color '333333' # sets the text color. accepts hex RGB.
338
+ size 28 # sets the font size. units in half points.
339
+ bold false # sets the font weight.
340
+ italic false # sets the font style.
341
+ underline false # sets whether or not to underline the text.
342
+ caps false # sets whether or not text should be rendered in all capital letters.
343
+ align :left # sets the alignment. accepts :left, :center, :right, and :both.
344
+ line 360 # sets the line height. units in twips.
345
+ top 100 # sets the spacing above the paragraph. units in twips.
346
+ bottom 0 # sets the spacing below the paragraph. units in twips.
347
+ indent_left 360 # sets the left indent. units in twips.
348
+ indent_right 360 # sets the rights indent. units in twips.
349
+ indent_first 720 # sets the first line indent. units in twips.
347
350
  end
348
351
  ```
349
352
 
@@ -631,7 +634,7 @@ end
631
634
  If your table contains more complex data (multiple paragraphs, images, lists, etc.), you will probably want to instantiate your `TableCellModel` instances directly. With the exception of page breaks, table cells can contain anything the document can contain, including another table.
632
635
 
633
636
  ```ruby
634
- c1 = Caracal::Core::Models:TableCellModel.new do
637
+ c1 = Caracal::Core::Models::TableCellModel.new do
635
638
  background 'cccccc' # sets the background color. defaults to 'ffffff'.
636
639
  margins do
637
640
  top # sets the top margin. defaults to 0. units in twips.
@@ -45,6 +45,9 @@ module Caracal
45
45
  attr_reader :style_line
46
46
  attr_reader :style_base
47
47
  attr_reader :style_next
48
+ attr_reader :style_indent_left
49
+ attr_reader :style_indent_right
50
+ attr_reader :style_indent_first
48
51
 
49
52
  # initialization
50
53
  def initialize(options={}, &block)
@@ -84,7 +87,7 @@ module Caracal
84
87
  end
85
88
 
86
89
  # integers
87
- [:bottom, :size, :line, :top].each do |m|
90
+ [:bottom, :size, :line, :top, :indent_left, :indent_right, :indent_first].each do |m|
88
91
  define_method "#{ m }" do |value|
89
92
  instance_variable_set("@style_#{ m }", value.to_i)
90
93
  end
@@ -126,7 +129,7 @@ module Caracal
126
129
  private
127
130
 
128
131
  def option_keys
129
- [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align]
132
+ [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first]
130
133
  end
131
134
 
132
135
  end
@@ -45,7 +45,7 @@ module Caracal
45
45
  xml.send 'w:keepLines', { 'w:val' => '0' }
46
46
  xml.send 'w:widowControl', { 'w:val' => '1' }
47
47
  xml.send 'w:spacing', spacing_options(s, true)
48
- xml.send 'w:ind', { 'w:left' => '0', 'w:firstLine' => '0', 'w:right' => '0' }
48
+ xml.send 'w:ind', indentation_options(s, true)
49
49
  xml.send 'w:jc', { 'w:val' => s.style_align.to_s }
50
50
  end
51
51
  end
@@ -76,6 +76,7 @@ module Caracal
76
76
  xml.send 'w:spacing', spacing_options(s) unless spacing_options(s).nil?
77
77
  xml.send 'w:contextualSpacing', { 'w:val' => '1' }
78
78
  xml.send 'w:jc', { 'w:val' => s.style_align.to_s } unless s.style_align.nil?
79
+ xml.send 'w:ind', indentation_options(s) unless indentation_options(s).nil?
79
80
  end
80
81
  xml.send 'w:rPr' do
81
82
  xml.send 'w:rFonts', font_options(s) unless s.style_font.nil?
@@ -125,18 +126,16 @@ module Caracal
125
126
  { 'w:cs' => name, 'w:hAnsi' => name, 'w:eastAsia' => name, 'w:ascii' => name }
126
127
  end
127
128
 
128
- def spacing_options(style, default=false)
129
- top = (default) ? style.style_top.to_i : style.style_top
130
- bottom = (default) ? style.style_bottom.to_i : style.style_bottom
131
- line = style.style_line
132
-
129
+ def indentation_options(style, default=false)
130
+ left = (default) ? style.style_indent_left.to_i : style.style_indent_left
131
+ right = (default) ? style.style_indent_right.to_i : style.style_indent_right
132
+ first = (default) ? style.style_indent_first.to_i : style.style_indent_first
133
133
  options = nil
134
- if [top, bottom, line].compact.size > 0
135
- options = {}
136
- options['w:lineRule'] = 'auto'
137
- options['w:before'] = top unless top.nil?
138
- options['w:after'] = bottom unless bottom.nil?
139
- options['w:line'] = line unless line.nil?
134
+ if [left, right, first].compact.size > 0
135
+ options = {}
136
+ options['w:left'] = left unless left.nil?
137
+ options['w:right'] = right unless right.nil?
138
+ options['w:firstLine'] = first unless first.nil?
140
139
  end
141
140
  options
142
141
  end
@@ -161,6 +160,22 @@ module Caracal
161
160
  }
162
161
  end
163
162
 
163
+ def spacing_options(style, default=false)
164
+ top = (default) ? style.style_top.to_i : style.style_top
165
+ bottom = (default) ? style.style_bottom.to_i : style.style_bottom
166
+ line = style.style_line
167
+
168
+ options = nil
169
+ if [top, bottom, line].compact.size > 0
170
+ options = {}
171
+ options['w:lineRule'] = 'auto'
172
+ options['w:before'] = top unless top.nil?
173
+ options['w:after'] = bottom unless bottom.nil?
174
+ options['w:line'] = line unless line.nil?
175
+ end
176
+ options
177
+ end
178
+
164
179
  end
165
180
  end
166
181
  end
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '1.0.7'
2
+ VERSION = '1.0.8'
3
3
  end
@@ -107,6 +107,21 @@ describe Caracal::Core::Models::StyleModel do
107
107
 
108
108
  it { expect(subject.style_top).to eq 100 }
109
109
  end
110
+ describe '.indent_left' do
111
+ before { subject.indent_left(1440) }
112
+
113
+ it { expect(subject.style_indent_left).to eq 1440 }
114
+ end
115
+ describe '.indent_right' do
116
+ before { subject.indent_right(720) }
117
+
118
+ it { expect(subject.style_indent_right).to eq 720 }
119
+ end
120
+ describe '.indent_right' do
121
+ before { subject.indent_first(567) }
122
+
123
+ it { expect(subject.style_indent_first).to eq 567 }
124
+ end
110
125
 
111
126
  # strings
112
127
  describe '.id' do
@@ -184,7 +199,7 @@ describe Caracal::Core::Models::StyleModel do
184
199
  # .option_keys
185
200
  describe '.option_keys' do
186
201
  let(:actual) { subject.send(:option_keys).sort }
187
- let(:expected) { [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align].sort }
202
+ let(:expected) { [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first].sort }
188
203
 
189
204
  it { expect(actual).to eq expected }
190
205
  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: 1.0.7
4
+ version: 1.0.8
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: 2016-09-10 00:00:00.000000000 Z
12
+ date: 2016-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri