caracal 1.0.5 → 1.0.6

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: 491450be9349f7528fa95e04b379b72f4807d395
4
- data.tar.gz: 823708c706f984673a8f42c64d73e5d4fdc9be87
3
+ metadata.gz: 182b527fbc16b0c6a5ae6c5cc2b77c307dc65f7c
4
+ data.tar.gz: ac8bd74712cfc75f7c9ac786d33de2b6be4ed3ac
5
5
  SHA512:
6
- metadata.gz: 575e505a4c78d7ffc05b87587d12fa94c436ce53c9d466762a84fa9fdeaca974843cec777698ca2cd1bf1ddea1c0727637275f6d3dcc0b3738a7226e29b93f30
7
- data.tar.gz: a91c03e2d61d31db942c1c086b462e2528694533055616bb1ff9f30f0f2026c5a4c4b66262c308830c33abb47878dd97f42c9ba0c4994853edded97c1e2fd855
6
+ metadata.gz: a1e01da077541a289ff4b30e7dc0d6793f7cb7def0ddd8cca6b0480cdc80941fd52c04155d0f41d8572778d6425d09e765574b64f632d59212c7c36a7cac9411
7
+ data.tar.gz: 187ed9bfa2d8d5f182e7b4223506d69901756d8458c49868306d2033aee7c29ff49a6c4035ca12290ffd2ea965e767e3dc10e47a80d26c2441fec8aa49b04839
@@ -1,5 +1,11 @@
1
1
  #### v1.0.5
2
2
 
3
+ * Bug Fixes
4
+ * Changed Paragraph and Table Cell Models slightly to allow syntax flexibility with respect to options (@jdugan).
5
+
6
+
7
+ #### v1.0.5
8
+
3
9
  * Enhancements
4
10
  * Added vertical alignment (@ykonovets).
5
11
 
@@ -30,7 +30,7 @@ module Caracal
30
30
  # initialization
31
31
  def initialize(options={}, &block)
32
32
  content = options.delete(:content) { "" }
33
- text content, options.dup
33
+ text content, options.dup, &block
34
34
  super options, &block
35
35
  end
36
36
 
@@ -5,23 +5,23 @@ require 'caracal/core/models/margin_model'
5
5
  module Caracal
6
6
  module Core
7
7
  module Models
8
-
9
- # This class handles block options passed to tables via their data
8
+
9
+ # This class handles block options passed to tables via their data
10
10
  # collections.
11
11
  #
12
12
  class TableCellModel < BaseModel
13
-
13
+
14
14
  #-------------------------------------------------------------
15
15
  # Configuration
16
16
  #-------------------------------------------------------------
17
-
17
+
18
18
  # constants
19
19
  const_set(:DEFAULT_CELL_BACKGROUND, 'ffffff')
20
20
  const_set(:DEFAULT_CELL_MARGINS, Caracal::Core::Models::MarginModel.new({ top: 100, bottom: 100, left: 100, right: 100 }))
21
21
  const_set(:DEFAULT_CELL_VERTICAL_ALIGN, :top)
22
22
 
23
23
  # accessors
24
- attr_reader :cell_background
24
+ attr_reader :cell_background
25
25
  attr_reader :cell_width
26
26
  attr_reader :cell_margins
27
27
  attr_reader :cell_vertical_align
@@ -33,29 +33,29 @@ module Caracal
33
33
  @cell_vertical_align = DEFAULT_CELL_VERTICAL_ALIGN
34
34
 
35
35
  if content = options.delete(:content)
36
- p content, options.dup
36
+ p content, options.dup, &block
37
37
  end
38
-
38
+
39
39
  super options, &block
40
40
  end
41
-
42
-
41
+
42
+
43
43
  #-------------------------------------------------------------
44
44
  # Public Methods
45
45
  #-------------------------------------------------------------
46
-
46
+
47
47
  #=============== DATA ACCESSORS =======================
48
-
48
+
49
49
  def contents
50
50
  @contents ||= []
51
51
  end
52
-
53
-
52
+
53
+
54
54
  #=============== STYLES ===============================
55
-
56
- # This method allows styles to be applied to this cell
55
+
56
+ # This method allows styles to be applied to this cell
57
57
  # from the table level. It attempts to add the style
58
- # first to the instance, and then to any sub-models that
58
+ # first to the instance, and then to any sub-models that
59
59
  # respond to the method.
60
60
  #
61
61
  # In all cases, invalid options will simply be ignored.
@@ -64,21 +64,21 @@ module Caracal
64
64
  # make dup of options so we don't
65
65
  # harm args sent to sibling cells
66
66
  options = opts.dup
67
-
67
+
68
68
  # first, try apply to self
69
69
  options.each do |(k,v)|
70
70
  send(k, v) if respond_to?(k)
71
71
  end
72
-
72
+
73
73
  # prevent top-level attrs from trickling down
74
- options.delete_if { |(k,v)| option_keys.include?(k) }
75
-
74
+ options.delete_if { |(k,v)| option_keys.include?(k) }
75
+
76
76
  # then, try apply to contents
77
77
  contents.each do |model|
78
78
  options.each do |k,v|
79
79
  model.send(k, v) if model.respond_to?(k)
80
80
  end
81
-
81
+
82
82
  # finally, apply to runs. options do trickle down
83
83
  # because paragraph-level styles don't seem to
84
84
  # affect runs within tables. weirdsies.
@@ -91,46 +91,46 @@ module Caracal
91
91
  end
92
92
  end
93
93
  end
94
-
94
+
95
95
  def calculate_width(default_width)
96
96
  width(default_width) unless cell_width.to_i > 0
97
-
97
+
98
98
  container_width = cell_width - cell_margin_left - cell_margin_right
99
-
99
+
100
100
  contents.each do |model|
101
101
  if model.respond_to?(:calculate_width)
102
102
  model.calculate_width(container_width) # will always be a TableModel
103
103
  end
104
104
  end
105
105
  end
106
-
107
-
106
+
107
+
108
108
  #=============== GETTERS ==============================
109
-
109
+
110
110
  # margin attrs
111
111
  [:top, :bottom, :left, :right].each do |m|
112
112
  define_method "cell_margin_#{ m }" do
113
113
  v = cell_margins ? cell_margins.send("margin_#{ m }") : 0
114
114
  end
115
115
  end
116
-
117
-
116
+
117
+
118
118
  #=============== SETTERS ==============================
119
-
119
+
120
120
  # integers
121
121
  [:width].each do |m|
122
122
  define_method "#{ m }" do |value|
123
123
  instance_variable_set("@cell_#{ m }", value.to_i)
124
124
  end
125
125
  end
126
-
126
+
127
127
  # models
128
128
  [:margins].each do |m|
129
129
  define_method "#{ m }" do |options = {}, &block|
130
130
  instance_variable_set("@cell_#{ m }", Caracal::Core::Models::MarginModel.new(options, &block))
131
131
  end
132
132
  end
133
-
133
+
134
134
  # strings
135
135
  [:background].each do |m|
136
136
  define_method "#{ m }" do |value|
@@ -147,23 +147,23 @@ module Caracal
147
147
 
148
148
 
149
149
  #=============== VALIDATION ===========================
150
-
150
+
151
151
  def valid?
152
152
  contents.size > 0
153
153
  end
154
-
155
-
154
+
155
+
156
156
  #-------------------------------------------------------------
157
157
  # Private Instance Methods
158
158
  #-------------------------------------------------------------
159
159
  private
160
-
160
+
161
161
  def option_keys
162
162
  [:background, :margins, :width, :vertical_align]
163
163
  end
164
-
164
+
165
165
  end
166
-
166
+
167
167
  end
168
168
  end
169
169
  end
@@ -96,6 +96,17 @@ module Caracal
96
96
  [:content, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align]
97
97
  end
98
98
 
99
+ def method_missing(method, *args, &block)
100
+ # I'm on the fence with respect to this implementation. We're ignoring
101
+ # :method_missing errors to allow syntax flexibility for paragraph-type
102
+ # models. The issue is the syntax format of those models--the way we pass
103
+ # the content value as a special argument--coupled with the model's
104
+ # ability to accept nested instructions.
105
+ #
106
+ # By ignoring method missing errors here, we can pass the entire paragraph
107
+ # block in the initial, built-in call to :text.
108
+ end
109
+
99
110
  end
100
111
 
101
112
  end
@@ -1,3 +1,3 @@
1
1
  module Caracal
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'
3
3
  end
@@ -3,15 +3,16 @@ require 'spec_helper'
3
3
  describe Caracal::Core::Models::LinkModel do
4
4
  subject do
5
5
  described_class.new do
6
- content 'Link Text'
7
- href 'http://www.google.com'
8
- font 'Courier New'
9
- color '666666'
10
- size 20
11
- bold false
12
- italic false
13
- underline true
14
- bgcolor 'cccccc'
6
+ content 'Link Text'
7
+ href 'http://www.google.com'
8
+ font 'Courier New'
9
+ color '666666'
10
+ size 20
11
+ bold false
12
+ italic false
13
+ underline true
14
+ bgcolor 'cccccc'
15
+ vertical_align :top
15
16
  end
16
17
  end
17
18
 
@@ -53,7 +54,7 @@ describe Caracal::Core::Models::LinkModel do
53
54
 
54
55
  # .run_attributes
55
56
  describe '.run_attributes' do
56
- let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc' } }
57
+ let(:expected) { { font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', vertical_align: :top } }
57
58
 
58
59
  it { expect(subject.run_attributes).to eq expected }
59
60
  end
@@ -142,7 +143,7 @@ describe Caracal::Core::Models::LinkModel do
142
143
  # .option_keys
143
144
  describe '.option_keys' do
144
145
  let(:actual) { subject.send(:option_keys).sort }
145
- let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline, :bgcolor].sort }
146
+ let(:expected) { [:content, :href, :font, :color, :size, :bold, :italic, :underline, :bgcolor, :vertical_align].sort }
146
147
 
147
148
  it { expect(actual).to eq expected }
148
149
  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.5
4
+ version: 1.0.6
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-05-31 00:00:00.000000000 Z
12
+ date: 2016-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri