prawn-rails-forms 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +194 -3
- data/lib/prawn-rails-forms.rb +33 -38
- data/lib/prawn-rails-forms/version.rb +1 -1
- data/test-app/Gemfile +11 -0
- data/test-app/Gemfile.lock +147 -0
- data/test-app/app/controllers/application_controller.rb +3 -0
- data/test-app/app/controllers/pdf_controller.rb +7 -0
- data/test-app/app/views/pdf/static.pdf.prawn +108 -0
- data/test-app/bin/bundle +3 -0
- data/test-app/bin/rails +9 -0
- data/test-app/bin/spring +17 -0
- data/test-app/config.ru +3 -0
- data/test-app/config/application.rb +14 -0
- data/test-app/config/boot.rb +3 -0
- data/test-app/config/environment.rb +2 -0
- data/test-app/config/environments/development.rb +21 -0
- data/test-app/config/initializers/prawn_rails.rb +6 -0
- data/test-app/config/puma.rb +5 -0
- data/test-app/config/routes.rb +3 -0
- data/test-app/config/secrets.yml +2 -0
- data/test-app/config/spring.rb +6 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8869d63d7f64526cc13de42144bed82256a9c60
|
4
|
+
data.tar.gz: 3fee050421b66072049e5e1c9666976238a329eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 571595c80d390dee11e264da5f2d1d105ae54d533585428dacc9ae1f5faad2c948152dcc82f4e8cd6c713bdb080976773d49e4e7b5a049a37019a8718782fbde
|
7
|
+
data.tar.gz: 25b200c7ab1d71120fb8f8f80f9fe8af27e202f1aecb3725c608682982b1049f63fec319530320c1852b342eb4d197a0ef6030684925be3d9465574983005e19
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# PrawnRailsForms
|
2
2
|
|
3
|
-
|
3
|
+
A simple extension to PrawnRails, allowing you to specify dynamically filled forms in terms of their layout on the page.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,11 +18,202 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install prawn-rails-forms
|
20
20
|
|
21
|
-
|
21
|
+
Then, anywhere in the `config/initializers/prawn_rails.rb` file specified by [the PrawnRails docs](https://github.com/cortiz/prawn-rails), add:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
include PrawnRailsForms
|
25
|
+
```
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
In a PrawnRails `.pdf.prawn` document, with a `pdf` block variable, e.g.:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
prawn_document do |pdf|
|
33
|
+
# Your code goes here...
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Fields are laid out in rows, subdivided into an arbitrary number of units.
|
38
|
+
Rows must have a height specified, in points.
|
39
|
+
Fields cannot be created outside of rows.
|
40
|
+
For instance, say we want to create the following row of a form:
|
41
|
+
|
42
|
+
![1](https://cloud.githubusercontent.com/assets/3988134/26561634/e6028f68-448d-11e7-800a-93e3aca2db6a.png)
|
43
|
+
|
44
|
+
Then this row will be subdivided into 8 units. We specify this with:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
pdf.field_row height: 25, units: 8 do |row|
|
48
|
+
# Specify fields...
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
Then we specify the fields in terms of how many units they take up, what their name should be, and what variable should be dynamically filled into this space.
|
53
|
+
|
54
|
+
For example, the first field in the image above would be:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
pdf.field_row height: 25, units: 8 do |row|
|
58
|
+
row.text_field width: 4, field: 'Operator', value: @incident.driver.name
|
59
|
+
# etc.
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Note that the `@incident.driver.name` is arbitrary — this would be whatever code you need to fill the value of this field.
|
64
|
+
|
65
|
+
### Text fields
|
66
|
+
|
67
|
+
Text fields must have a `field` and `value` attribute.
|
68
|
+
|
69
|
+
The value can be a string, or an array of strings (which will be newline-separated in the output).
|
70
|
+
|
71
|
+
If the text overflows, it will be truncated (rather than doing any damage to subsequent fields or rows.)
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit
|
75
|
+
```
|
76
|
+
|
77
|
+
You can optionally specify the `width`, in terms of the units of the row. (Default is 1 unit.)
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
81
|
+
width: 3
|
82
|
+
```
|
83
|
+
|
84
|
+
You can optionally specify the `height` of the field, in points. It's not recommended for this to be more than the row height.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
88
|
+
height: 30
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Additional options
|
92
|
+
|
93
|
+
You can change the text size with a `size` attribute. Default is 10pt.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
97
|
+
options: { size: 8 } # for large fruits
|
98
|
+
```
|
99
|
+
|
100
|
+
If there is a certain condition which you want to be true in order to display the value:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
104
|
+
options: { if: @user.likes_fruit? }
|
105
|
+
```
|
106
|
+
|
107
|
+
Or a condition which you want to be false:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
111
|
+
options: { unless: @user.hates_fruit? }
|
112
|
+
```
|
113
|
+
|
114
|
+
You can change how you want the text to be aligned horizontally. Default is center.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
118
|
+
options: { align: :left }
|
119
|
+
```
|
120
|
+
|
121
|
+
You can also change the vertical alignment. Default is bottom.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
125
|
+
options: { valign: :center }
|
126
|
+
```
|
127
|
+
|
128
|
+
And of course, you can combine any or all of the above:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
row.text_field field: 'Favorite fruit', value: @user.favorite_fruit,
|
132
|
+
width: 3, height: 30,
|
133
|
+
options: { align: :left, valign: :center, size: 8,
|
134
|
+
if: @user.likes_fruit?, unless: @user.hates_fruit? }
|
135
|
+
```
|
136
|
+
|
137
|
+
### Check box fields
|
138
|
+
|
139
|
+
For selecting one of a group of options (the equivalent of an HTML select tag), you can have check box fields, e.g.:
|
140
|
+
|
141
|
+
![2](https://cloud.githubusercontent.com/assets/3988134/26561635/e603f628-448d-11e7-8af8-6ced6a729cd5.png)
|
142
|
+
|
143
|
+
Check box fields must have `field`, `options`, and `checked` attributes specified.
|
144
|
+
|
145
|
+
`field` is the name of the field.
|
146
|
+
|
147
|
+
`options` is the Array of options which will be shown.
|
148
|
+
|
149
|
+
`checked` is the Array, of equal size to `options`, of booleans specifying whether each option should be checked.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
vegetables = %w[celery asparagus yams]
|
153
|
+
row.check_box_field field: 'Favorite vegetables',
|
154
|
+
options: vegetables,
|
155
|
+
checked: vegetables.map{ |v| @user.likes? v }
|
156
|
+
```
|
157
|
+
|
158
|
+
You can optionally specify the width of the field, in the subunits into which the row is divided:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
row.check_box_field field: 'Favorite vegetables'
|
162
|
+
options: vegetables,
|
163
|
+
checked: vegetables.map{ |v| @user.likes? v },
|
164
|
+
width: 4
|
165
|
+
```
|
166
|
+
|
167
|
+
Or the height, in points. Default is the row height.
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
row.check_box_field field: 'Favorite vegetables'
|
171
|
+
options: vegetables,
|
172
|
+
checked: vegetables.map{ |v| @user.likes? v },
|
173
|
+
height: 60
|
174
|
+
```
|
175
|
+
|
176
|
+
In the event that you would like multiple columns of checkboxes, you can specify the number of checkboxes which should occur in a column (default is 3):
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
row.check_box_field field: 'Favorite vegetables',
|
180
|
+
options: vegetables,
|
181
|
+
checked: vegetables.map{ |v| @user.likes? v },
|
182
|
+
per_column: 5
|
183
|
+
```
|
184
|
+
|
185
|
+
### Splitting rows into sub-rows
|
186
|
+
|
187
|
+
Say we want the following layout:
|
188
|
+
|
189
|
+
![3](https://cloud.githubusercontent.com/assets/3988134/26561633/e601874e-448d-11e7-8951-2f8627285a63.png)
|
190
|
+
|
191
|
+
The easiest way to apprach this is to complete the top line (the fields which all touch the top of the row), and then to go back and do the first field which does not.
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
pdf.field_row height: 75, units: 8 do |row|
|
195
|
+
# ...
|
196
|
+
row.at_height 25 do
|
197
|
+
row.text_field # ...
|
198
|
+
end
|
199
|
+
end
|
200
|
+
```
|
201
|
+
|
202
|
+
If you want to jump midway through a line, then you can optionally specify the unit you would like to jump to:
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
row.at_height 25, unit: 5 do
|
206
|
+
# ...
|
207
|
+
end
|
208
|
+
```
|
209
|
+
|
210
|
+
This would start a new field 25 points from the top, halfway through the row.
|
211
|
+
|
212
|
+
## Development
|
213
|
+
|
214
|
+
There's a test rails app in `test-app/`. Bundle and boot it up, and the root page should show you a fairly self-explanatory static PDF.
|
215
|
+
|
216
|
+
New functionality would ideally be coupled with new 'test cases' in `static.pdf.prawn`.
|
26
217
|
|
27
218
|
## Contributing
|
28
219
|
|
data/lib/prawn-rails-forms.rb
CHANGED
@@ -1,15 +1,37 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'prawn-rails-forms/version'
|
3
2
|
require 'prawn-rails'
|
4
3
|
|
5
4
|
module PrawnRailsForms
|
6
|
-
class
|
7
|
-
attr_accessor :height, :units, :x, :y, :unit_width
|
8
|
-
|
9
|
-
def initialize(height, units, x, y, unit_width)
|
10
|
-
@height, @units, @x, @y, @unit_width =
|
11
|
-
height, units, x, y, unit_width
|
5
|
+
class FieldRow
|
6
|
+
attr_accessor :document, :height, :units, :x, :y, :unit_width
|
7
|
+
|
8
|
+
def initialize(document,height, units, x, y, unit_width)
|
9
|
+
@document, @height, @units, @x, @y, @unit_width =
|
10
|
+
document, height, units, x, y, unit_width
|
11
|
+
end
|
12
|
+
|
13
|
+
def at_height(height, options = {}, &block)
|
14
|
+
@y -= height
|
15
|
+
if options[:unit].present?
|
16
|
+
@x = options[:unit] * @unit_width
|
17
|
+
end
|
18
|
+
block.call
|
19
|
+
@y += height
|
20
|
+
end
|
21
|
+
|
22
|
+
def text_field(**args)
|
23
|
+
start, width, height = field_attributes args
|
24
|
+
@document.send :make_text_field, start, width, height, **args.except(:width, :height)
|
25
|
+
@x += width
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_box_field(**args)
|
29
|
+
start, width, height = field_attributes args
|
30
|
+
@document.send :make_check_box_field, start, width, height, **args.except(:width, :height)
|
31
|
+
@x += width
|
12
32
|
end
|
33
|
+
|
34
|
+
private
|
13
35
|
|
14
36
|
def field_attributes(args)
|
15
37
|
start = [@x, @y]
|
@@ -20,33 +42,13 @@ module PrawnRailsForms
|
|
20
42
|
end
|
21
43
|
|
22
44
|
class PrawnRails::Document
|
23
|
-
attr_accessor :row_helper
|
24
45
|
|
25
46
|
def field_row(height:, units:, &block)
|
26
|
-
|
27
|
-
|
28
|
-
block.call
|
29
|
-
@row_helper = nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def at_row_height(height, options = {}, &block)
|
33
|
-
if @row_helper.present?
|
34
|
-
@row_helper.y -= height
|
35
|
-
if options[:unit].present?
|
36
|
-
@row_helper.x = options[:unit] * @row_helper.unit_width
|
37
|
-
end
|
38
|
-
block.call
|
39
|
-
@row_helper.y += height
|
40
|
-
else raise ArgumentError, 'Must be within a field row'
|
41
|
-
end
|
47
|
+
unit_width = bounds.width / units
|
48
|
+
yield FieldRow.new(self, height, units, 0, cursor, unit_width)
|
42
49
|
end
|
43
50
|
|
44
|
-
|
45
|
-
raise ArgumentError, 'Must be within a field row' unless @row_helper.present?
|
46
|
-
start, width, height = @row_helper.field_attributes args
|
47
|
-
make_text_field start, width, height, **args.except(:width, :height)
|
48
|
-
@row_helper.x += width if @row_helper.present?
|
49
|
-
end
|
51
|
+
private
|
50
52
|
|
51
53
|
def make_text_field(start, width, height, field:, value:, options: {})
|
52
54
|
bounding_box start, width: width, height: height do
|
@@ -73,13 +75,6 @@ module PrawnRailsForms
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
76
|
-
|
77
|
-
def check_box_field(**args)
|
78
|
-
raise ArgumentError, 'Must be within a field row' unless @row_helper.present?
|
79
|
-
start, width, height = @row_helper.field_attributes args
|
80
|
-
make_check_box_field start, width, height, **args.except(:width, :height)
|
81
|
-
@row_helper.x += width if @row_helper.present?
|
82
|
-
end
|
83
78
|
|
84
79
|
def make_check_box_field(start, width, height, field:, options:, checked:, per_column: 3)
|
85
80
|
bounding_box start, width: width, height: height do
|
data/test-app/Gemfile
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
prawn-rails-forms (0.0.1)
|
5
|
+
prawn-rails (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (5.1.1)
|
11
|
+
actionpack (= 5.1.1)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.1.1)
|
15
|
+
actionpack (= 5.1.1)
|
16
|
+
actionview (= 5.1.1)
|
17
|
+
activejob (= 5.1.1)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.1.1)
|
21
|
+
actionview (= 5.1.1)
|
22
|
+
activesupport (= 5.1.1)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.1.1)
|
28
|
+
activesupport (= 5.1.1)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubi (~> 1.4)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (5.1.1)
|
34
|
+
activesupport (= 5.1.1)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.1.1)
|
37
|
+
activesupport (= 5.1.1)
|
38
|
+
activerecord (5.1.1)
|
39
|
+
activemodel (= 5.1.1)
|
40
|
+
activesupport (= 5.1.1)
|
41
|
+
arel (~> 8.0)
|
42
|
+
activesupport (5.1.1)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
+
i18n (~> 0.7)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
tzinfo (~> 1.1)
|
47
|
+
arel (8.0.0)
|
48
|
+
builder (3.2.3)
|
49
|
+
concurrent-ruby (1.0.5)
|
50
|
+
erubi (1.6.0)
|
51
|
+
ffi (1.9.18)
|
52
|
+
globalid (0.4.0)
|
53
|
+
activesupport (>= 4.2.0)
|
54
|
+
i18n (0.8.1)
|
55
|
+
listen (3.1.5)
|
56
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
57
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
58
|
+
ruby_dep (~> 1.2)
|
59
|
+
loofah (2.0.3)
|
60
|
+
nokogiri (>= 1.5.9)
|
61
|
+
mail (2.6.5)
|
62
|
+
mime-types (>= 1.16, < 4)
|
63
|
+
method_source (0.8.2)
|
64
|
+
mime-types (3.1)
|
65
|
+
mime-types-data (~> 3.2015)
|
66
|
+
mime-types-data (3.2016.0521)
|
67
|
+
mini_portile2 (2.1.0)
|
68
|
+
minitest (5.10.2)
|
69
|
+
nio4r (2.1.0)
|
70
|
+
nokogiri (1.7.2)
|
71
|
+
mini_portile2 (~> 2.1.0)
|
72
|
+
pdf-core (0.7.0)
|
73
|
+
prawn (2.2.2)
|
74
|
+
pdf-core (~> 0.7.0)
|
75
|
+
ttfunk (~> 1.5)
|
76
|
+
prawn-rails (1.0.0)
|
77
|
+
prawn
|
78
|
+
prawn-table
|
79
|
+
rails (>= 3.1.0)
|
80
|
+
prawn-table (0.2.2)
|
81
|
+
prawn (>= 1.3.0, < 3.0.0)
|
82
|
+
puma (3.8.2)
|
83
|
+
rack (2.0.3)
|
84
|
+
rack-test (0.6.3)
|
85
|
+
rack (>= 1.0)
|
86
|
+
rails (5.1.1)
|
87
|
+
actioncable (= 5.1.1)
|
88
|
+
actionmailer (= 5.1.1)
|
89
|
+
actionpack (= 5.1.1)
|
90
|
+
actionview (= 5.1.1)
|
91
|
+
activejob (= 5.1.1)
|
92
|
+
activemodel (= 5.1.1)
|
93
|
+
activerecord (= 5.1.1)
|
94
|
+
activesupport (= 5.1.1)
|
95
|
+
bundler (>= 1.3.0, < 2.0)
|
96
|
+
railties (= 5.1.1)
|
97
|
+
sprockets-rails (>= 2.0.0)
|
98
|
+
rails-dom-testing (2.0.3)
|
99
|
+
activesupport (>= 4.2.0)
|
100
|
+
nokogiri (>= 1.6)
|
101
|
+
rails-html-sanitizer (1.0.3)
|
102
|
+
loofah (~> 2.0)
|
103
|
+
railties (5.1.1)
|
104
|
+
actionpack (= 5.1.1)
|
105
|
+
activesupport (= 5.1.1)
|
106
|
+
method_source
|
107
|
+
rake (>= 0.8.7)
|
108
|
+
thor (>= 0.18.1, < 2.0)
|
109
|
+
rake (12.0.0)
|
110
|
+
rb-fsevent (0.9.8)
|
111
|
+
rb-inotify (0.9.8)
|
112
|
+
ffi (>= 0.5.0)
|
113
|
+
ruby_dep (1.5.0)
|
114
|
+
spring (2.0.2)
|
115
|
+
activesupport (>= 4.2)
|
116
|
+
spring-watcher-listen (2.0.1)
|
117
|
+
listen (>= 2.7, < 4.0)
|
118
|
+
spring (>= 1.2, < 3.0)
|
119
|
+
sprockets (3.7.1)
|
120
|
+
concurrent-ruby (~> 1.0)
|
121
|
+
rack (> 1, < 3)
|
122
|
+
sprockets-rails (3.2.0)
|
123
|
+
actionpack (>= 4.0)
|
124
|
+
activesupport (>= 4.0)
|
125
|
+
sprockets (>= 3.0.0)
|
126
|
+
thor (0.19.4)
|
127
|
+
thread_safe (0.3.6)
|
128
|
+
ttfunk (1.5.1)
|
129
|
+
tzinfo (1.2.3)
|
130
|
+
thread_safe (~> 0.1)
|
131
|
+
websocket-driver (0.6.5)
|
132
|
+
websocket-extensions (>= 0.1.0)
|
133
|
+
websocket-extensions (0.1.2)
|
134
|
+
|
135
|
+
PLATFORMS
|
136
|
+
ruby
|
137
|
+
|
138
|
+
DEPENDENCIES
|
139
|
+
listen (>= 3.0.5, < 3.2)
|
140
|
+
prawn-rails-forms!
|
141
|
+
puma (~> 3.7)
|
142
|
+
rails (~> 5.1.1)
|
143
|
+
spring
|
144
|
+
spring-watcher-listen (~> 2.0.0)
|
145
|
+
|
146
|
+
BUNDLED WITH
|
147
|
+
1.14.6
|
@@ -0,0 +1,108 @@
|
|
1
|
+
prawn_document do |pdf|
|
2
|
+
pdf.text 'Text boxes - base case and size modifications',
|
3
|
+
align: :center, size: 14
|
4
|
+
unit_width = pdf.bounds.width / 5
|
5
|
+
y = pdf.cursor
|
6
|
+
pdf.bounding_box [0, y], height: 15, width: unit_width do
|
7
|
+
pdf.text_box 'This should look normal',
|
8
|
+
size: 10, valign: :bottom, align: :center
|
9
|
+
end
|
10
|
+
pdf.bounding_box [unit_width, y], height: 20, width: unit_width * 2 do
|
11
|
+
pdf.text_box 'This should be twice as long as the others',
|
12
|
+
size: 10, valign: :bottom, align: :center
|
13
|
+
end
|
14
|
+
pdf.bounding_box [unit_width * 3, y], height: 20, width: unit_width do
|
15
|
+
pdf.text_box 'This should have bigger text',
|
16
|
+
size: 10, valign: :bottom, align: :center
|
17
|
+
end
|
18
|
+
pdf.bounding_box [unit_width * 4, y], height: 20, width: unit_width do
|
19
|
+
pdf.text_box 'This should be 5 pixels less tall than the others',
|
20
|
+
size: 10, valign: :bottom, align: :center
|
21
|
+
end
|
22
|
+
|
23
|
+
pdf.field_row height: 30, units: 5 do |row|
|
24
|
+
row.text_field field: 'Favorite fruit', value: 'Bananas!'
|
25
|
+
row.text_field field: 'Longer bananas?', value: 'Absolutely.',
|
26
|
+
width: 2
|
27
|
+
row.text_field field: 'Bigger bananas?', value: 'Yes!',
|
28
|
+
options: { size: 14 }
|
29
|
+
row.text_field field: 'Smaller bananas?', value: 'If you must',
|
30
|
+
height: 25
|
31
|
+
end
|
32
|
+
|
33
|
+
pdf.move_down 70
|
34
|
+
pdf.text 'Text boxes - conditional display options',
|
35
|
+
align: :center, size: 14
|
36
|
+
unit_width = pdf.bounds.width / 4
|
37
|
+
y = pdf.cursor
|
38
|
+
4.times do |i|
|
39
|
+
pdf.bounding_box [unit_width * i, y], height: 15, width: unit_width do
|
40
|
+
message = i.even? ? 'This should show a value' : 'This should not show a value'
|
41
|
+
pdf.text_box message, size: 10, valign: :bottom, align: :center
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
pdf.field_row height: 30, units: 4 do |row|
|
46
|
+
row.text_field field: 'If true', value: 'True',
|
47
|
+
options: { if: true }
|
48
|
+
row.text_field field: 'If false', value: 'False',
|
49
|
+
options: { if: false }
|
50
|
+
row.text_field field: 'Unless false', value: 'True',
|
51
|
+
options: { unless: false }
|
52
|
+
row.text_field field: 'Unless true', value: 'False',
|
53
|
+
options: { unless: true }
|
54
|
+
end
|
55
|
+
|
56
|
+
pdf.move_down 70
|
57
|
+
pdf.text 'Check boxes',
|
58
|
+
align: :center, size: 14
|
59
|
+
unit_width = pdf.bounds.width / 5
|
60
|
+
y = pdf.cursor
|
61
|
+
messages = [
|
62
|
+
'This should have none checked',
|
63
|
+
'This should have all checked',
|
64
|
+
'This should have 2 and 4 checked',
|
65
|
+
'This should have 4 options shown, 3 per column (default)',
|
66
|
+
'This should have 4 options shown, 2 per column'
|
67
|
+
]
|
68
|
+
messages.each.with_index do |message, i|
|
69
|
+
pdf.bounding_box [unit_width * i, y], height: 25, width: unit_width do
|
70
|
+
pdf.text_box message, size: 10, valign: :bottom, align: :center
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
pdf.field_row height: 50, units: 5 do |row|
|
75
|
+
numbers = [2, 3, 4]
|
76
|
+
row.check_box_field field: 'Check the negatives', options: numbers,
|
77
|
+
checked: numbers.map(&:negative?)
|
78
|
+
row.check_box_field field: 'Check the positives', options: numbers,
|
79
|
+
checked: numbers.map(&:positive?)
|
80
|
+
row.check_box_field field: 'Check the evens', options: numbers,
|
81
|
+
checked: numbers.map(&:even?)
|
82
|
+
|
83
|
+
numbers << 5
|
84
|
+
|
85
|
+
row.check_box_field field: 'Check the evens', options: numbers,
|
86
|
+
checked: numbers.map(&:even?)
|
87
|
+
row.check_box_field field: 'Check the evens', options: numbers,
|
88
|
+
checked: numbers.map(&:even?), per_column: 2
|
89
|
+
end
|
90
|
+
|
91
|
+
pdf.move_down 70
|
92
|
+
pdf.text 'Splitting rows',
|
93
|
+
align: :center, size: 14
|
94
|
+
pdf.move_down 10
|
95
|
+
pdf.text 'This should look as expected', size: 10, align: :center
|
96
|
+
|
97
|
+
pdf.field_row height: 50, units: 2 do |row|
|
98
|
+
row.text_field field: 'Full height', value: 'Yep',
|
99
|
+
options: { valign: :center }
|
100
|
+
row.text_field field: 'Half height, top', value: 'Hope so',
|
101
|
+
height: 25, options: { valign: :center }
|
102
|
+
row.at_height 25, unit: 1 do
|
103
|
+
row.text_field field: 'Half height, bottom', value: 'Aww yeah',
|
104
|
+
height: 25, options: { valign: :center }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/test-app/bin/bundle
ADDED
data/test-app/bin/rails
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
load File.expand_path('../spring', __FILE__)
|
4
|
+
rescue LoadError => e
|
5
|
+
raise unless e.message.include?('spring')
|
6
|
+
end
|
7
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
8
|
+
require_relative '../config/boot'
|
9
|
+
require 'rails/commands'
|
data/test-app/bin/spring
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file loads spring without using Bundler, in order to be fast.
|
4
|
+
# It gets overwritten when you run the `spring binstub` command.
|
5
|
+
|
6
|
+
unless defined?(Spring)
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler'
|
9
|
+
|
10
|
+
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
|
11
|
+
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
|
12
|
+
if spring
|
13
|
+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
|
14
|
+
gem 'spring', spring.version
|
15
|
+
require 'spring/binstub'
|
16
|
+
end
|
17
|
+
end
|
data/test-app/config.ru
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'boot'
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
require "active_model/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_view/railtie"
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
module TestApp
|
10
|
+
class Application < Rails::Application
|
11
|
+
config.load_defaults 5.1
|
12
|
+
config.generators.system_tests = nil
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.cache_classes = false
|
3
|
+
config.eager_load = false
|
4
|
+
config.consider_all_requests_local = true
|
5
|
+
|
6
|
+
if Rails.root.join('tmp/caching-dev.txt').exist?
|
7
|
+
config.action_controller.perform_caching = true
|
8
|
+
|
9
|
+
config.cache_store = :memory_store
|
10
|
+
config.public_file_server.headers = {
|
11
|
+
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
|
12
|
+
}
|
13
|
+
else
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
config.cache_store = :null_store
|
17
|
+
end
|
18
|
+
|
19
|
+
config.active_support.deprecation = :log
|
20
|
+
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-rails-forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- UMass Transportation Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn-rails
|
@@ -66,6 +66,25 @@ files:
|
|
66
66
|
- lib/prawn-rails-forms.rb
|
67
67
|
- lib/prawn-rails-forms/version.rb
|
68
68
|
- prawn-rails-forms.gemspec
|
69
|
+
- test-app/Gemfile
|
70
|
+
- test-app/Gemfile.lock
|
71
|
+
- test-app/app/controllers/application_controller.rb
|
72
|
+
- test-app/app/controllers/pdf_controller.rb
|
73
|
+
- test-app/app/views/pdf/static.pdf.prawn
|
74
|
+
- test-app/bin/bundle
|
75
|
+
- test-app/bin/rails
|
76
|
+
- test-app/bin/spring
|
77
|
+
- test-app/config.ru
|
78
|
+
- test-app/config/application.rb
|
79
|
+
- test-app/config/boot.rb
|
80
|
+
- test-app/config/environment.rb
|
81
|
+
- test-app/config/environments/development.rb
|
82
|
+
- test-app/config/initializers/prawn_rails.rb
|
83
|
+
- test-app/config/puma.rb
|
84
|
+
- test-app/config/routes.rb
|
85
|
+
- test-app/config/secrets.yml
|
86
|
+
- test-app/config/spring.rb
|
87
|
+
- test-app/log/.keep
|
69
88
|
homepage: https://github.com/umts/prawn-rails-forms
|
70
89
|
licenses:
|
71
90
|
- MIT
|