texrack 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.asc +14 -14
- data.tar.gz.asc +14 -14
- data/CHANGELOG.md +4 -0
- data/README.md +8 -0
- data/config.ru +6 -0
- data/lib/texrack.rb +5 -1
- data/lib/texrack/endpoint.rb +28 -10
- data/lib/texrack/output_file.rb +41 -0
- data/lib/texrack/version.rb +1 -1
- data/{lib/texrack/static → web/assets}/latex-failed.png +0 -0
- data/{lib/texrack/static → web/assets}/missing-convert.png +0 -0
- data/{lib/texrack/static → web/assets}/missing-pdflatex.png +0 -0
- data/{lib/texrack → web}/views/form.erb +0 -0
- data/{lib/texrack → web}/views/latex.erb +0 -0
- metadata +9 -8
- metadata.gz.asc +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b523a5a1e75e256049dfb84edf012060fdb50337
|
4
|
+
data.tar.gz: 90e7971413c416e2d5e2318878a0e6313ec5332c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e46b080448db5c47d3d18453bdc47addc72553bd5f4ce18379787231a5537f214e8c1fcdaa95ae3f8094ddd698f57a7980eec94fd1b0869292d6fcb98f8fa98d
|
7
|
+
data.tar.gz: bbc0d57800af7de61d334a3a08215c3863f3cacfb0d1e7cf643da9744a40496f21a4162c3e6fa85e7320c0029b1496e9320e0162273db9be60a2ffb0fb26e6f5
|
checksums.yaml.gz.asc
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
-----BEGIN PGP SIGNATURE-----
|
2
|
-
Version: GnuPG/MacGPG2 v2.0.
|
2
|
+
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
|
3
3
|
Comment: GPGTools - http://gpgtools.org
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|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.md
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,7 @@ Texrack.config = {
|
|
22
22
|
pdflatex: "pdflatex",
|
23
23
|
convert: "convert",
|
24
24
|
logger: nil,
|
25
|
+
cache_dir: Dir.mktmpdir
|
25
26
|
}
|
26
27
|
```
|
27
28
|
|
@@ -52,3 +53,10 @@ turns into
|
|
52
53
|
If you are dealing with software incapable of proper status codes (looking at
|
53
54
|
you, Flash), you can pass `always_200=1` and it'll respond with 200 OK even
|
54
55
|
though we should really respond with a 5xx.
|
56
|
+
|
57
|
+
### Caching
|
58
|
+
Generated images are cached by default, so we don't have to shell out to
|
59
|
+
pdflatex and imagemagick all the time. Configure `cache_dir` to store the
|
60
|
+
files somewhere safe, otherwise a tempdir is created and used.
|
61
|
+
|
62
|
+
The application sends ETags for each generated image.
|
data/config.ru
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
$:.unshift 'lib'
|
2
|
+
require 'logger'
|
3
|
+
require 'rack/conditionalget'
|
2
4
|
require 'texrack'
|
3
5
|
|
6
|
+
Texrack.config[:cache_dir] = File.join(File.dirname(__FILE__), 'tmp', 'cache')
|
7
|
+
Texrack.config[:logger] = Logger.new('log/texrack.log')
|
8
|
+
|
9
|
+
use Rack::ConditionalGet
|
4
10
|
run Texrack::Endpoint.new
|
data/lib/texrack.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
|
1
3
|
require 'texrack/version'
|
4
|
+
require 'texrack/output_file'
|
2
5
|
require 'texrack/latex_to_pdf'
|
3
6
|
require 'texrack/pdf_to_png'
|
4
7
|
require 'texrack/endpoint'
|
@@ -12,7 +15,8 @@ module Texrack
|
|
12
15
|
@config ||= {
|
13
16
|
pdflatex: "pdflatex",
|
14
17
|
convert: "convert",
|
15
|
-
logger: nil
|
18
|
+
logger: nil,
|
19
|
+
cache_dir: Dir.mktmpdir
|
16
20
|
}
|
17
21
|
end
|
18
22
|
end
|
data/lib/texrack/endpoint.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'erb'
|
3
|
+
require 'digest/sha1'
|
3
4
|
|
4
5
|
module Texrack
|
5
6
|
class Endpoint < Sinatra::Base
|
6
7
|
enable :logging
|
7
|
-
set :
|
8
|
-
set :
|
8
|
+
set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
|
9
|
+
set :public_folder, Proc.new { "#{root}/assets" }
|
10
|
+
set :views, Proc.new { "#{root}/views" }
|
9
11
|
|
10
12
|
get '/' do
|
11
|
-
if data !=
|
13
|
+
if data != ''
|
12
14
|
render_png
|
13
15
|
else
|
14
16
|
erb :form
|
@@ -21,14 +23,21 @@ module Texrack
|
|
21
23
|
|
22
24
|
def render_png
|
23
25
|
content_type 'image/png'
|
26
|
+
etag digest
|
27
|
+
cache_control :public, max_age: 60 * 60 * 24 * 365
|
28
|
+
expires 60 * 60 * 24 * 365
|
24
29
|
|
25
30
|
begin
|
26
|
-
output =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
output = Texrack::OutputFile.new(digest)
|
32
|
+
if output.exists?
|
33
|
+
send_file output, disposition: :inline
|
34
|
+
else
|
35
|
+
pdf_source = erb :latex
|
36
|
+
pdf = Texrack::LatexToPdf.new(pdf_source, logger).generate_pdf
|
37
|
+
png = Texrack::PdfToPng.new(pdf, logger).to_file(output)
|
38
|
+
output.finish
|
39
|
+
send_file png, disposition: :inline
|
40
|
+
end
|
32
41
|
rescue Texrack::LatexFailedError
|
33
42
|
send_static_error "latex-failed.png"
|
34
43
|
rescue Texrack::LatexNotFoundError
|
@@ -46,6 +55,7 @@ module Texrack
|
|
46
55
|
end
|
47
56
|
|
48
57
|
def send_static_error(filename)
|
58
|
+
headers['ETag'] = nil
|
49
59
|
send_file File.join(settings.public_folder, filename), {
|
50
60
|
disposition: :inline,
|
51
61
|
status: error_status
|
@@ -72,9 +82,17 @@ module Texrack
|
|
72
82
|
params[:data].to_s.strip
|
73
83
|
end
|
74
84
|
|
85
|
+
def digest
|
86
|
+
@digest ||= Digest::SHA1.hexdigest("#{data}:#{math_mode?}:#{packages_source}")
|
87
|
+
end
|
88
|
+
|
89
|
+
def packages_source
|
90
|
+
params[:packages].to_s.strip
|
91
|
+
end
|
92
|
+
|
75
93
|
def packages
|
76
94
|
found = {}
|
77
|
-
|
95
|
+
packages_source.split("|").each do |package|
|
78
96
|
details = package.match /(?:\[([^\]]+)\])?([A-Za-z]+)/
|
79
97
|
found[details[2]] = details[1]
|
80
98
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class Texrack::OutputFile
|
4
|
+
def initialize(digest)
|
5
|
+
@digest = digest
|
6
|
+
FileUtils.mkdir_p file_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def path
|
10
|
+
file
|
11
|
+
end
|
12
|
+
alias_method :to_path, :path
|
13
|
+
|
14
|
+
def exists?
|
15
|
+
File.readable?(file) && File.size?(file)
|
16
|
+
end
|
17
|
+
|
18
|
+
def finish
|
19
|
+
FileUtils.chmod(0644, file)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :digest
|
25
|
+
|
26
|
+
def file
|
27
|
+
File.join(file_path, "#{digest}.png")
|
28
|
+
end
|
29
|
+
|
30
|
+
def file_path
|
31
|
+
File.join(cache_dir, *partition)
|
32
|
+
end
|
33
|
+
|
34
|
+
def cache_dir
|
35
|
+
Texrack.config[:cache_dir]
|
36
|
+
end
|
37
|
+
|
38
|
+
def partition
|
39
|
+
digest.scan(/.{3}/).first(3)
|
40
|
+
end
|
41
|
+
end
|
data/lib/texrack/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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:
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -55,14 +55,15 @@ files:
|
|
55
55
|
- lib/texrack.rb
|
56
56
|
- lib/texrack/endpoint.rb
|
57
57
|
- lib/texrack/latex_to_pdf.rb
|
58
|
+
- lib/texrack/output_file.rb
|
58
59
|
- lib/texrack/pdf_to_png.rb
|
59
|
-
- lib/texrack/static/latex-failed.png
|
60
|
-
- lib/texrack/static/missing-convert.png
|
61
|
-
- lib/texrack/static/missing-pdflatex.png
|
62
60
|
- lib/texrack/version.rb
|
63
|
-
- lib/texrack/views/form.erb
|
64
|
-
- lib/texrack/views/latex.erb
|
65
61
|
- texrack.gemspec
|
62
|
+
- web/assets/latex-failed.png
|
63
|
+
- web/assets/missing-convert.png
|
64
|
+
- web/assets/missing-pdflatex.png
|
65
|
+
- web/views/form.erb
|
66
|
+
- web/views/latex.erb
|
66
67
|
homepage: https://github.com/PerfectlyNormal/texrack
|
67
68
|
licenses:
|
68
69
|
- MIT
|
@@ -84,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
85
|
version: '0'
|
85
86
|
requirements: []
|
86
87
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.1.
|
88
|
+
rubygems_version: 2.1.11
|
88
89
|
signing_key:
|
89
90
|
specification_version: 4
|
90
91
|
summary: Rack microservice to render LaTeX as PNG
|
metadata.gz.asc
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
-----BEGIN PGP SIGNATURE-----
|
2
|
-
Version: GnuPG/MacGPG2 v2.0.
|
2
|
+
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
|
3
3
|
Comment: GPGTools - http://gpgtools.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