latexpdf 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README.rdoc +34 -0
  4. data/Rakefile +16 -0
  5. data/lib/action_view/template_handlers/tex.rb +26 -0
  6. data/lib/latexpdf/configuration.rb +13 -0
  7. data/lib/latexpdf/errors/latexpdf_error.rb +13 -0
  8. data/lib/latexpdf/pdf_generator.rb +105 -0
  9. data/lib/latexpdf/railtie.rb +9 -0
  10. data/lib/latexpdf/version.rb +3 -0
  11. data/lib/latexpdf.rb +45 -0
  12. data/test/dummy/README.rdoc +28 -0
  13. data/test/dummy/Rakefile +6 -0
  14. data/test/dummy/app/assets/javascripts/application.js +13 -0
  15. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  16. data/test/dummy/app/controllers/application_controller.rb +5 -0
  17. data/test/dummy/app/controllers/tex_controller.rb +7 -0
  18. data/test/dummy/app/helpers/application_helper.rb +2 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/test/dummy/app/views/tex/example.pdf.tex +4 -0
  21. data/test/dummy/bin/bundle +3 -0
  22. data/test/dummy/bin/rails +4 -0
  23. data/test/dummy/bin/rake +4 -0
  24. data/test/dummy/bin/setup +21 -0
  25. data/test/dummy/config/application.rb +32 -0
  26. data/test/dummy/config/boot.rb +5 -0
  27. data/test/dummy/config/database.yml +25 -0
  28. data/test/dummy/config/environment.rb +5 -0
  29. data/test/dummy/config/environments/development.rb +41 -0
  30. data/test/dummy/config/environments/production.rb +79 -0
  31. data/test/dummy/config/environments/test.rb +42 -0
  32. data/test/dummy/config/initializers/assets.rb +11 -0
  33. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  34. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  35. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  36. data/test/dummy/config/initializers/inflections.rb +16 -0
  37. data/test/dummy/config/initializers/mime_types.rb +4 -0
  38. data/test/dummy/config/initializers/session_store.rb +3 -0
  39. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  40. data/test/dummy/config/locales/en.yml +23 -0
  41. data/test/dummy/config/routes.rb +3 -0
  42. data/test/dummy/config/secrets.yml +22 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/log/test.log +458 -0
  45. data/test/dummy/public/404.html +67 -0
  46. data/test/dummy/public/422.html +67 -0
  47. data/test/dummy/public/500.html +66 -0
  48. data/test/dummy/public/favicon.ico +0 -0
  49. data/test/dummy/tmp/cache/assets/sprockets/v3.0/5L/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
  50. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Al/Al8B-MlRXLmvveOkSiQtTH7Mnx87ww6TKPPkXQkDCfA.cache +1 -0
  51. data/test/dummy/tmp/cache/assets/sprockets/v3.0/El/Elvl8FhrIcCHSvOVJ4mlw98G_x77dIhDO7ncklgb9o8.cache +0 -0
  52. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Eo/EoGXUuweaJggMJEhq_PIGuHGezpQHVeyR5Tnle6g0Zk.cache +0 -0
  53. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Iv/IvDM1j8-H1H6kEjVCsyIW8N2zla-aIp9q_OE9PVZtVw.cache +1 -0
  54. data/test/dummy/tmp/cache/assets/sprockets/v3.0/OH/OHv3xxmOjKcBMS0Y_yTmyfrhpGoi7AbGMBAcCFsH1vg.cache +1 -0
  55. data/test/dummy/tmp/cache/assets/sprockets/v3.0/OI/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +2 -0
  56. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Ol/OlBX9JIv9SAOmK2t35x1SYDx1sxCXF0yvqpna3WMyH0.cache +1 -0
  57. data/test/dummy/tmp/cache/assets/sprockets/v3.0/TG/TGzz_qJLZNCMGy25pS4Lm-8Vj71mxCyy5TNmGoF9mUk.cache +1 -0
  58. data/test/dummy/tmp/cache/assets/sprockets/v3.0/Yr/YrZ0OIHu42cExs1kqngMA6ShVDKhfGmhyW-E9haNo5Y.cache +1 -0
  59. data/test/dummy/tmp/cache/assets/sprockets/v3.0/gp/gpiWtnqpufka8lRtMznM6Ko0aWJrcH_j8cfZwdYmzNI.cache +1 -0
  60. data/test/dummy/tmp/cache/assets/sprockets/v3.0/hZ/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
  61. data/test/dummy/tmp/cache/assets/sprockets/v3.0/jo/jozGBeLU1Q4eVAsw_A_nyY994iqcnwgTZWiFbVsYmBs.cache +0 -0
  62. data/test/dummy/tmp/cache/assets/sprockets/v3.0/pE/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
  63. data/test/dummy/tmp/cache/assets/sprockets/v3.0/sU/sU_vk26h2xIJpI3d-zhVgF2iTwOCAFk7zHPYuvqWNk0.cache +0 -0
  64. data/test/dummy/tmp/cache/assets/sprockets/v3.0/sp/sp2aS0gBrj1ZVPgX0e8j11TaSSz3qpMGjtFv6soZ0KM.cache +0 -0
  65. data/test/integration/rendering_test.rb +11 -0
  66. data/test/latexpdf/configuration_test.rb +16 -0
  67. data/test/latexpdf/latexpdf_error_test.rb +10 -0
  68. data/test/latexpdf/latexpdf_test.rb +19 -0
  69. data/test/latexpdf/logger_test.rb +6 -0
  70. data/test/latexpdf/pdf_generator_test.rb +39 -0
  71. data/test/test_helper.rb +57 -0
  72. data/test/testdata/invalid_tex.tex +3 -0
  73. data/test/testdata/minimal.tex +5 -0
  74. metadata +281 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"0processors:type=text/css&file_type=text/css;TTI"9file-digest://app/assets/stylesheets/application.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI")file-digest://app/assets/stylesheets;TT
@@ -0,0 +1 @@
1
+ "%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
@@ -0,0 +1 @@
1
+ I"}app/assets/stylesheets/application.css?type=text/css&id=93902ba9be958ea697873edae159cdc470211bd8c2b939ae303aba14e18bf150:ET
@@ -0,0 +1 @@
1
+ "%Ѱč@�����6H�uZoX�Z�gbh0W��V
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"9file-digest://app/assets/stylesheets/application.css;TTI")file-digest://app/assets/stylesheets;TT
@@ -0,0 +1 @@
1
+ I"�app/assets/javascripts/application.js?type=application/javascript&id=c87c9ccdd07de9828f7f7d5aa23764f1cfc554f22e682fb7d6ce41e5c0e0b956:ET
@@ -0,0 +1 @@
1
+ "%�W\�yho9S���ƫ˥��)|�~���(���
@@ -0,0 +1 @@
1
+ I"�app/assets/stylesheets/application.css?type=text/css&pipeline=self&id=06b90b83bbaac1dfd68de9c50878994eea7a69a94d0b122e6b8d4e9d6cc66f94:ET
@@ -0,0 +1 @@
1
+ I"�app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=98cd4cc444a449286875aa32504b1eb7c21f3f00d75d45943262079070f2c6ef:ET
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"8file-digest://app/assets/javascripts/application.js;TTI")file-digest://app/assets/javascripts;TT
@@ -0,0 +1,2 @@
1
+ [o:Set:
2
+ @hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"8file-digest://app/assets/javascripts/application.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI")file-digest://app/assets/javascripts;TT
@@ -0,0 +1,11 @@
1
+ require "test_helper"
2
+
3
+ class RenderingTest < ActionDispatch::IntegrationTest
4
+ test "Generate PDF on the fly in a controller" do
5
+ get "/tex/example.pdf"
6
+ assert_match (/application\/pdf/), response.headers["Content-Type"]
7
+ reader = PDF::Reader.new(StringIO.new(response.body))
8
+ assert_equal 1, reader.pages.count
9
+ assert_match (/Test latex document/), reader.pages.first.text
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+
3
+ module Latexpdf
4
+ class ConfigurationTest < MiniTest::Test
5
+ def test_implement_passes_configuration
6
+ assert_equal 2, Configuration.new.passes
7
+ end
8
+
9
+ def test_configure_a_default_logger
10
+ config = Configuration.new
11
+
12
+ assert_equal Logger, config.logger.class
13
+ assert_equal "Latexpdf", config.logger.progname
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+
3
+ module Latexpdf
4
+ class LatexpdfErrorTest < Minitest::Test
5
+ def test_implement_to_s
6
+ e = LatexpdfError.new("message")
7
+ assert_equal "message", e.to_s
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+
3
+ module Latexpdf
4
+ class LatexpdfTest < Minitest::Test
5
+ def test_be_able_to_configure_passes
6
+ Latexpdf.configure do |config|
7
+ config.passes = 5
8
+ end
9
+ assert_equal 5, Latexpdf.configuration.passes
10
+ end
11
+
12
+ def test_be_able_to_configure_a_logger
13
+ Latexpdf.configure do |config|
14
+ config.logger = "test_logger"
15
+ end
16
+ assert_equal "test_logger", Latexpdf.logger
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ require "test_helper"
2
+
3
+ module Latexpdf
4
+ class LoggerTest < Minitest::Test
5
+ end
6
+ end
@@ -0,0 +1,39 @@
1
+ require "test_helper"
2
+
3
+ module Latexpdf
4
+ class PdfGeneratorTest < Minitest::Test
5
+ def teardown
6
+ subject.cleanup
7
+ end
8
+
9
+ def test_generate_pdf
10
+ subject.generate
11
+ assert File.file?(pdf_file)
12
+ assert_match (/Test latex document/), pdf_reader.pages.first.text
13
+ end
14
+
15
+ def test_fail_on_invalid_tex
16
+ invalid_tex_file = File.join(data_path, "invalid_tex.tex")
17
+ @subject = PdfGenerator.new(invalid_tex_file)
18
+ e = assert_raises LatexpdfError do
19
+ subject.generate
20
+ end
21
+ assert_match (/Missing \\begin\{document\}/), e.message
22
+ end
23
+
24
+ private
25
+
26
+ def subject
27
+ minimal_tex_file = File.join(data_path, "minimal.tex")
28
+ @subject ||= PdfGenerator.new(File.read(minimal_tex_file))
29
+ end
30
+
31
+ def pdf_file
32
+ subject.pdf_file
33
+ end
34
+
35
+ def pdf_reader
36
+ PDF::Reader.new(pdf_file)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,57 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
4
+ require "rails/test_help"
5
+
6
+ require "simplecov"
7
+ SimpleCov.start if ENV["COVERAGE"]
8
+
9
+ require "minitest/autorun"
10
+
11
+ old_verbose, $VERBOSE = $VERBOSE, nil
12
+ require "pdf-reader"
13
+ $VERBOSE = old_verbose
14
+
15
+ require "minitest/reporters"
16
+ Minitest::Reporters.use!
17
+
18
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
19
+ # to be shown.
20
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
21
+
22
+ # Load support files
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
24
+
25
+ # Load fixtures from the engine
26
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
27
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
28
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
29
+ ActiveSupport::TestCase.fixtures :all
30
+ end
31
+
32
+ class MockLogger
33
+ def clear
34
+ @messages = {}
35
+ end
36
+
37
+ def messages
38
+ @messages ||= {}
39
+ end
40
+
41
+ def info(msg)
42
+ msgs = (messages[:info] || Array.new) << msg
43
+ @messages[:info] = msgs
44
+ end
45
+
46
+ def error(msg)
47
+ end
48
+ end
49
+
50
+ def test_logger
51
+ @logger ||= MockLogger.new
52
+ end
53
+
54
+ def data_path
55
+ File.join(__dir__, "testdata")
56
+ end
57
+
@@ -0,0 +1,3 @@
1
+ Invalid
2
+ <%= "Invalid test latex document" %>
3
+
@@ -0,0 +1,5 @@
1
+ \documentclass{article}
2
+ \usepackage{fontspec}
3
+ \begin{document}
4
+ Test latex document €€€€
5
+ \end{document}