prawn-rails-forms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fbc180759bfc078fd33fd5c1606cbb99a6c8825c
4
+ data.tar.gz: d0a78629714077ed28b328dc0e7454e8b2d38149
5
+ SHA512:
6
+ metadata.gz: f0098edb6d405f8d11a1e9bf032ad51bd1315cab2690080d3d6f48c9572e2d896b0f0ea6d77b13c3b5bdd4edc8141d1fd8fd21733ff686884ada471a4966aa24
7
+ data.tar.gz: f72ccfe9264863dd90f20572be3c15382986671f33a6264d35990f2003a7b907d199a00a2d2007c748592d3dd84fbad96c4ac1c15fc14070875e1a021b80496d
@@ -0,0 +1 @@
1
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 UMass Transportation Services
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # PrawnRailsForms
2
+
3
+ TODO: what even is this
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'prawn-rails-forms'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install prawn-rails-forms
20
+
21
+ TODO: adding to prawn rails initializer file
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/umts/prawn-rails-forms.
@@ -0,0 +1,122 @@
1
+ require "prawn-rails-forms/version"
2
+
3
+ require 'prawn-rails'
4
+
5
+ module PrawnRailsForms
6
+ class RowHelper
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
12
+ end
13
+
14
+ def field_attributes(args)
15
+ start = [@x, @y]
16
+ width = @unit_width * (args[:width] || 1)
17
+ height = args[:height] || @height
18
+ [start, width, height]
19
+ end
20
+ end
21
+
22
+ class PrawnRails::Document
23
+ attr_accessor :row_helper
24
+
25
+ def field_row(height:, units:, &block)
26
+ @row_helper = RowHelper.new height, units,
27
+ 0, cursor, bounds.width / units
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
42
+ end
43
+
44
+ def text_field(**args)
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
50
+
51
+ def make_text_field(start, width, height, field:, value:, options: {})
52
+ bounding_box start, width: width, height: height do
53
+ stroke_bounds
54
+ bounds.add_left_padding 2
55
+ move_down 2
56
+ text field.upcase, size: 6
57
+ text_size = options[:size] || 10
58
+ if value.present?
59
+ unless options[:if] == false || options[:unless] == true
60
+ align = options[:align] || :center
61
+ valign = options[:valign] || :bottom
62
+ value = value.to_s unless value.is_a? Array
63
+ text = if value.is_a? Array
64
+ value.join "\n"
65
+ else value.to_s
66
+ end
67
+ # cursor is current y position
68
+ bounding_box [0, cursor], width: bounds.width do
69
+ text_box text, align: align, size: text_size, valign: valign,
70
+ overflow: :ellipses
71
+ end
72
+ end
73
+ end
74
+ end
75
+ 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
+
84
+ def make_check_box_field(start, width, height, field:, options:, checked:, per_column: 3)
85
+ bounding_box start, width: width, height: height do
86
+ stroke_bounds
87
+ bounds.add_left_padding 2
88
+ move_down 2
89
+ text field.upcase, size: 6
90
+ move_down 2
91
+ box_height = cursor
92
+ box_width = (width - 4) / options.each_slice(per_column).count
93
+ options.each_slice(per_column).with_index do |opts, i|
94
+ bounding_box [box_width * i, box_height], width: box_width, height: box_height do
95
+ bounds.add_left_padding 2
96
+ bounds.add_right_padding 2
97
+ move_down 2
98
+ opts.each.with_index do |opt, j|
99
+ overall_index = i * per_column + j
100
+ make_check_box checked: checked[overall_index], text: opt
101
+ move_down 2
102
+ end # each option
103
+ end # options bounding box
104
+ end # each set of options
105
+ end # field bounding box
106
+ end # method definition
107
+
108
+ def make_check_box(checked:, text:)
109
+ box_y = cursor
110
+ bounding_box [0, box_y], width: 7, height: 7 do
111
+ stroke_bounds
112
+ if checked
113
+ move_down 1
114
+ text 'X', align: :center, size: 6, style: :bold
115
+ end
116
+ end
117
+ bounding_box [9, box_y], width: bounds.width - 9, height: 10 do
118
+ text text, size: 10
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,3 @@
1
+ module PrawnRailsForms
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "prawn-rails-forms/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "prawn-rails-forms"
7
+ spec.version = PrawnRailsForms::VERSION
8
+ spec.authors = ["UMass Transportation Services"]
9
+ spec.email = ["transit-it@admin.umass.edu"]
10
+ spec.licenses = ['MIT']
11
+
12
+ spec.summary = %q{An extension to PrawnRails, making form layouts easier.}
13
+ spec.homepage = "https://github.com/umts/prawn-rails-forms"
14
+ spec.files = `git ls-files -z`.split "\x0"
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_dependency 'prawn-rails', '~> 1.0'
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.15"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prawn-rails-forms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - UMass Transportation Services
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - transit-it@admin.umass.edu
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - lib/prawn-rails-forms.rb
67
+ - lib/prawn-rails-forms/version.rb
68
+ - prawn-rails-forms.gemspec
69
+ homepage: https://github.com/umts/prawn-rails-forms
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.6.11
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: An extension to PrawnRails, making form layouts easier.
93
+ test_files: []