caracal 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/caracal/core/models/image_model.rb +6 -1
- data/lib/caracal/core/models/relationship_model.rb +10 -5
- data/lib/caracal/document.rb +3 -1
- data/lib/caracal/renderers/document_renderer.rb +1 -1
- data/lib/caracal/version.rb +1 -1
- data/spec/lib/caracal/core/models/image_model_spec.rb +8 -0
- data/spec/lib/caracal/core/models/relationship_model_spec.rb +18 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd6f4b1d2999578352b19dc9b0a37550421fee95
|
4
|
+
data.tar.gz: f5ece05dd0fb90bea538a8c0cdf8fa9073fd6e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aacd3a282bce1a381f62af7e8b8643f96035ded1d2516cb51459df8071833f010f8080f1628fa48b71cfc0c9f3a29f6c69fe08e30eed2826148ac3a46a996a4
|
7
|
+
data.tar.gz: 6222df0d328b719a19e2cdf2a5139025654ad928b4423c7ad2c2fd07fcb583af928df4528c029db2f7013bb8f0cc403dd2a00100ca6150db9c8612c802e26bc8
|
data/README.md
CHANGED
@@ -304,7 +304,7 @@ end
|
|
304
304
|
|
305
305
|
Fonts are added to the font table file by calling the `font` method and passing the name of the font.
|
306
306
|
|
307
|
-
*At present, Caracal only supports declaring the primary font name
|
307
|
+
*At present, Caracal only supports declaring the primary font name.*
|
308
308
|
|
309
309
|
```ruby
|
310
310
|
docx.font do
|
@@ -514,6 +514,7 @@ Images can be added by using the `img` method. The method accepts several optio
|
|
514
514
|
|
515
515
|
```ruby
|
516
516
|
docx.img image_url('example.png') do
|
517
|
+
data raw_data # sets the file data directly instead of opening the url
|
517
518
|
width 396 # sets the image width. units specified in pixels.
|
518
519
|
height 216 # sets the image height. units specified in pixels.
|
519
520
|
align :right # controls the justification of the image. default is :left.
|
@@ -524,6 +525,11 @@ docx.img image_url('example.png') do
|
|
524
525
|
end
|
525
526
|
```
|
526
527
|
|
528
|
+
*Note: If you provide the image data, you should still supply a URL. I know this
|
529
|
+
is a bit hacky, but it allows the library to key the image more effectively and
|
530
|
+
Caracal needs a file extension to apply to the renamed media file. This seemed
|
531
|
+
the simplest solution to both problems.*
|
532
|
+
|
527
533
|
|
528
534
|
### Tables
|
529
535
|
|
@@ -24,6 +24,7 @@ module Caracal
|
|
24
24
|
|
25
25
|
# accessors
|
26
26
|
attr_reader :image_url
|
27
|
+
attr_reader :image_data
|
27
28
|
attr_reader :image_width
|
28
29
|
attr_reader :image_height
|
29
30
|
attr_reader :image_align
|
@@ -60,6 +61,10 @@ module Caracal
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
64
|
+
def relationship_target
|
65
|
+
image_url || image_data
|
66
|
+
end
|
67
|
+
|
63
68
|
|
64
69
|
#=============== SETTERS ==============================
|
65
70
|
|
@@ -71,7 +76,7 @@ module Caracal
|
|
71
76
|
end
|
72
77
|
|
73
78
|
# strings
|
74
|
-
[:url].each do |m|
|
79
|
+
[:data, :url].each do |m|
|
75
80
|
define_method "#{ m }" do |value|
|
76
81
|
instance_variable_set("@image_#{ m }", value.to_s)
|
77
82
|
end
|
@@ -27,10 +27,11 @@ module Caracal
|
|
27
27
|
|
28
28
|
# accessors
|
29
29
|
attr_reader :relationship_id
|
30
|
+
attr_reader :relationship_key
|
30
31
|
attr_reader :relationship_type
|
31
32
|
attr_reader :relationship_target
|
32
|
-
attr_reader :
|
33
|
-
|
33
|
+
attr_reader :relationship_data
|
34
|
+
|
34
35
|
|
35
36
|
|
36
37
|
#-------------------------------------------------------------
|
@@ -63,13 +64,17 @@ module Caracal
|
|
63
64
|
@relationship_id = value.to_i
|
64
65
|
end
|
65
66
|
|
67
|
+
def type(value)
|
68
|
+
@relationship_type = value.to_s.downcase.to_sym
|
69
|
+
end
|
70
|
+
|
66
71
|
def target(value)
|
67
72
|
@relationship_target = value.to_s
|
68
73
|
@relationship_key = value.to_s.downcase
|
69
74
|
end
|
70
75
|
|
71
|
-
def
|
72
|
-
@
|
76
|
+
def data(value)
|
77
|
+
@relationship_data = value.to_s
|
73
78
|
end
|
74
79
|
|
75
80
|
|
@@ -98,7 +103,7 @@ module Caracal
|
|
98
103
|
private
|
99
104
|
|
100
105
|
def option_keys
|
101
|
-
[:id, :type, :target]
|
106
|
+
[:id, :type, :target, :data]
|
102
107
|
end
|
103
108
|
|
104
109
|
end
|
data/lib/caracal/document.rb
CHANGED
@@ -196,7 +196,9 @@ module Caracal
|
|
196
196
|
def render_media(zip)
|
197
197
|
images = relationships.select { |r| r.relationship_type == :image }
|
198
198
|
images.each do |rel|
|
199
|
-
content =
|
199
|
+
unless content = rel.relationship_data
|
200
|
+
content = open(rel.relationship_target).read
|
201
|
+
end
|
200
202
|
|
201
203
|
zip.put_next_entry("word/#{ rel.formatted_target }")
|
202
204
|
zip.write(content)
|
@@ -96,7 +96,7 @@ module Caracal
|
|
96
96
|
raise Caracal::Errors::NoDefaultStyleError 'Document must declare a default paragraph style.'
|
97
97
|
end
|
98
98
|
|
99
|
-
rel = document.relationship({ target: model.image_url,
|
99
|
+
rel = document.relationship({ type: :image, target: model.image_url, data: model.image_data })
|
100
100
|
rel_id = rel.relationship_id
|
101
101
|
rel_name = rel.formatted_target
|
102
102
|
|
data/lib/caracal/version.rb
CHANGED
@@ -36,6 +36,7 @@ describe Caracal::Core::Models::ImageModel do
|
|
36
36
|
# accessors
|
37
37
|
describe 'accessors' do
|
38
38
|
it { expect(subject.image_url).to eq 'https://www.google.com/images/srpr/logo11w.png' }
|
39
|
+
it { expect(subject.image_data).to eq nil }
|
39
40
|
it { expect(subject.image_width).to eq 250 }
|
40
41
|
it { expect(subject.image_height).to eq 200 }
|
41
42
|
it { expect(subject.image_align).to eq :right }
|
@@ -77,6 +78,13 @@ describe Caracal::Core::Models::ImageModel do
|
|
77
78
|
it { expect(subject.image_url).to eq 'https://www.google.com/images/dummy.png' }
|
78
79
|
end
|
79
80
|
|
81
|
+
# .data
|
82
|
+
describe '.data' do
|
83
|
+
before { subject.data('PNG Data follows here') }
|
84
|
+
|
85
|
+
it { expect(subject.image_data).to eq 'PNG Data follows here' }
|
86
|
+
end
|
87
|
+
|
80
88
|
# .width
|
81
89
|
describe '.width' do
|
82
90
|
before { subject.width(300) }
|
@@ -27,10 +27,11 @@ describe Caracal::Core::Models::RelationshipModel do
|
|
27
27
|
|
28
28
|
# accessors
|
29
29
|
describe 'accessors' do
|
30
|
-
it { expect(subject.relationship_id).to
|
31
|
-
it { expect(subject.
|
30
|
+
it { expect(subject.relationship_id).to eq 3 }
|
31
|
+
it { expect(subject.relationship_key).to eq 'footer.xml' }
|
32
|
+
it { expect(subject.relationship_type).to eq :footer }
|
32
33
|
it { expect(subject.relationship_target).to eq 'footer.xml' }
|
33
|
-
it { expect(subject.
|
34
|
+
it { expect(subject.relationship_data).to eq nil }
|
34
35
|
end
|
35
36
|
|
36
37
|
end
|
@@ -51,6 +52,15 @@ describe Caracal::Core::Models::RelationshipModel do
|
|
51
52
|
it { expect(subject.relationship_id).to eq 3 }
|
52
53
|
end
|
53
54
|
|
55
|
+
# .type
|
56
|
+
describe '.type' do
|
57
|
+
before do
|
58
|
+
subject.type('link')
|
59
|
+
end
|
60
|
+
|
61
|
+
it { expect(subject.relationship_type).to eq :link }
|
62
|
+
end
|
63
|
+
|
54
64
|
# .target
|
55
65
|
describe '.target' do
|
56
66
|
before do
|
@@ -61,13 +71,13 @@ describe Caracal::Core::Models::RelationshipModel do
|
|
61
71
|
it { expect(subject.relationship_key).to eq 'dummy.xml' }
|
62
72
|
end
|
63
73
|
|
64
|
-
# .
|
65
|
-
describe '.
|
74
|
+
# .data
|
75
|
+
describe '.data' do
|
66
76
|
before do
|
67
|
-
subject.
|
77
|
+
subject.data('Dummy data')
|
68
78
|
end
|
69
79
|
|
70
|
-
it { expect(subject.
|
80
|
+
it { expect(subject.relationship_data).to eq 'Dummy data' }
|
71
81
|
end
|
72
82
|
|
73
83
|
|
@@ -173,7 +183,7 @@ describe Caracal::Core::Models::RelationshipModel do
|
|
173
183
|
# .option_keys
|
174
184
|
describe '.option_keys' do
|
175
185
|
let(:actual) { subject.send(:option_keys).sort }
|
176
|
-
let(:expected) { [:id, :type, :target].sort }
|
186
|
+
let(:expected) { [:id, :type, :target, :data].sort }
|
177
187
|
|
178
188
|
it { expect(actual).to eq expected }
|
179
189
|
end
|