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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c548f224b7eb99f58da603aec01ccbbb380d03f
4
- data.tar.gz: 7428ec2df6923cdd1feb8e9d459f94f8de852404
3
+ metadata.gz: b523a5a1e75e256049dfb84edf012060fdb50337
4
+ data.tar.gz: 90e7971413c416e2d5e2318878a0e6313ec5332c
5
5
  SHA512:
6
- metadata.gz: 6cd83ec84cdf8992a7d9f546e38c0587c26ccfd762f1c5921b1f5d8fc640fed2d49c176468fdd1b0eb63aa57115f654fa112c08bb4e0efb98a928b129eb6cc78
7
- data.tar.gz: c9b077643d63b19eb5c0d099fb3af506691584ec8140cce315ef126af2c232f51fe244d75380858763373ca51d9c811b89ddcfe1b61e85e4e3f5ea893dde616e
6
+ metadata.gz: e46b080448db5c47d3d18453bdc47addc72553bd5f4ce18379787231a5537f214e8c1fcdaa95ae3f8094ddd698f57a7980eec94fd1b0869292d6fcb98f8fa98d
7
+ data.tar.gz: bbc0d57800af7de61d334a3a08215c3863f3cacfb0d1e7cf643da9744a40496f21a4162c3e6fa85e7320c0029b1496e9320e0162273db9be60a2ffb0fb26e6f5
@@ -1,18 +1,18 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
2
+ Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQIcBAABAgAGBQJSe5JQAAoJEH1ncb0Txu7XdFoP/2EPuG+v/TdE5XCTcMnZNByN
6
- pRZwXygziaEVzTeFG+OSzb7c7tCX9a2qPgeJ8B4q6KmuUAGSF2V4hiPOOOKEHvIX
7
- yAj00EN0pZ3crXvZvD8fwAtMKKw8C0TxyoeKJGqOk14+2cKi6J253O/I2nHkxwic
8
- dxrVSjKKuD1PZ6zKgaGBJAG+SGzuIrrXzRMQ9SyYjN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p5oVDOv7M+6R9
13
+ uYDTR5hfZ+GgfYIPADr8q1f+ffVWWNQamJpzC6/Ho/glk9p+6q4YwY1Jm/GA6LD2
14
+ Xbi+lo4d/nNrQeSwoamGg/6djvuwRc3svBdIECyNtFRjqoBhpJgGdBiUMbQ2qPaE
15
+ zcJMJWswIydCZ162hLRZboK1wUFgj5iJtr0bt1WJZ7n/wbFsSR7b1B07N6/dCOJR
16
+ +VAEV0AU2GpYhDutUm43
17
+ =ASTb
18
18
  -----END PGP SIGNATURE-----
data.tar.gz.asc CHANGED
@@ -1,18 +1,18 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG/MacGPG2 v2.0.20 (Darwin)
2
+ Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQIcBAABAgAGBQJSe5JPAAoJEH1ncb0Txu7XjegP/0AGxaGl5t3CfkDanymq4Bk3
6
- iW09BXNHk5PLIqNsanDCzsn3mmFO+s5N4JFkhum5QOJgyrgsWlMpyseCsFbIPgaw
7
- b1V1Oj3qbvbxqFVnWXZqYNDmEIuyTz53IThrmwiwnvYtU80uQvaPtxpkvecLvjUD
8
- GZC+O8CM7/+WQPvvXcRb/MwrowV0HDaAl0hgDnJIrdWqThE0ZAaWQCFJZ9TKeHu5
9
- z0lSDXYmItNZL8YPvu/fSkOJV4unDn0ZPAQ9XAfWbrTmbJ1bg6Fa8lWnpFsJI187
10
- Rpp20dT+qm0yshWhWAHijmmxj2Q88z+VEFpg/Rzi0PzqfXym2jYi+acerh9wb4Ku
11
- Wsqsb8uwtO/Nn7QlZXe+v9BiztqwCfah66WNQdQbYkdred06jn09hqmXgZ0dBpAS
12
- ovZaES30BZMibCs8NIhwP96thOK0K80gTyphPoSMRsrv9q4T8PIiWcJnD4SOjC6f
13
- 7slTEmowji2c430cJ6ANF246hP4vtYw7hfRWkBA3oGTDE6KMLwtCh8BxN+JSd8C3
14
- NoEjhOa2OuS4Zr09PmNd7k80R2qXYM0xpr7KM38bEwzkeAlh/dsSlxAYH5gpIEj0
15
- eBHpgK6ihlBTEl6wGKRsqgxdPJgnR0Ri9H54GjeUF82JTE3VTQu4IvAReg0D9bSW
16
- 2B4tVsicvc5oWkWL7RSz
17
- =MU1d
5
+ iQIcBAABAgAGBQJTqDsmAAoJEH1ncb0Txu7XtUMP/RrEIOUh2KBGm9gl/STVGQZ7
6
+ VPdAYz3Ze00Kqe0fxwuBaHBzliLoW+PYv3S8zg7iUkQrHbQrcA6X4BydknsLQBnA
7
+ pLhyO/GXoMWawJTwf1PdnVhAPIkbdHy0pZ0F/FM9JJtakXS7TDNrnvTkaJaZ+3CY
8
+ pvYUIEj5qeCg9+cLbSPLKX/uYnQ6a7eR9dJCE3LrkAIj79ATXMUMEzDUNm3wifIE
9
+ vgfcjz/D7gRedqD6d8OVLyf2FwIdHSxCkDE9ZqH1a9c/zkCPQEKJuvnyjnZshaqX
10
+ JuNIhV0S/7sAVEx5szAHu3lJP1iLsHbFTHOxNQu7ChOz9rln7vXeveoAB7UsSiXC
11
+ /tNYBMYY9h3MJyrVUi7+Sj9mD/Rs9OfIr+hfAGFLr1jZIyiIDG6JSd1GBF32p14/
12
+ LoLsLnXRAsWAo+YS4VjeHPJBKSdCBPt+zM0o19V79rcJBLU4XFDPk0FSl+AHEa8V
13
+ Yr9bYJ+3A40567CbRRslGTrJBmQ/4VTM9hzbFaUzMBS2hxnEbXd68zWP/GAi1RwU
14
+ v5V0Guwu9ZXBMupBRGARUWAIiYvmQ1/x6vIZxufpsXBKttgysHQM0LSiV73PMhme
15
+ V2BkNlCKm64eHUrIix1kMMmJS769p+dr0ExdEqQWMwY7ASQFA5TzytQNA+6/AlW4
16
+ flr7SfGnDJUjTT2JkATk
17
+ =s9QM
18
18
  -----END PGP SIGNATURE-----
@@ -1,3 +1,7 @@
1
+ # 0.6.0 / unreleased
2
+
3
+ * Cache the generated images and return proper ETags
4
+
1
5
  # 0.5.1 / 2013-11-07
2
6
 
3
7
  * Oh, git. And stupid authors…
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
@@ -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
@@ -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 :public_folder, File.dirname(__FILE__) + '/static'
8
- set :views, File.dirname(__FILE__) + '/views'
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 = Tempfile.new(["texrack-output", ".png"])
27
- pdf_source = erb :latex
28
- pdf = Texrack::LatexToPdf.new(pdf_source, logger).generate_pdf
29
- png = Texrack::PdfToPng.new(pdf, logger).to_file(output)
30
- File.chmod(0644, png)
31
- send_file png, disposition: :inline
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
- params[:packages].to_s.split("|").each do |package|
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
@@ -1,3 +1,3 @@
1
1
  module Texrack
2
- VERSION = "0.5.1"
2
+ VERSION = '0.6.0'
3
3
  end
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.5.1
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: 2013-11-07 00:00:00.000000000 Z
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.10
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.20 (Darwin)
2
+ Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQIcBAABAgAGBQJSe5JPAAoJEH1ncb0Txu7XtAcQALFWIZltEa6fQE3/yU8suh4n
6
- LvALFlrBo4z3eQuuhtTlSdFnYX+Bq/D5QqdvNuRMMi+VwtrXdgQ1igH0ks4S29fP
7
- L1fEUzALax3lRoBSERM2WGAB7ogDKpBt3+3mBeZQtzxCZYuhytHwrFdknHpDDwMZ
8
- n53rz4l5hFZVyiaM2jdjtv3Ul1HrKun9emd4bCfirSsZ04kRF72qA2DAnpUPj2lR
9
- pk9uhcirxyHrHAsNYTWYgQJ1lPe67GRQF/b/uaDXXOSrYNMTvZa0FhJK7fvWHYZY
10
- FPBiFYbmyuNlOQw1WRFQr8woNc6jlnqiiJxab6CIS+l881sqcrhVarEyDLojAQQ2
11
- M8zp5c6puHzW7leWoqxOkFkVV2oEvjfKS2cutDe8y3XjhxL+qf3pHOMYEFBdloKi
12
- rwiUHOW0jD1yoAFuHYN5Nu3vSM6sEEUL1A9pEg/jC9xrwdbqxn8fOAkJ77VND5zF
13
- zGrBOMYDPUydy5oSIhEH5qVQvS04cwuMp0KUr12T7KJ6kZUnblmwZ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