caracal 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 718806bf68883db5fcc8368a9494bb3235d6b39f
4
- data.tar.gz: 617abc80e867466e960ca952c4b12a799741470a
3
+ metadata.gz: 3d6531d588b6cb5bb6a5c48941029510fdfce000
4
+ data.tar.gz: b7d7136f8e1dc0b126599e6f14b92aae20a925f4
5
5
  SHA512:
6
- metadata.gz: 1a3f5d8804e51338f20f7167c1c14cc01bd9ed57a7d3765df79d29053fb796a2e7b76ed0896a35e90118cb1d22df59db97ac6299a2e7d042f3d1b1a6231d61b4
7
- data.tar.gz: a3b4ceeb74433b5a34248a3208f6d5a8d803c0d7dd4eda033068b66708e22cf01e9d1839754e89b243edd28032eebff70c4b49f1e43e3e203759f0b8202d4203
6
+ metadata.gz: 125ebdcb4425c9283651a28deb626244eca27ac179889e7d5d93aaa55ef998182cb144727552040786cf73cd4b6eae94524f57466a70b7bc022332aa26b9b2e3
7
+ data.tar.gz: e3b1762168958781a93605fa12591229cfb1c24a0fe300394783da2e83cb4b6347197287a99fbf09d6ed882f8c7fb256f1268a44170d2e789ddb6148ea7520e3
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Caracal
2
2
 
3
- [![Build Status](http://img.shields.io/travis/trade-informatics/caracal.svg?style=flat)](https://travis-ci.org/trade-informatics/caracal)
4
3
  [![Gem Version](http://img.shields.io/gem/v/caracal.svg?style=flat)](https://rubygems.org/gems/caracal)
5
4
 
6
5
 
@@ -334,6 +333,7 @@ Paragraph style classes can be defined using the `style` method. The method acc
334
333
  docx.style do
335
334
  id 'Heading1' # sets the internal identifier for the style.
336
335
  name 'heading 1' # sets the friendly name of the style.
336
+ type 'paragraph' # sets the style type. accepts `paragraph` or `character`
337
337
  font 'Palantino' # sets the font family.
338
338
  color '333333' # sets the text color. accepts hex RGB.
339
339
  size 28 # sets the font size. units in half points.
@@ -363,6 +363,11 @@ Caracal establishes a standard set of default styles for every document. Default
363
363
  * Heading5
364
364
  * Heading6
365
365
 
366
+ Styles are declared as `paragraph` by default. If you need to adjust inline text styles repeatedly, you might
367
+ benefit from defining a `character` style. Paragraph styles affects all text runs within a paragraph; character styles
368
+ are used to style individual runs within a larger text block.
369
+
370
+ One-off inline text styling can also be accomplished by passing the `text` command override arguments (see below).
366
371
 
367
372
 
368
373
  ### Custom Properties
@@ -416,7 +421,7 @@ docx.p do
416
421
  text ' to something awesome', font: 'Courier New', color: '555555', size: 32, bold: true, italic: true, underline: true, bgcolor: 'cccccc'
417
422
  text '.'
418
423
  br
419
- text 'This text follows a line break.'
424
+ text 'This text follows a line break and uses a character style instead of overrides.', style: 'MyCharStyle'
420
425
  page
421
426
  end
422
427
  ```
@@ -715,6 +720,11 @@ Caracal includes [Tilt](https://github.com/rtomayko/tilt) integration to facilit
715
720
  Rails integration can be added via the [Caracal-Rails](https://github.com/trade-informatics/caracal-rails) gem.
716
721
 
717
722
 
723
+ ## Using Variables
724
+
725
+ Lexical scope is a pretty big challenge for Caracal and it often confuses new users. This [closed issue](https://github.com/trade-informatics/caracal/issues/71) covers the discussion both from the user and library persepctive.
726
+
727
+
718
728
  ## Filing an Issue
719
729
 
720
730
  Caracal was written for and tested against Word 2010, 2013, and Office365. It should also open in LibreOffice
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Caracal::VERSION
9
9
  spec.authors = ['Trade Infomatics', 'John Dugan']
10
10
  spec.email = ['jpdugan@gmail.com']
11
- spec.summary = %q{ Fast, professional MSWord writer for Ruby. }
12
- spec.description = %q{ Caracal is a pure Ruby MSWord generation library that produces professional quality Word documents using a simple, HTML-style DSL. }
11
+ spec.summary = %q{ Fast, professional Microsoft Word (docx) writer for Ruby. }
12
+ spec.description = %q{ Caracal is a pure Ruby Microsoft Word generation library that produces professional quality MSWord documents (docx) using a simple, HTML-style DSL. }
13
13
  spec.homepage = 'https://github.com/trade-informatics/caracal'
14
14
  spec.license = 'MIT'
15
15
 
@@ -10,11 +10,12 @@ module Caracal
10
10
  #
11
11
  class StyleModel < BaseModel
12
12
 
13
- #-------------------------------------------------------------
13
+ #--------------------------------------------------
14
14
  # Configuration
15
- #-------------------------------------------------------------
15
+ #--------------------------------------------------
16
16
 
17
17
  # constants
18
+ const_set(:DEFAULT_STYLE_TYPE, 'paragraph')
18
19
  const_set(:DEFAULT_STYLE_COLOR, '333333')
19
20
  const_set(:DEFAULT_STYLE_SIZE, 20)
20
21
  const_set(:DEFAULT_STYLE_BOLD, false)
@@ -31,6 +32,7 @@ module Caracal
31
32
  # accessors
32
33
  attr_reader :style_default
33
34
  attr_reader :style_id
35
+ attr_reader :style_type
34
36
  attr_reader :style_name
35
37
  attr_reader :style_color
36
38
  attr_reader :style_font
@@ -52,6 +54,7 @@ module Caracal
52
54
  # initialization
53
55
  def initialize(options={}, &block)
54
56
  @style_default = false
57
+ @style_type = DEFAULT_STYLE_TYPE
55
58
  @style_base = DEFAULT_STYLE_BASE
56
59
  @style_next = DEFAULT_STYLE_NEXT
57
60
 
@@ -73,11 +76,11 @@ module Caracal
73
76
  end
74
77
 
75
78
 
76
- #-------------------------------------------------------------
77
- # Public Instance Methods
78
- #-------------------------------------------------------------
79
+ #--------------------------------------------------
80
+ # Public Methods
81
+ #--------------------------------------------------
79
82
 
80
- #=============== SETTERS ==============================
83
+ #========== SETTERS ===============================
81
84
 
82
85
  # booleans
83
86
  [:bold, :italic, :underline, :caps].each do |m|
@@ -94,7 +97,7 @@ module Caracal
94
97
  end
95
98
 
96
99
  # strings
97
- [:id, :name, :color, :font].each do |m|
100
+ [:id, :type, :name, :color, :font].each do |m|
98
101
  define_method "#{ m }" do |value|
99
102
  instance_variable_set("@style_#{ m }", value.to_s)
100
103
  end
@@ -107,29 +110,52 @@ module Caracal
107
110
  end
108
111
  end
109
112
 
113
+ # custom
114
+ def type(value)
115
+ allowed = ['character', 'paragraph']
116
+ given = value.to_s.downcase.strip
117
+ @style_type = allowed.include?(given) ? given : DEFAULT_STYLE_TYPE
118
+ end
119
+
110
120
 
111
- #=============== STATE ================================
121
+ #========== STATE =================================
112
122
 
113
123
  def matches?(str)
114
124
  style_id.downcase == str.to_s.downcase
115
125
  end
116
126
 
117
127
 
118
- #=============== VALIDATION ===========================
128
+ #========== VALIDATION ============================
119
129
 
120
130
  def valid?
121
- a = [:id, :name]
131
+ a = [:id, :name, :type]
122
132
  a.map { |m| send("style_#{ m }") }.compact.size == a.size
123
133
  end
124
134
 
125
135
 
126
- #-------------------------------------------------------------
127
- # Private Instance Methods
128
- #-------------------------------------------------------------
136
+ #--------------------------------------------------
137
+ # Private Methods
138
+ #--------------------------------------------------
129
139
  private
130
140
 
131
141
  def option_keys
132
- [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first]
142
+ [ :type,
143
+ :bold,
144
+ :italic,
145
+ :underline,
146
+ :caps,
147
+ :top,
148
+ :bottom,
149
+ :size,
150
+ :line,
151
+ :id,
152
+ :name,
153
+ :color,
154
+ :font,
155
+ :align,
156
+ :indent_left,
157
+ :indent_right,
158
+ :indent_first ]
133
159
  end
134
160
 
135
161
  end
@@ -10,12 +10,13 @@ module Caracal
10
10
  #
11
11
  class TextModel < BaseModel
12
12
 
13
- #-------------------------------------------------------------
13
+ #--------------------------------------------------
14
14
  # Configuration
15
- #-------------------------------------------------------------
15
+ #--------------------------------------------------
16
16
 
17
17
  # accessors
18
18
  attr_reader :text_content
19
+ attr_reader :text_style
19
20
  attr_reader :text_font
20
21
  attr_reader :text_color
21
22
  attr_reader :text_size
@@ -27,15 +28,16 @@ module Caracal
27
28
 
28
29
 
29
30
 
30
- #-------------------------------------------------------------
31
- # Public Instance Methods
32
- #-------------------------------------------------------------
31
+ #--------------------------------------------------
32
+ # Public Methods
33
+ #--------------------------------------------------
33
34
 
34
- #=============== GETTERS ==============================
35
+ #========== GETTERS ===============================
35
36
 
36
37
  # .run_attributes
37
38
  def run_attributes
38
39
  {
40
+ style: text_style,
39
41
  font: text_font,
40
42
  color: text_color,
41
43
  size: text_size,
@@ -48,7 +50,7 @@ module Caracal
48
50
  end
49
51
 
50
52
 
51
- #=============== SETTERS ==============================
53
+ #========== SETTERS ===============================
52
54
 
53
55
  # booleans
54
56
  [:bold, :italic, :underline].each do |m|
@@ -65,7 +67,7 @@ module Caracal
65
67
  end
66
68
 
67
69
  # strings
68
- [:bgcolor, :color, :content, :font].each do |m|
70
+ [:bgcolor, :color, :content, :font, :style].each do |m|
69
71
  define_method "#{ m }" do |value|
70
72
  instance_variable_set("@text_#{ m }", value.to_s)
71
73
  end
@@ -79,7 +81,7 @@ module Caracal
79
81
  end
80
82
 
81
83
 
82
- #=============== VALIDATION ===========================
84
+ #========== VALIDATION ============================
83
85
 
84
86
  def valid?
85
87
  a = [:content]
@@ -87,13 +89,13 @@ module Caracal
87
89
  end
88
90
 
89
91
 
90
- #-------------------------------------------------------------
91
- # Private Instance Methods
92
- #-------------------------------------------------------------
92
+ #--------------------------------------------------
93
+ # Private Methods
94
+ #--------------------------------------------------
93
95
  private
94
96
 
95
97
  def option_keys
96
- [:content, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align]
98
+ [:content, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align]
97
99
  end
98
100
 
99
101
  def method_missing(method, *args, &block)
@@ -8,9 +8,9 @@ module Caracal
8
8
  module Renderers
9
9
  class StylesRenderer < XmlRenderer
10
10
 
11
- #-------------------------------------------------------------
11
+ #----------------------------------------------------
12
12
  # Public Methods
13
- #-------------------------------------------------------------
13
+ #----------------------------------------------------
14
14
 
15
15
  # This method produces the xml required for the `word/styles.xml`
16
16
  # sub-document.
@@ -19,7 +19,7 @@ module Caracal
19
19
  builder = ::Nokogiri::XML::Builder.with(declaration_xml) do |xml|
20
20
  xml['w'].styles root_options do
21
21
 
22
- #============ DEFAULT STYLES ================================
22
+ #========== DEFAULT STYLES ====================
23
23
 
24
24
  unless s = document.default_style
25
25
  raise Caracal::Errors::NoDefaultStyleError 'Document must declare a default paragraph style.'
@@ -62,10 +62,10 @@ module Caracal
62
62
  default_id = s.style_id
63
63
 
64
64
 
65
- #============ PARAGRAPH STYLES ================================
65
+ #========== PARA/CHAR STYLES ==================
66
66
 
67
67
  document.styles.reject { |s| s.style_id == default_id }.each do |s|
68
- xml['w'].style({ 'w:styleId' => s.style_id, 'w:type' => 'paragraph' }) do
68
+ xml['w'].style({ 'w:styleId' => s.style_id, 'w:type' => s.style_type }) do
69
69
  xml['w'].name({ 'w:val' => s.style_name })
70
70
  xml['w'].basedOn({ 'w:val' => s.style_base })
71
71
  xml['w'].next({ 'w:val' => s.style_next })
@@ -90,7 +90,7 @@ module Caracal
90
90
  end
91
91
  end
92
92
 
93
- #============ TABLE STYLES ================================
93
+ #========== TABLE STYLES ======================
94
94
 
95
95
  xml['w'].style({ 'w:styleId' => 'DefaultTable', 'w:type' => 'table' }) do
96
96
  xml['w'].basedOn({ 'w:val' => 'TableNormal' })
@@ -116,9 +116,9 @@ module Caracal
116
116
 
117
117
 
118
118
 
119
- #-------------------------------------------------------------
119
+ #----------------------------------------------------
120
120
  # Private Methods
121
- #-------------------------------------------------------------
121
+ #----------------------------------------------------
122
122
  private
123
123
 
124
124
  def font_options(style)
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -54,7 +54,7 @@ describe Caracal::Core::Models::LinkModel do
54
54
 
55
55
  # .run_attributes
56
56
  describe '.run_attributes' do
57
- let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :top } }
57
+ let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :top } }
58
58
 
59
59
  it { expect(subject.run_attributes).to eq expected }
60
60
  end
@@ -143,7 +143,7 @@ describe Caracal::Core::Models::LinkModel do
143
143
  # .option_keys
144
144
  describe '.option_keys' do
145
145
  let(:actual) { subject.send(:option_keys).sort }
146
- let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align].sort }
146
+ let(:expected) { [:content, :href, :style, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align].sort }
147
147
 
148
148
  it { expect(actual).to eq expected }
149
149
  end
@@ -19,6 +19,7 @@ describe Caracal::Core::Models::StyleModel do
19
19
 
20
20
  # constants
21
21
  describe 'constants' do
22
+ it { expect(described_class::DEFAULT_STYLE_TYPE).to eq 'paragraph' }
22
23
  it { expect(described_class::DEFAULT_STYLE_COLOR).to eq '333333' }
23
24
  it { expect(described_class::DEFAULT_STYLE_SIZE).to eq 20 }
24
25
  it { expect(described_class::DEFAULT_STYLE_BOLD).to eq false }
@@ -38,6 +39,7 @@ describe Caracal::Core::Models::StyleModel do
38
39
  it { expect(subject.style_default).to eq true }
39
40
  it { expect(subject.style_id).to eq 'Normal' }
40
41
  it { expect(subject.style_name).to eq 'normal' }
42
+ it { expect(subject.style_type).to eq 'paragraph' }
41
43
  it { expect(subject.style_color).to eq '333333' }
42
44
  it { expect(subject.style_font).to eq 'Arial' }
43
45
  it { expect(subject.style_size).to eq 20 }
@@ -152,6 +154,20 @@ describe Caracal::Core::Models::StyleModel do
152
154
  it { expect(subject.style_align).to eq :right }
153
155
  end
154
156
 
157
+ # custom
158
+ describe '.type' do
159
+ describe 'when valid' do
160
+ before { subject.type 'character'}
161
+
162
+ it { expect(subject.style_type).to eq 'character' }
163
+ end
164
+ describe 'when invalid' do
165
+ before { subject.type 'bogus'}
166
+
167
+ it { expect(subject.style_type).to eq 'paragraph' }
168
+ end
169
+ end
170
+
155
171
 
156
172
  #=================== STATE ===============================
157
173
 
@@ -199,7 +215,7 @@ describe Caracal::Core::Models::StyleModel do
199
215
  # .option_keys
200
216
  describe '.option_keys' do
201
217
  let(:actual) { subject.send(:option_keys).sort }
202
- let(:expected) { [:bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first].sort }
218
+ let(:expected) { [:type, :bold, :italic, :underline, :caps, :top, :bottom, :size, :line, :id, :name, :color, :font, :align, :indent_left, :indent_right, :indent_first].sort }
203
219
 
204
220
  it { expect(actual).to eq expected }
205
221
  end
@@ -47,7 +47,7 @@ describe Caracal::Core::Models::TextModel do
47
47
 
48
48
  # .run_attributes
49
49
  describe '.run_attributes' do
50
- let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :subscript } }
50
+ let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :subscript } }
51
51
 
52
52
  it { expect(subject.run_attributes).to eq expected }
53
53
  end
@@ -137,7 +137,7 @@ describe Caracal::Core::Models::TextModel do
137
137
  # .option_keys
138
138
  describe '.option_keys' do
139
139
  let(:actual) { subject.send(:option_keys).sort }
140
- let(:expected) { [:bgcolor, :bold, :color, :content, :font, :italic, :size, :underline, :vertical_align].sort }
140
+ let(:expected) { [:bgcolor, :bold, :color, :content, :font, :italic, :size, :style, :underline, :vertical_align].sort }
141
141
 
142
142
  it { expect(actual).to eq expected }
143
143
  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.1.0
4
+ version: 1.1.1
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: 2017-08-17 00:00:00.000000000 Z
12
+ date: 2018-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -95,8 +95,8 @@ dependencies:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '3.0'
98
- description: " Caracal is a pure Ruby MSWord generation library that produces professional
99
- quality Word documents using a simple, HTML-style DSL. "
98
+ description: " Caracal is a pure Ruby Microsoft Word generation library that produces
99
+ professional quality MSWord documents (docx) using a simple, HTML-style DSL. "
100
100
  email:
101
101
  - jpdugan@gmail.com
102
102
  executables: []
@@ -231,10 +231,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  version: '0'
232
232
  requirements: []
233
233
  rubyforge_project:
234
- rubygems_version: 2.6.12
234
+ rubygems_version: 2.6.14
235
235
  signing_key:
236
236
  specification_version: 4
237
- summary: Fast, professional MSWord writer for Ruby.
237
+ summary: Fast, professional Microsoft Word (docx) writer for Ruby.
238
238
  test_files:
239
239
  - spec/lib/caracal/core/file_name_spec.rb
240
240
  - spec/lib/caracal/core/fonts_spec.rb