rails-latex 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 981dceed55af9b6b6796e8e01b25877fddcb62c8
4
- data.tar.gz: bcff34464bbb2955845001df8500aa4fb9c8c29f
3
+ metadata.gz: 5309d586b2ef3b9af95eb0c66e120d4c523773b6
4
+ data.tar.gz: 93a2ad21871df64a11416a0a26bebae2d059fda2
5
5
  SHA512:
6
- metadata.gz: d13fd73e6c34823a51f71305e5c856c723ddf13b32bacb44e0aee8cec14c578c21cc59b97a1cb8c4b2c39c2af8bbe51fa9c914889023f4e704128c6d14ed1228
7
- data.tar.gz: a8c7a813ae373bfe14e105fd595ef186d7c7e1702c9a253602e01ca37acebaad3e75e5dc8453bdfc260985b8ad0b9ce34f43d3e570964b31350d1d15fcc30fff
6
+ metadata.gz: f942c7f3a80b5e93e4b064bfbbe1adf796a1022df665e2a1b024f482757ea84edad578b01d8402dc3e6f9c9c3745880c647c8d550cb3a3c13f3fd23ee44b3acd
7
+ data.tar.gz: c8680b6ced9aa002404e4a6969c8c88d23e29e7147041ab1a678da4123d8a35bb0663d99bbbc13141d6e886a6c8adf2afd4cf92f51356eafc8e91aecc2e40711
@@ -1,11 +1,10 @@
1
1
  <h1>LatexExample#index</h1>
2
2
  <ul>
3
- <li> <%= link_to "print", latex_example_path(:format => :pdf) %></li>
3
+ <li><%= link_to "print", latex_example_path(:format => :pdf) %></li>
4
4
 
5
5
  <li><%= link_to "print barcode", latex_example_barcode_path(:format => :pdf) %></li>
6
6
 
7
7
  <li><%= link_to "print barcode - with no '.pdf' in url", latex_example_barcode_path %></li>
8
8
 
9
-
10
9
  <li><%= link_to "generate barcode pdf as string", latex_example_barcode_as_string_path %> and write to <tt><%= "#{Rails.root}/tmp/a.pdf" %></tt> </li>
11
10
  </ul>
@@ -6,4 +6,3 @@ Generated at <%= Time.current %>.
6
6
 
7
7
  The last page is \pageref{LastPage}.
8
8
 
9
-
@@ -1,14 +1,38 @@
1
1
  \documentclass[12pt,a4paper,sloppy]{article}
2
- <% @latex_config={:command => 'pdflatex',:parse_runs => 2} # you can override the defaults if you wish; see LatexToPdf#config %>
2
+ <% @latex_config = { :recipe => [
3
+ {:command => 'pdflatex'},
4
+ {:command => 'bibtex', :arguments =>[]},
5
+ {:command => 'pdflatex', :runs => 2}
6
+ ]} # you can override the defaults if you wish; see LatexToPdf#config
7
+ %>
8
+ \usepackage{filecontents}
3
9
  \usepackage{lastpage}
4
10
  \usepackage{graphics}
5
- \begin{document}
6
11
 
7
- This document uses \verb|parse_runs = 2| to calculate the last page.
12
+ \begin{filecontents}{bibliography.bib}
13
+ @article{example,
14
+ author = {John Doe},
15
+ title = {The title of the work},
16
+ journal = {The name of the journal},
17
+ year = 1993,
18
+ number = 2,
19
+ pages = {201-213},
20
+ month = 7,
21
+ note = {An optional note},
22
+ volume = 4
23
+ }
24
+ \end{filecontents}
25
+
26
+ \begin{document}
27
+ This document\cite{example} uses \verb|parse_runs = 2| to calculate the last page.
8
28
 
9
29
  Other defaults can be overridden using \verb|LatexToPdf#config| and \verb|@latex_config|.
10
30
 
11
31
  <%= yield %>
12
32
 
33
+ \bibliography{bibliography}
34
+ \bibliographystyle{plain}
35
+
36
+
13
37
  \end{document}
14
38
 
@@ -4,7 +4,6 @@
4
4
  \usepackage{pst-barcode}
5
5
  \usepackage{hyperref}
6
6
 
7
-
8
7
  \begin{document}
9
8
 
10
9
  <%= yield %>
@@ -13,7 +13,7 @@ module ActionView # :nodoc: all
13
13
  def compile(template)
14
14
  erb = "<% __in_erb_template=true %>#{template.source}"
15
15
  out=self.class.erb_implementation.new(erb, :trim=>(self.class.erb_trim_mode == "-")).src
16
- out + ";LatexToPdf.generate_pdf(@output_buffer.to_s,@latex_config||{},@latex_parse_twice)"
16
+ out + ";LatexToPdf.generate_pdf(@output_buffer.to_s, @latex_config||{})"
17
17
  end
18
18
  end
19
19
  end
@@ -1,53 +1,94 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  class LatexToPdf
3
3
  def self.config
4
- @config||={:command => 'pdflatex', :arguments => ['-halt-on-error'], :parse_runs => 1}
4
+ @config||={
5
+ :recipe => [
6
+ # {
7
+ # :command => 'pdflatex',
8
+ # :input => 'input.tex',
9
+ # :arguments => ['-halt-on-error', '-shell-escape', '-interaction=batchmode'],
10
+ # :extra_arguments => [],
11
+ # :runs => 1
12
+ # }
13
+ ],
14
+ :command => 'pdflatex',
15
+ :arguments => ['-halt-on-error'],
16
+ :default_arguments => ['-shell-escape', '-interaction=batchmode'],
17
+ :parse_runs => 1
18
+ }
5
19
  end
6
20
 
7
21
  # Converts a string of LaTeX +code+ into a binary string of PDF.
8
22
  #
9
- # pdflatex is used to convert the file and creates the directory +#{Rails.root}/tmp/rails-latex/+ to store intermediate
10
- # files.
23
+ # By default, pdflatex is used to convert the file and creates the directory
24
+ # +#{Rails.root}/tmp/rails-latex/+ to store intermediate files.
11
25
  #
12
- # The config argument defaults to LatexToPdf.config but can be overridden using @latex_config.
13
- def self.generate_pdf(code,config,parse_twice=nil)
14
- config=self.config.merge(config)
15
- parse_runs=config[:parse_runs]
16
- Rails.logger.info "Running Latex #{parse_runs} times..."
17
- dir=File.join(Rails.root,'tmp','rails-latex',"#{Process.pid}-#{Thread.current.hash}")
18
- input=File.join(dir,'input.tex')
26
+ # The config argument defaults to LatexToPdf.config but can be overridden
27
+ # using @latex_config.
28
+ def self.generate_pdf(code, config)
29
+ config = self.config.merge(config)
30
+ recipe = config[:recipe]
31
+
32
+ # Deprecated legacy mode, if no recipe found
33
+ if recipe.length == 0
34
+ if config != self.config
35
+ Rails.logger.warn("Using command, arguments and parse_runs is deprecated in favor of recipe")
36
+ end
37
+ # Regression fix -- ability to override some arguments (-halt-on-error) but not other (-interaction),
38
+ # this is expected behaviour as seen in test_broken_doc_overriding_halt_on_error.
39
+ # Will be fixed in rails-latex 3
40
+ recipe = [{
41
+ :command => config[:command],
42
+ :arguments => config[:arguments] + config[:default_arguments],
43
+ :runs => config[:parse_runs]
44
+ }]
45
+ end
46
+
47
+ # Create directory, prepare additional supporting files (.cls, .sty, ...)
48
+ dir = File.join(Rails.root, 'tmp', 'rails-latex', "#{Process.pid}-#{Thread.current.hash}")
49
+ input = File.join(dir, 'input.tex')
19
50
  FileUtils.mkdir_p(dir)
20
- # copy any additional supporting files (.cls, .sty, ...)
21
51
  supporting = config[:supporting]
22
52
  if supporting.kind_of?(String) or supporting.kind_of?(Pathname) or (supporting.kind_of?(Array) and supporting.length > 0)
23
53
  FileUtils.cp_r(supporting, dir)
24
54
  end
25
- File.open(input,'wb') {|io| io.write(code) }
26
- Process.waitpid(
27
- fork do
28
- begin
29
- Dir.chdir dir
30
- args=config[:arguments] + %w[-shell-escape -interaction batchmode input.tex]
31
- kwargs={:out => ["input.log","a"]}
32
- (parse_runs-1).times do
33
- system config[:command],'-draftmode',*args,**kwargs
55
+ File.open(input,'wb') {|io| io.write(code)}
56
+
57
+ # Process recipe
58
+ recipe.each do |item|
59
+ command = item[:command] || config[:command]
60
+ runs = item[:runs] || config[:parse_runs]
61
+ args = item[:arguments] || config[:arguments]
62
+ args += item[:extra_arguments].to_a + ['input']
63
+ kwargs = {:out => ["input.log", "a"]}
64
+ Rails.logger.info "Running #{command} #{args.join(' ')} #{runs} times..."
65
+ Process.waitpid(
66
+ fork do
67
+ begin
68
+ Dir.chdir dir
69
+ (runs - 1).times do
70
+ system command, *args, **kwargs
71
+ end
72
+ exec command, *args, **kwargs
73
+ rescue
74
+ File.open("input.log", 'a'){|io|
75
+ io.write("#{$!.message}:\n#{$!.backtrace.join("\n")}\n")
76
+ }
77
+ ensure
78
+ Process.exit! 1
34
79
  end
35
- exec config[:command],*args,**kwargs
36
- rescue
37
- File.open("input.log",'a') {|io|
38
- io.write("#{$!.message}:\n#{$!.backtrace.join("\n")}\n")
39
- }
40
- ensure
41
- Process.exit! 1
42
80
  end
43
- end)
81
+ )
82
+ end
83
+
84
+ # Finish
44
85
  if File.exist?(pdf_file=input.sub(/\.tex$/,'.pdf'))
45
- FileUtils.mv(input,File.join(dir,'..','input.tex'))
46
- FileUtils.mv(input.sub(/\.tex$/,'.log'),File.join(dir,'..','input.log'))
47
- result=File.read(pdf_file)
86
+ FileUtils.mv(input, File.join(dir, '..', 'input.tex'))
87
+ FileUtils.mv(input.sub(/\.tex$/,'.log'), File.join(dir, '..', 'input.log'))
88
+ result = File.read(pdf_file)
48
89
  FileUtils.rm_rf(dir)
49
90
  else
50
- raise "pdflatex failed: See #{input.sub(/\.tex$/,'.log')} for details"
91
+ raise "rails-latex failed: See #{input.sub(/\.tex$/,'.log')} for details"
51
92
  end
52
93
  result
53
94
  end
@@ -1,3 +1,3 @@
1
1
  module RailsLatex
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
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: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Baier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-07-04 00:00:00.000000000 Z
12
+ date: 2016-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails