corpshort 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module Corpshort
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,107 @@
1
+ require 'prawn'
2
+ require 'prawn/qrcode'
3
+
4
+ module Corpshort
5
+ class VerticalPdf
6
+ include Prawn::Measurements
7
+
8
+ def initialize(url:, base_url:, name:, flex: false)
9
+ @url = url
10
+ @base_url = base_url
11
+ @name = name
12
+
13
+ @flex = flex
14
+
15
+ if @flex
16
+ @width = code_size + required_width_for_url_box + padding + padding
17
+ end
18
+ end
19
+
20
+ def w
21
+ @width || cm2pt(6)
22
+ end
23
+
24
+ def h
25
+ cm2pt(4)
26
+ end
27
+
28
+ def code_size
29
+ cm2pt(3)
30
+ end
31
+
32
+ def padding
33
+ cm2pt(0.2)
34
+ end
35
+
36
+ def text
37
+ [
38
+ {link: @url, text: @base_url},
39
+ {link: @url, text: '/'},
40
+ {link: @url, styles: [:bold], text: @name},
41
+ ]
42
+ end
43
+
44
+ def required_width_for_url_box
45
+ doc = Prawn::Document.new(page_size: [cm2pt(5),cm2pt(5)], margin: 0)
46
+ doc.font_size = 12
47
+ text.inject(0) do |r,t|
48
+ r + doc.width_of(t.fetch(:text), style: t[:styles]&.first)
49
+ end
50
+ end
51
+
52
+ def url_box
53
+ Prawn::Text::Formatted::Box.new(
54
+ text,
55
+ document: pdf,
56
+ at: [padding, (h-code_size)-padding],
57
+ width: w - padding - padding,
58
+ height: (h-code_size) - padding - padding,
59
+ overflow: :shrink_to_fit,
60
+ min_font_size: nil,
61
+ disable_wrap_by_char: true,
62
+ align: :center,
63
+ valign: :center,
64
+ kerning: true,
65
+ )
66
+ end
67
+
68
+ def render
69
+ @pdf = nil
70
+
71
+ code_pos = [(w-code_size)/2.0, h]
72
+
73
+ pdf.fill_color 'FFFFFF'
74
+ pdf.fill { pdf.rounded_rectangle code_pos, code_size, code_size, 5 }
75
+ pdf.print_qr_code(@url, level: :m, pos: code_pos, extent: code_size, stroke: false)
76
+
77
+ [true, false].each do |dry_run|
78
+ box = url_box()
79
+ box.render(dry_run: dry_run)
80
+ if dry_run
81
+ pdf.fill_color 'FFFFFF'
82
+ pdf.fill do
83
+ pdf.rounded_rectangle(
84
+ [box.at[0] - padding, box.at[1] + padding],
85
+ box.available_width + padding + padding,
86
+ box.height + padding + padding,
87
+ 5,
88
+ )
89
+ end
90
+ pdf.fill_color '000000'
91
+ end
92
+ end
93
+
94
+ pdf
95
+ end
96
+
97
+ def document
98
+ render
99
+ end
100
+
101
+ def pdf
102
+ @pdf ||= Prawn::Document.new(page_size: [w,h], margin: 0).tap do |pdf|
103
+ pdf.font_size = 12
104
+ end
105
+ end
106
+ end
107
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: corpshort
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sorah Fukumori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-protection
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: erubi
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk-dynamodb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rqrcode
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: prawn
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: prawn-qrcode
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rack-test
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description:
182
+ email:
183
+ - sorah@cookpad.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".travis.yml"
191
+ - Gemfile
192
+ - Gemfile.lock
193
+ - LICENSE.txt
194
+ - README.md
195
+ - Rakefile
196
+ - app/public/style.css
197
+ - app/views/edit.erb
198
+ - app/views/index.erb
199
+ - app/views/layout.erb
200
+ - app/views/list.erb
201
+ - app/views/show.erb
202
+ - bin/console
203
+ - bin/setup
204
+ - config.ru
205
+ - corpshort.gemspec
206
+ - lib/corpshort.rb
207
+ - lib/corpshort/app.rb
208
+ - lib/corpshort/backends/base.rb
209
+ - lib/corpshort/backends/dynamodb.rb
210
+ - lib/corpshort/backends/memory.rb
211
+ - lib/corpshort/backends/redis.rb
212
+ - lib/corpshort/horizontal_pdf.rb
213
+ - lib/corpshort/link.rb
214
+ - lib/corpshort/version.rb
215
+ - lib/corpshort/vertical_pdf.rb
216
+ homepage: https://github.com/sorah/corpshort
217
+ licenses:
218
+ - MIT
219
+ metadata: {}
220
+ post_install_message:
221
+ rdoc_options: []
222
+ require_paths:
223
+ - lib
224
+ required_ruby_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ required_rubygems_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubyforge_project:
236
+ rubygems_version: 2.7.7
237
+ signing_key:
238
+ specification_version: 4
239
+ summary: '"go/" like private link shortener for internal purpose'
240
+ test_files: []