texrack 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NGIyZDVhOGRjYzc0MzQ5ZGQwMzlhMmE0MTdkYWE4MDZmODRlMTUwYw==
5
- data.tar.gz: !binary |-
6
- NTkwNWQ1MTI3ZjkzZTljMGI1NjU0ZmU3MGMwMTE2NTljM2EyNjE2Nw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- M2Q2NTQ0ZDRjMTg3NjE5OTM5MmExM2U5ZmM2MzdhMDg4ZDQxNDczZmI0YTcz
10
- OTY1MzQ1ZGU0ZTZiOGU5MjIyNTgwNzMwOGEwZmNjMTI0Mjc2N2UxN2RjZmNl
11
- MDU0NjBlZTFkN2Q2NTIzYmI4MTM5YzNlZmY0NDM0NWExODQ5ZWQ=
12
- data.tar.gz: !binary |-
13
- OTIyYzU4NTA2YmIyMzViODEwMDQ5NjNlNTFhZjFjNjVhMGVhYTdmMGE5YWQ5
14
- NDFkYWFkMTJmYTAxNmQwYWZlMDU5MWMxZWMyMzI4ZGQ1NDAzNGVhODdjNWQz
15
- NTMwMTAwMjZjMDcwZDY2MTE2ZGU0YjQ1OGJmNzM0OGY0MWZjMDI=
2
+ SHA1:
3
+ metadata.gz: 4aea4cde344abda376e29d4adbb6415644d75d67
4
+ data.tar.gz: c2d87b2eee6ea9963d8c41cc0710775a3f3d948c
5
+ SHA512:
6
+ metadata.gz: 48f349be4326492b76c5908c1c9f4b726d5b7e57c47892bd93ca52aa38b0111d316ff00236b0ed0c157b11b299fbd0b90154b75a1a8f9abf2649e63e53cc9a52
7
+ data.tar.gz: 0eaab0480d74bf0e6602057bd9fce79e259832ed69e589240e0a9f9654ac58b97b2b2938aef9c1c8bcdf40c5b2235dd2331e47090892f6adbd1c30d349e6eec2
checksums.yaml.gz.asc CHANGED
@@ -2,17 +2,17 @@
2
2
  Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQIcBAABAgAGBQJSc3n3AAoJEH1ncb0Txu7XuZMQAJKfYU5XwxxT6Nw2aNhVVCoZ
6
- Q34Lt43zPcQpHHF8LK5bP/FNHD4GQK+WWiMPComX5VmnTIxLbQX2DNEWmeiMpyjw
7
- ydYzURm8aZGheI1ejFuE9Py50m8WeTAituN/x2ey5WnwGIEsvVVQ+NYXdknz2jNl
8
- nvbaiH3/F8UZe7oqeCKFTPB5XPaIDQQMdk3pwGqiIPtSXnIig51LP7dvKPQ06Yca
9
- TiZYxjsQjRIJviHFO5nbww7322eNDlySqGdndlRJxAJjcLcrhruf0kdWOcev4ZF4
10
- rChy909T/r+5aJ7P58lgNQWI0MA+4LuLlKNyQhN+dbnGvdEioF88gfaQPhBm4sTC
11
- AAIPvp4suFWKerwmOveG607KvK7178V+5svrSZDrnxfhu3K+8+42coh1Gsyh4EeL
12
- c7xSXLMqycmqQxTtXlVkFk2IoQytieaXD/BnjKqLKkjQGXTQlVD+1hXxNcMheda+
13
- IKO08yma6uEiocJxZjvb9nVhDbicLfO428bdjihGYYs/cF7nhlojVJFxp9r2Kf7Z
14
- xv9zQkVsDhL6Ucr266G3DKN0mzSBeZZB78axkzjZJRVkxyc8oL2/IMutLCZIYHfR
15
- JmmalIU9ZoGdRoUXmr8A9MwDIQKu2rlogaFSkaM/ZKjYovfIwyYgFi+PVOX9wa8l
16
- FzBRzW44gnLsWCjrSieU
17
- =LOQB
5
+ iQIcBAABAgAGBQJSePZ+AAoJEH1ncb0Txu7XyKoQAI9383kh4LNjO6W23K5ipagY
6
+ dcSrmSvn1XDIJvAJyFtQpBaGVxdcGJW8U5E8LCEhD3UE93mOfgC86HGuQLO0/0EC
7
+ M87VvLp2rtwa+FoEF+e6Y5FYLahuLFlSnomDDhWwAcU85eazr3ARSprdx6e8iH3B
8
+ N0xplsS1mpoBbZ1tn4pAinDx2IU/iqnqYadPgMPpqJ3+jjDKZn9vNTCbpwLphVOA
9
+ xbGWJiu1CKWs1gCUWcwR9uUMWTqcPXkfforJmJdZd7lZ1KccMc1HoNY9JykRpRgu
10
+ VRGmGmRnu/P+MwO+AdeQnXamcld95rMU7ktnQM0YIAbp8LcaDCZ7SruXzlaXUYQg
11
+ YFNbdvfkW0aGR0RLcAK2DWtUDcPcgPuCz23q6YO4kZhmToIR4monO+ZohmsJEfUB
12
+ RvA+sljHqBwwMF2N42dGYm1pwhKm//28GHWlxIt4sRrbtM1xSiOZh/Pi9u9l+QC6
13
+ AgMcdaVdKut1EN0BzjSHZwSVHUf1vZWaRDxYZWmgMrPFhxPbYhex63+2f9RoGZN2
14
+ ICE9Fiq30k+1iyFATTvv8xdJzxUVdj+f8Wk4+mMHC2RzZ7AySPLDkXktWPIUOC1W
15
+ I3SElQ42lIn668t3MRMpRjHJuZz06/MILVi2mVFcJ1jPJg6PtUDpKq1Do6xaOXYx
16
+ NMcmLMvksi0DxwW2j8uQ
17
+ =391P
18
18
  -----END PGP SIGNATURE-----
data.tar.gz.asc CHANGED
@@ -2,17 +2,17 @@
2
2
  Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQIcBAABAgAGBQJSc3n3AAoJEH1ncb0Txu7XMcwP/1S6Ixhnzw6oKq/8hiJ6T1bA
6
- tHf5Ip8nB0BZP2vIioAeEOJxZDr3YnbRJ+d4nJy4MltqlYZtE4ZV64umNKqRnSHT
7
- JtwHK7my38kA9H7pM6GKJq19VojZU7RxDAmp/RHkLbZfh9pC8su09lshOX7EX09f
8
- jIIo1PhZUT9yhXiuPczNHa6fI/z4c942a8KCAIftrF3xDCA9ahY63QeYarr3LVrf
9
- 0QwvAORKQ9tv16M/BxArhF36mnVF64wFYa7mkqrczCkXXGwWlBXH0D1fv/GEvvZz
10
- OQzWGCsOEdH8IKup8bwKtAnXxuZlvLkct1DQgiCv7N8PDhTdcu73JJW9XPXBD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0tphfvhHdfcYoUcD9iHROn14i0f5z+MpEpMbQvVDzAQfpskRUx6spwyXyIG
16
+ ubc4VCkcsK7pxxZRcflN
17
+ =km1K
18
18
  -----END PGP SIGNATURE-----
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # 0.3.0 / 2013-11-05
2
+
3
+ * Allow forcing the response status to 200 OK
4
+ * Remove unused code
5
+
6
+ # 0.2.0 / 2013-11-01
7
+
8
+ * Replace RMagick with Cocaine and ImageMagick
9
+ * Better error handling
10
+ * Work when mounted somewhere other than /
11
+
12
+ # 0.1.0 / 2013-10-28
13
+
14
+ * Initial version
data/README.md CHANGED
@@ -31,3 +31,8 @@ turns into
31
31
  \usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
32
32
  \usepackage{amssymb}
33
33
  ```
34
+
35
+ ### Always respond with 200 OK
36
+ If you are dealing with software incapable of proper status codes (looking at
37
+ you, Flash), you can pass `always_200=1` and it'll respond with 200 OK even
38
+ though we should really respond with a 5xx.
@@ -7,57 +7,65 @@ module Texrack
7
7
  set :public_folder, File.dirname(__FILE__) + '/static'
8
8
 
9
9
  get '/' do
10
- if params[:data].to_s.strip != ""
11
- render_png(params[:data])
10
+ if data != ""
11
+ render_png
12
12
  else
13
13
  erb :form
14
14
  end
15
15
  end
16
16
 
17
17
  post '/' do
18
- render_png(params[:data])
18
+ render_png
19
19
  end
20
20
 
21
- def render_png(source)
21
+ def render_png
22
22
  content_type 'image/png'
23
+
23
24
  begin
24
- @data = source
25
25
  output = Tempfile.new(["texrack-output", ".png"])
26
26
  pdf_source = erb :latex
27
27
  pdf = Texrack::LatexToPdf.new(pdf_source, logger).generate_pdf
28
28
  png = Texrack::PdfToPng.new(pdf, logger).to_file(output)
29
- send_file png, {
30
- disposition: :inline
31
- }
29
+ send_file png, disposition: :inline
32
30
  rescue Texrack::LatexFailedError
33
- send_file File.join(settings.public_folder, "latex-failed.png"), {
34
- disposition: :inline,
35
- status: 500
36
- }
31
+ send_static_error "latex-failed.png"
37
32
  rescue Texrack::LatexNotFoundError
38
33
  logger.error "Could not find pdflatex in #{ENV['PATH']}"
39
- send_file File.join(settings.public_folder, "missing-pdflatex.png"), {
40
- disposition: :inline,
41
- status: 500
42
- }
34
+ send_static_error "missing-pdflatex.png"
43
35
  rescue Texrack::ConvertNotFoundError
44
36
  logger.error "Could not find convert (ImageMagick) in #{ENV['PATH']}"
45
- send_file File.join(settings.public_folder, "missing-convert.png"), {
46
- disposition: :inline,
47
- status: 500
48
- }
37
+ send_static_error "missing-convert.png"
49
38
  end
50
39
  end
51
40
 
52
41
  helpers do
42
+ def send_static_error(filename)
43
+ send_file File.join(settings.public_folder, filename), {
44
+ disposition: :inline,
45
+ status: error_status
46
+ }
47
+ end
48
+
53
49
  def math_mode?
54
50
  params[:math] != "0"
55
51
  end
56
52
 
53
+ def always_respond_with_200?
54
+ params[:always_200] == "1"
55
+ end
56
+
57
+ def error_status
58
+ always_respond_with_200? ? 200 : 500
59
+ end
60
+
57
61
  def root_path
58
62
  "#{env['SCRIPT_NAME']}/"
59
63
  end
60
64
 
65
+ def data
66
+ params[:data].to_s.strip
67
+ end
68
+
61
69
  def packages
62
70
  found = {}
63
71
  params[:packages].to_s.split("|").each do |package|
@@ -1,14 +1,9 @@
1
1
  class Texrack::LatexToPdf
2
- def self.config
3
- @config ||= {command: 'pdflatex', arguments: [], parse_twice: false}
4
- end
5
-
6
- attr_reader :config, :latex, :logger
2
+ attr_reader :latex, :logger
7
3
 
8
- def initialize(latex, logger=Logger.new(STDOUT), overrides = {})
4
+ def initialize(latex, logger=Logger.new(STDOUT))
9
5
  @latex = latex
10
6
  @logger = logger
11
- @config = self.class.config.merge(overrides)
12
7
  end
13
8
 
14
9
  # Converts a string of LaTeX code into a binary string of PDF.
@@ -27,15 +22,10 @@ class Texrack::LatexToPdf
27
22
  fork do
28
23
  begin
29
24
  Dir.chdir File.dirname(input)
30
- args = config[:arguments] + %w[-shell-escape -interaction batchmode -halt-on-error] + [input.path]
31
-
32
- if config[:parse_twice]
33
- logger.debug("Texrack executing (parse twice): #{config[:command]} -draftmode #{args}")
34
- system config[:command], '-draftmode', *args
35
- end
25
+ args = %w[-shell-escape -interaction batchmode -halt-on-error] + [input.path]
36
26
 
37
- logger.debug "Texrack executing: #{config[:command]} #{args}"
38
- exec config[:command], *args
27
+ logger.debug "Texrack executing: pdflatex #{args}"
28
+ exec "pdflatex", *args
39
29
  rescue
40
30
  logger.error "#{$!.message}:\n#{$!.backtrace.join("\n")}\n"
41
31
  ensure
Binary file
Binary file
@@ -1,3 +1,3 @@
1
1
  module Texrack
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -6,7 +6,7 @@
6
6
  \usepackage{amsmath}
7
7
  \begin{document}
8
8
  <% if math_mode? %>\[<% end %>
9
- <%= @data %>
9
+ <%= data %>
10
10
  <% if math_mode? %>\]<% end %>
11
11
  \end{document}
12
12
 
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Per Christian B. Viken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: sinatra
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - ~>
17
18
  - !ruby/object:Gem::Version
18
19
  version: 1.4.4
20
+ type: :runtime
21
+ prerelease: false
19
22
  version_requirements: !ruby/object:Gem::Requirement
20
23
  requirements:
21
24
  - - ~>
22
25
  - !ruby/object:Gem::Version
23
26
  version: 1.4.4
24
- type: :runtime
25
- prerelease: false
26
- name: sinatra
27
27
  - !ruby/object:Gem::Dependency
28
+ name: cocaine
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: 0.5.3
34
+ type: :runtime
35
+ prerelease: false
33
36
  version_requirements: !ruby/object:Gem::Requirement
34
37
  requirements:
35
38
  - - ~>
36
39
  - !ruby/object:Gem::Version
37
40
  version: 0.5.3
38
- type: :runtime
39
- prerelease: false
40
- name: cocaine
41
41
  description: texrack is a microservice that renders LaTeX as PNG files. Can be mounted
42
42
  in a Rack app
43
43
  email:
@@ -48,6 +48,7 @@ extra_rdoc_files:
48
48
  - MIT-LICENSE
49
49
  - README.md
50
50
  files:
51
+ - CHANGELOG.md
51
52
  - MIT-LICENSE
52
53
  - README.md
53
54
  - config.ru
@@ -73,19 +74,18 @@ require_paths:
73
74
  - lib
74
75
  required_ruby_version: !ruby/object:Gem::Requirement
75
76
  requirements:
76
- - - ! '>='
77
+ - - '>='
77
78
  - !ruby/object:Gem::Version
78
79
  version: '0'
79
80
  required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements:
81
- - - ! '>='
82
+ - - '>='
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  requirements: []
85
86
  rubyforge_project:
86
- rubygems_version: 2.0.3
87
+ rubygems_version: 2.1.10
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Rack microservice to render LaTeX as PNG
90
91
  test_files: []
91
- has_rdoc:
metadata.gz.asc CHANGED
@@ -2,17 +2,17 @@
2
2
  Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQIcBAABAgAGBQJSc3n2AAoJEH1ncb0Txu7XDdsP/3N7Sfl6Xfm3hwSaNxeOxGwb
6
- QOhc54Ri2o52AP0eUzQptpbkgonfTrk1rOH2Tvekj6PqfoJtv9mk6GZ8bCumcYtB
7
- +06IjudEtI78SF2O6/r0QEtXnIqOnqmqFPn9r8OY4FmMqCNkabN+DF+5LkJqM0tQ
8
- PnlDl3eY/3sBn5n4V5ujRLWX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