rails-latex 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
= Rails-LaTeX
|
2
2
|
|
3
3
|
* Git: http://github.com/jacott/rails-latex
|
4
|
-
* Author: Geoff Jacobsen
|
5
|
-
* Copyright: 2009-2010
|
4
|
+
* Author: Geoff Jacobsen
|
5
|
+
* Copyright: 2009-2010
|
6
6
|
* License: MIT-LICENSE
|
7
7
|
|
8
8
|
== Description
|
@@ -22,7 +22,7 @@ app/views/stories/show.html.erb:
|
|
22
22
|
|
23
23
|
|
24
24
|
app/views/stories/show.pdf.erb:
|
25
|
-
...
|
25
|
+
...
|
26
26
|
<%= lesc @story.name % >
|
27
27
|
|
28
28
|
app/views/layouts/application.pdf.erbtex:
|
@@ -33,7 +33,7 @@ app/views/layouts/application.pdf.erbtex:
|
|
33
33
|
|
34
34
|
|
35
35
|
config/initializers/mime_types.rb:
|
36
|
-
...
|
36
|
+
...
|
37
37
|
Mime::Type.register "application/pdf", :pdf, ['text/pdf'], ['pdf']
|
38
38
|
|
39
39
|
|
@@ -48,12 +48,16 @@ You can override the defaults like so:
|
|
48
48
|
|
49
49
|
LatexToPdf.config.merge! :command => 'xetex', :arguments => ['-etex'], :parse_twice => true
|
50
50
|
|
51
|
+
or to change just the arguments:
|
52
|
+
|
53
|
+
LatexToPdf.config[:arguments].delete('-halt-on-error')
|
54
|
+
|
51
55
|
The defaults are:
|
52
56
|
command: 'pdflatex'
|
53
|
-
arguments: []
|
57
|
+
arguments: ['-halt-on-error']
|
54
58
|
parse_twice: false
|
55
59
|
|
56
|
-
The last log file is moved to tmp/rails-latex/input.log . If the PDF is
|
60
|
+
The last log file is moved to tmp/rails-latex/input.log . If the PDF is not produced the build directory is not removed;
|
57
61
|
an archive script should be written to occasionally clean up the tmp/rails-latex directory.
|
58
62
|
|
59
63
|
See the rails application under examples/rails-latex-demo/ for a working example.
|
@@ -76,7 +80,7 @@ Then in your mailer:
|
|
76
80
|
def email_sender(user, pdf_attachment)
|
77
81
|
@user = user
|
78
82
|
attachments["attachment_name.pdf"] = {:mime_type => 'application/pdf', :content => pdf_attachment}
|
79
|
-
mail( .... )
|
83
|
+
mail( .... )
|
80
84
|
end
|
81
85
|
|
82
86
|
== Requirements
|
@@ -7,10 +7,8 @@ class LatexExampleController < ApplicationController
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def barcode_as_string
|
10
|
-
|
11
|
-
old_content_type = self.content_type
|
12
10
|
@pdf=render_to_string(action: 'barcode', layout: "barcode", formats: [:pdf])
|
13
|
-
self.content_type =
|
11
|
+
self.content_type = 'text/html'
|
14
12
|
|
15
13
|
File.open(file="#{Rails.root}/tmp/a.pdf",'w:binary') do |io|
|
16
14
|
io.write(@pdf)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class LatexToPdf
|
2
2
|
def self.config
|
3
|
-
@config||={:command => 'pdflatex', :arguments => [], :parse_twice => false}
|
3
|
+
@config||={:command => 'pdflatex', :arguments => ['-halt-on-error'], :parse_twice => false}
|
4
4
|
end
|
5
5
|
|
6
6
|
# Converts a string of LaTeX +code+ into a binary string of PDF.
|
@@ -24,7 +24,7 @@ class LatexToPdf
|
|
24
24
|
Dir.chdir dir
|
25
25
|
STDOUT.reopen("input.log","a")
|
26
26
|
STDERR.reopen(STDOUT)
|
27
|
-
args=config[:arguments] + %w[-shell-escape -interaction batchmode
|
27
|
+
args=config[:arguments] + %w[-shell-escape -interaction batchmode input.tex]
|
28
28
|
system config[:command],'-draftmode',*args if parse_twice
|
29
29
|
exec config[:command],*args
|
30
30
|
rescue
|
data/lib/rails-latex/version.rb
CHANGED
data/test/test_latex_to_pdf.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'helper'
|
2
3
|
require 'rails-latex/erb_latex'
|
3
4
|
require 'ostruct'
|
@@ -5,7 +6,13 @@ require 'ostruct'
|
|
5
6
|
Rails=OpenStruct.new(:root => TMP_DIR=File.expand_path("../tmp",__FILE__))
|
6
7
|
|
7
8
|
class TestLatexToPdf < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
super
|
11
|
+
FileUtils.rm_rf("#{TMP_DIR}/tmp/rails-latex")
|
12
|
+
end
|
13
|
+
|
8
14
|
def teardown
|
15
|
+
super
|
9
16
|
LatexToPdf.instance_eval { @config=nil }
|
10
17
|
end
|
11
18
|
|
@@ -26,6 +33,22 @@ class TestLatexToPdf < Test::Unit::TestCase
|
|
26
33
|
assert_equal "dsf \\textless{} \\textgreater{} \\& ! @ \\# \\$ \\% \\^{} \\~{} \\textbackslash{} fds", LatexToPdf.escape_latex('dsf < > & ! @ # $ % ^ ~ \\ fds')
|
27
34
|
end
|
28
35
|
|
36
|
+
def test_broken_doc_halt_on_error
|
37
|
+
begin
|
38
|
+
LatexToPdf.generate_pdf(IO.read(File.expand_path('../test_broken_doc.tex',__FILE__)),{})
|
39
|
+
fail "Should throw exception"
|
40
|
+
rescue => e
|
41
|
+
assert(/^pdflatex failed: See / =~ e.message)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_broken_doc_overriding_halt_on_error
|
46
|
+
pdf_file=write_pdf do
|
47
|
+
LatexToPdf.generate_pdf(IO.read(File.expand_path('../test_broken_doc.tex',__FILE__)),{arguments: []})
|
48
|
+
end
|
49
|
+
assert_equal "file with error\n\n1\n\n\f", `pdftotext #{pdf_file} -`
|
50
|
+
end
|
51
|
+
|
29
52
|
def test_generate_pdf_one_parse
|
30
53
|
pdf_file=write_pdf do
|
31
54
|
LatexToPdf.generate_pdf(IO.read(File.expand_path('../test_doc.tex',__FILE__)),{})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-latex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/rails-latex/version.rb
|
96
96
|
- rails-latex.gemspec
|
97
97
|
- test/helper.rb
|
98
|
+
- test/test_broken_doc.tex
|
98
99
|
- test/test_doc.tex
|
99
100
|
- test/test_latex_to_pdf.rb
|
100
101
|
homepage: http://github.com/jacott/rails-latex
|
@@ -118,9 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.8.
|
122
|
+
rubygems_version: 1.8.23
|
122
123
|
signing_key:
|
123
124
|
specification_version: 3
|
124
125
|
summary: A LaTeX to pdf rails 3 renderer.
|
125
126
|
test_files: []
|
126
|
-
has_rdoc:
|