latexpdf 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/latexpdf/escaper.rb +33 -0
- data/lib/latexpdf/version.rb +1 -1
- data/lib/latexpdf.rb +3 -0
- data/test/dummy/app/controllers/tex_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/app/views/tex/example2.pdf.tex +6 -0
- data/test/dummy/config/environments/development.rb +0 -3
- data/test/dummy/log/development.log +54 -0
- data/test/dummy/log/test.log +105 -0
- data/test/integration/rendering_test.rb +10 -0
- data/test/latexpdf/escaper_test.rb +45 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617518c1f7ec6b02b3c2d789c717f14bd5d15bf9
|
4
|
+
data.tar.gz: d0fdc327ff7685d40d6236a984ce297531905891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90db69ee7ea6e75cf90e12c0de5b31b91af9e0cfbbfb53d096fe4a7f4ca14e58e6daf231b582fc4bef7704cb4f028ada22206171fddf8f8778aea99ccc0dba5d
|
7
|
+
data.tar.gz: 27d1def3ad962959d8a1c36a3765572a2a9f9d17c154dee20b7220fd0dd6bfba497cdbdab64616e71ecd22b0ec46c50c55349a2666f6f8afba6315a4e1c761aa
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Latexpdf
|
2
|
+
class Escaper
|
3
|
+
ESCAPE_RE=/([{}_$&%#])|([\\^~|<>])/
|
4
|
+
ESC_MAP = {
|
5
|
+
'\\' => 'backslash',
|
6
|
+
'^' => 'asciicircum',
|
7
|
+
'~' => 'asciitilde',
|
8
|
+
'|' => 'bar',
|
9
|
+
'<' => 'less',
|
10
|
+
'>' => 'greater',
|
11
|
+
}
|
12
|
+
|
13
|
+
def tex_safe(text)
|
14
|
+
text.gsub(ESCAPE_RE) { |m|
|
15
|
+
if $1
|
16
|
+
"\\#{m}"
|
17
|
+
else
|
18
|
+
"\\text#{ESC_MAP[m]}{}"
|
19
|
+
end
|
20
|
+
}.html_safe
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.escape_latex(text)
|
25
|
+
latex_escaper.tex_safe(text)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self.latex_escaper
|
31
|
+
@latex_escaper ||= Escaper.new
|
32
|
+
end
|
33
|
+
end
|
data/lib/latexpdf/version.rb
CHANGED
data/lib/latexpdf.rb
CHANGED
@@ -19,9 +19,6 @@ Rails.application.configure do
|
|
19
19
|
# Print deprecation notices to the Rails logger.
|
20
20
|
config.active_support.deprecation = :log
|
21
21
|
|
22
|
-
# Raise an error on page load if there are pending migrations.
|
23
|
-
config.active_record.migration_error = :page_load
|
24
|
-
|
25
22
|
# Debug mode disables concatenation and preprocessing of assets.
|
26
23
|
# This option may cause significant delays in view rendering with a large
|
27
24
|
# number of complex assets.
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:21:02 +0200
|
4
|
+
Processing by TexController#example2 as PDF
|
5
|
+
Rendered tex/example2.pdf.tex (1397.9ms)
|
6
|
+
Completed 200 OK in 1408ms (Views: 1408.0ms)
|
7
|
+
|
8
|
+
|
9
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:24:01 +0200
|
10
|
+
Processing by TexController#example2 as PDF
|
11
|
+
Rendered tex/example2.pdf.tex (1451.5ms)
|
12
|
+
Completed 200 OK in 1454ms (Views: 1453.4ms)
|
13
|
+
|
14
|
+
|
15
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:24:02 +0200
|
16
|
+
Processing by TexController#example2 as PDF
|
17
|
+
Rendered tex/example2.pdf.tex (1495.4ms)
|
18
|
+
Completed 200 OK in 1498ms (Views: 1497.5ms)
|
19
|
+
|
20
|
+
|
21
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:24:47 +0200
|
22
|
+
Processing by TexController#example2 as PDF
|
23
|
+
Rendered tex/example2.pdf.tex (1300.8ms)
|
24
|
+
Completed 200 OK in 1303ms (Views: 1302.3ms)
|
25
|
+
|
26
|
+
|
27
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:24:49 +0200
|
28
|
+
Processing by TexController#example2 as PDF
|
29
|
+
Rendered tex/example2.pdf.tex (1474.8ms)
|
30
|
+
Completed 200 OK in 1478ms (Views: 1477.2ms)
|
31
|
+
|
32
|
+
|
33
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:25:01 +0200
|
34
|
+
Processing by TexController#example2 as PDF
|
35
|
+
Rendered tex/example2.pdf.tex (1272.2ms)
|
36
|
+
Completed 200 OK in 1274ms (Views: 1273.6ms)
|
37
|
+
|
38
|
+
|
39
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:25:02 +0200
|
40
|
+
Processing by TexController#example2 as PDF
|
41
|
+
Rendered tex/example2.pdf.tex (1470.4ms)
|
42
|
+
Completed 200 OK in 1472ms (Views: 1471.9ms)
|
43
|
+
|
44
|
+
|
45
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:27:26 +0200
|
46
|
+
Processing by TexController#example2 as PDF
|
47
|
+
Rendered tex/example2.pdf.tex (1483.5ms)
|
48
|
+
Completed 200 OK in 1495ms (Views: 1494.2ms)
|
49
|
+
|
50
|
+
|
51
|
+
Started GET "/tex/example2.pdf" for ::1 at 2016-05-24 11:27:28 +0200
|
52
|
+
Processing by TexController#example2 as PDF
|
53
|
+
Rendered tex/example2.pdf.tex (1586.0ms)
|
54
|
+
Completed 200 OK in 1589ms (Views: 1588.4ms)
|
data/test/dummy/log/test.log
CHANGED
@@ -456,3 +456,108 @@ Started GET "/tex/example.pdf" for 127.0.0.1 at 2016-05-23 17:40:08 +0200
|
|
456
456
|
Processing by TexController#example as PDF
|
457
457
|
Rendered tex/example.pdf.tex (1144.2ms)
|
458
458
|
Completed 200 OK in 1154ms (Views: 1153.8ms)
|
459
|
+
-----------------------------------------------------------
|
460
|
+
RenderingTest: test_Generate_PDF_on_the_fly_in_a_controller
|
461
|
+
-----------------------------------------------------------
|
462
|
+
Started GET "/tex/example.pdf" for 127.0.0.1 at 2016-05-24 10:22:59 +0200
|
463
|
+
Processing by TexController#example as PDF
|
464
|
+
Rendered tex/example.pdf.tex (2845.9ms)
|
465
|
+
Completed 200 OK in 2856ms (Views: 2855.3ms)
|
466
|
+
-----------------------------------------------------------
|
467
|
+
RenderingTest: test_Generate_PDF_on_the_fly_in_a_controller
|
468
|
+
-----------------------------------------------------------
|
469
|
+
Started GET "/tex/example.pdf" for 127.0.0.1 at 2016-05-24 11:01:22 +0200
|
470
|
+
Processing by TexController#example as PDF
|
471
|
+
Rendered tex/example.pdf.tex (1315.1ms)
|
472
|
+
Completed 200 OK in 1326ms (Views: 1325.5ms)
|
473
|
+
-----------------------------------------------------------
|
474
|
+
RenderingTest: test_Generate_PDF_on_the_fly_in_a_controller
|
475
|
+
-----------------------------------------------------------
|
476
|
+
Started GET "/tex/example.pdf" for 127.0.0.1 at 2016-05-24 11:08:45 +0200
|
477
|
+
Processing by TexController#example as PDF
|
478
|
+
Rendered tex/example.pdf.tex (1221.9ms)
|
479
|
+
Completed 200 OK in 1229ms (Views: 1229.0ms)
|
480
|
+
---------------------------------------------------------
|
481
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
482
|
+
---------------------------------------------------------
|
483
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:13:39 +0200
|
484
|
+
Processing by TexController#example2 as PDF
|
485
|
+
Rendered tex/example2.pdf.tex (356.3ms)
|
486
|
+
Completed 500 Internal Server Error in 364ms
|
487
|
+
---------------------------------------------------------
|
488
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
489
|
+
---------------------------------------------------------
|
490
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:13:58 +0200
|
491
|
+
Processing by TexController#example2 as PDF
|
492
|
+
Rendered tex/example2.pdf.tex (15.7ms)
|
493
|
+
Completed 500 Internal Server Error in 23ms
|
494
|
+
---------------------------------------------------------
|
495
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
496
|
+
---------------------------------------------------------
|
497
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:14:21 +0200
|
498
|
+
Processing by TexController#example2 as PDF
|
499
|
+
Rendered tex/example2.pdf.tex (1306.3ms)
|
500
|
+
Completed 200 OK in 1314ms (Views: 1314.1ms)
|
501
|
+
---------------------------------------------------------
|
502
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
503
|
+
---------------------------------------------------------
|
504
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:27:59 +0200
|
505
|
+
Processing by TexController#example2 as PDF
|
506
|
+
Rendered tex/example2.pdf.tex (1307.1ms)
|
507
|
+
Completed 200 OK in 1314ms (Views: 1313.8ms)
|
508
|
+
---------------------------------------------------------
|
509
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
510
|
+
---------------------------------------------------------
|
511
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:30:41 +0200
|
512
|
+
Processing by TexController#example2 as PDF
|
513
|
+
Rendered tex/example2.pdf.tex (1358.4ms)
|
514
|
+
Completed 200 OK in 1367ms (Views: 1366.3ms)
|
515
|
+
---------------------------------------------------------
|
516
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
517
|
+
---------------------------------------------------------
|
518
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:31:00 +0200
|
519
|
+
Processing by TexController#example2 as PDF
|
520
|
+
Rendered tex/example2.pdf.tex (1300.7ms)
|
521
|
+
Completed 200 OK in 1308ms (Views: 1307.7ms)
|
522
|
+
---------------------------------------------------------
|
523
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
524
|
+
---------------------------------------------------------
|
525
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:31:20 +0200
|
526
|
+
Processing by TexController#example2 as PDF
|
527
|
+
Rendered tex/example2.pdf.tex (1287.9ms)
|
528
|
+
Completed 200 OK in 1295ms (Views: 1294.4ms)
|
529
|
+
---------------------------------------------------------
|
530
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
531
|
+
---------------------------------------------------------
|
532
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:31:46 +0200
|
533
|
+
Processing by TexController#example2 as PDF
|
534
|
+
Rendered tex/example2.pdf.tex (1301.4ms)
|
535
|
+
Completed 200 OK in 1309ms (Views: 1309.2ms)
|
536
|
+
---------------------------------------------------------
|
537
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
538
|
+
---------------------------------------------------------
|
539
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:31:54 +0200
|
540
|
+
Processing by TexController#example2 as PDF
|
541
|
+
Rendered tex/example2.pdf.tex (1303.6ms)
|
542
|
+
Completed 200 OK in 1311ms (Views: 1310.3ms)
|
543
|
+
---------------------------------------------------------
|
544
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
545
|
+
---------------------------------------------------------
|
546
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:31:59 +0200
|
547
|
+
Processing by TexController#example2 as PDF
|
548
|
+
Rendered tex/example2.pdf.tex (1326.0ms)
|
549
|
+
Completed 200 OK in 1333ms (Views: 1332.7ms)
|
550
|
+
-----------------------------------------------------------
|
551
|
+
RenderingTest: test_Generate_PDF_on_the_fly_in_a_controller
|
552
|
+
-----------------------------------------------------------
|
553
|
+
Started GET "/tex/example.pdf" for 127.0.0.1 at 2016-05-24 11:43:02 +0200
|
554
|
+
Processing by TexController#example as PDF
|
555
|
+
Rendered tex/example.pdf.tex (3393.3ms)
|
556
|
+
Completed 200 OK in 3402ms (Views: 3402.0ms)
|
557
|
+
---------------------------------------------------------
|
558
|
+
RenderingTest: test_Generate_PDF_using_escaped_characters
|
559
|
+
---------------------------------------------------------
|
560
|
+
Started GET "/tex/example2.pdf" for 127.0.0.1 at 2016-05-24 11:43:05 +0200
|
561
|
+
Processing by TexController#example2 as PDF
|
562
|
+
Rendered tex/example2.pdf.tex (3438.5ms)
|
563
|
+
Completed 200 OK in 3441ms (Views: 3440.4ms)
|
@@ -8,4 +8,14 @@ class RenderingTest < ActionDispatch::IntegrationTest
|
|
8
8
|
assert_equal 1, reader.pages.count
|
9
9
|
assert_match (/Test latex document/), reader.pages.first.text
|
10
10
|
end
|
11
|
+
|
12
|
+
test "Generate PDF using escaped characters" do
|
13
|
+
get "/tex/example2.pdf"
|
14
|
+
assert_match (/application\/pdf/), response.headers["Content-Type"]
|
15
|
+
reader = PDF::Reader.new(StringIO.new(response.body))
|
16
|
+
assert_equal 1, reader.pages.count
|
17
|
+
assert_match (/& % \$ #/), reader.pages.first.text
|
18
|
+
assert_match (/\~ \^/), reader.pages.first.text
|
19
|
+
# PDF reader does not parse the others correctly unfortunately
|
20
|
+
end
|
11
21
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Latexpdf
|
4
|
+
class EscaperTest < MiniTest::Test
|
5
|
+
def test_escape_ampersand
|
6
|
+
assert_equal "\\&", Latexpdf.escape_latex("&")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_escape_dollar
|
10
|
+
assert_equal "\\$", Latexpdf.escape_latex("$")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_escape_pound
|
14
|
+
assert_equal "\\#", Latexpdf.escape_latex("#")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_escape_underscore
|
18
|
+
assert_equal "\\_", Latexpdf.escape_latex("_")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_escape_lcurly
|
22
|
+
assert_equal "\\{", Latexpdf.escape_latex("{")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_escape_rcurly
|
26
|
+
assert_equal "\\}", Latexpdf.escape_latex("}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_escape_tilde
|
30
|
+
assert_equal "\\textasciitilde{}", Latexpdf.escape_latex("~")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_escape_ciicircum
|
34
|
+
assert_equal "\\textasciicircum{}", Latexpdf.escape_latex("^")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_escape_backslash
|
38
|
+
assert_equal "\\textbackslash{}", Latexpdf.escape_latex("\\")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_escape_percent_sign
|
42
|
+
assert_equal "\\%", Latexpdf.escape_latex("%")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: latexpdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthijs Ooms
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/latexpdf.rb
|
126
126
|
- lib/latexpdf/configuration.rb
|
127
127
|
- lib/latexpdf/errors/latexpdf_error.rb
|
128
|
+
- lib/latexpdf/escaper.rb
|
128
129
|
- lib/latexpdf/pdf_generator.rb
|
129
130
|
- lib/latexpdf/railtie.rb
|
130
131
|
- lib/latexpdf/version.rb
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- test/dummy/app/helpers/application_helper.rb
|
138
139
|
- test/dummy/app/views/layouts/application.html.erb
|
139
140
|
- test/dummy/app/views/tex/example.pdf.tex
|
141
|
+
- test/dummy/app/views/tex/example2.pdf.tex
|
140
142
|
- test/dummy/bin/bundle
|
141
143
|
- test/dummy/bin/rails
|
142
144
|
- test/dummy/bin/rake
|
@@ -160,6 +162,7 @@ files:
|
|
160
162
|
- test/dummy/config/locales/en.yml
|
161
163
|
- test/dummy/config/routes.rb
|
162
164
|
- test/dummy/config/secrets.yml
|
165
|
+
- test/dummy/log/development.log
|
163
166
|
- test/dummy/log/test.log
|
164
167
|
- test/dummy/public/404.html
|
165
168
|
- test/dummy/public/422.html
|
@@ -183,6 +186,7 @@ files:
|
|
183
186
|
- test/dummy/tmp/cache/assets/sprockets/v3.0/sp/sp2aS0gBrj1ZVPgX0e8j11TaSSz3qpMGjtFv6soZ0KM.cache
|
184
187
|
- test/integration/rendering_test.rb
|
185
188
|
- test/latexpdf/configuration_test.rb
|
189
|
+
- test/latexpdf/escaper_test.rb
|
186
190
|
- test/latexpdf/latexpdf_error_test.rb
|
187
191
|
- test/latexpdf/latexpdf_test.rb
|
188
192
|
- test/latexpdf/logger_test.rb
|
@@ -223,6 +227,7 @@ test_files:
|
|
223
227
|
- test/dummy/app/helpers/application_helper.rb
|
224
228
|
- test/dummy/app/views/layouts/application.html.erb
|
225
229
|
- test/dummy/app/views/tex/example.pdf.tex
|
230
|
+
- test/dummy/app/views/tex/example2.pdf.tex
|
226
231
|
- test/dummy/bin/bundle
|
227
232
|
- test/dummy/bin/rails
|
228
233
|
- test/dummy/bin/rake
|
@@ -246,6 +251,7 @@ test_files:
|
|
246
251
|
- test/dummy/config/routes.rb
|
247
252
|
- test/dummy/config/secrets.yml
|
248
253
|
- test/dummy/config.ru
|
254
|
+
- test/dummy/log/development.log
|
249
255
|
- test/dummy/log/test.log
|
250
256
|
- test/dummy/public/404.html
|
251
257
|
- test/dummy/public/422.html
|
@@ -271,6 +277,7 @@ test_files:
|
|
271
277
|
- test/dummy/tmp/cache/assets/sprockets/v3.0/Yr/YrZ0OIHu42cExs1kqngMA6ShVDKhfGmhyW-E9haNo5Y.cache
|
272
278
|
- test/integration/rendering_test.rb
|
273
279
|
- test/latexpdf/configuration_test.rb
|
280
|
+
- test/latexpdf/escaper_test.rb
|
274
281
|
- test/latexpdf/latexpdf_error_test.rb
|
275
282
|
- test/latexpdf/latexpdf_test.rb
|
276
283
|
- test/latexpdf/logger_test.rb
|