texrack 0.3.0 → 0.5.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: 4aea4cde344abda376e29d4adbb6415644d75d67
4
- data.tar.gz: c2d87b2eee6ea9963d8c41cc0710775a3f3d948c
3
+ metadata.gz: d6317e26ded8ae7d0129684554de7d88e69a1e8b
4
+ data.tar.gz: 69b53f08a52c1fc208682845663ae7fb7e07a4b0
5
5
  SHA512:
6
- metadata.gz: 48f349be4326492b76c5908c1c9f4b726d5b7e57c47892bd93ca52aa38b0111d316ff00236b0ed0c157b11b299fbd0b90154b75a1a8f9abf2649e63e53cc9a52
7
- data.tar.gz: 0eaab0480d74bf0e6602057bd9fce79e259832ed69e589240e0a9f9654ac58b97b2b2938aef9c1c8bcdf40c5b2235dd2331e47090892f6adbd1c30d349e6eec2
6
+ metadata.gz: d111375ea46c941da09ae7e24041b738e333810eb993806b818de9212ec139f2dee4d3499e2017ba93ecd8ac077606107357354448ae5df0263084b7df10cfa7
7
+ data.tar.gz: b54563309cf3d815c712ec0d3fba2ed718895a390db4a0b906af8c1bed7681199b9aa1849a14cccc4cc800485a232f3ac7c3391720d3d1bdcfe9c752e07ac985
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
- iQIcBAABAgAGBQJSePZ+AAoJEH1ncb0Txu7XyKoQAI9383kh4LNjO6W23K5ipagY
6
- dcSrmSvn1XDIJvAJyFtQpBaGVxdcGJW8U5E8LCEhD3UE93mOfgC86HGuQLO0/0EC
7
- M87VvLp2rtwa+FoEF+e6Y5FYLahuLFlSnomDDhWwAcU85eazr3ARSprdx6e8iH3B
8
- N0xplsS1mpoBbZ1tn4pAinDx2IU/iqnqYadPgMPpqJ3+jjDKZn9vNTCbpwLphVOA
9
- xbGWJiu1CKWs1gCUWcwR9uUM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n7KOe5Yi4L1t10Fi855cj
14
+ m74/7z1kjKQX3+f6PZ71DZohw9+1LoLvNjpS1cYiYZBuiLK2L8Bq0TyidopLNwQ5
15
+ L5UbiBSdN/RNU3CTswcmD2Qnp2eSsMBVRTdi/28PlgRrD3oBQcbcrT1SejrhgNFq
16
+ MfMo+KltUt97YyZvnuBL
17
+ =VOKf
18
18
  -----END PGP SIGNATURE-----
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.5.0 / 2013-11-07
2
+
3
+ * A typo snuck in, referencing FileText instead of FileTest
4
+ * Make the generated PNG readable by the world, to avoid potential issues
5
+ with serving the file.
6
+ * Allow passing in a own logger, e.g. `Rails.logger`
7
+
8
+ # 0.4.0 / 2013-11-07
9
+
10
+ * Allow configuring where to find binaries
11
+
1
12
  # 0.3.0 / 2013-11-05
2
13
 
3
14
  * Allow forcing the response status to 200 OK
data/README.md CHANGED
@@ -4,11 +4,27 @@ Simple Rack middleware to render LaTeX to PNGs on the fly.
4
4
 
5
5
  ## Requirements
6
6
 
7
- * `pdflatex` must exist in `$PATH`
8
- * `convert` (from ImageMagick) must exist in `$PATH`
7
+ * `pdflatex` must be installed
8
+ * `convert` (from ImageMagick) must be installed
9
9
 
10
10
  ## Configuration
11
11
 
12
+ If "pdflatex" or "convert" is not available in `PATH`, you can change
13
+ `Texrack.config` and specify where to find them.
14
+
15
+ If you want a custom logger, set `Texrack.config[:logger]` to anything
16
+ responding to `#warn`, `#debug`, `#info` and so on.
17
+ For example `Rails.logger` if mounting inside a Rails application.
18
+
19
+ The default configuration is
20
+ ```ruby
21
+ Texrack.config = {
22
+ pdflatex: "pdflatex",
23
+ convert: "convert",
24
+ logger: nil,
25
+ }
26
+ ```
27
+
12
28
  ## Usage
13
29
 
14
30
  Either POST or GET to the configured URL with `data` set to the LaTeX source to
@@ -5,6 +5,7 @@ module Texrack
5
5
  class Endpoint < Sinatra::Base
6
6
  enable :logging
7
7
  set :public_folder, File.dirname(__FILE__) + '/static'
8
+ set :views, File.dirname(__FILE__) + '/views'
8
9
 
9
10
  get '/' do
10
11
  if data != ""
@@ -27,6 +28,7 @@ module Texrack
27
28
  pdf = Texrack::LatexToPdf.new(pdf_source, logger).generate_pdf
28
29
  png = Texrack::PdfToPng.new(pdf, logger).to_file(output)
29
30
  send_file png, disposition: :inline
31
+ File.chmod(0644, png)
30
32
  rescue Texrack::LatexFailedError
31
33
  send_static_error "latex-failed.png"
32
34
  rescue Texrack::LatexNotFoundError
@@ -39,6 +41,10 @@ module Texrack
39
41
  end
40
42
 
41
43
  helpers do
44
+ def logger
45
+ @logger ||= (Texrack.config[:logger] || Logger.new(STDERR))
46
+ end
47
+
42
48
  def send_static_error(filename)
43
49
  send_file File.join(settings.public_folder, filename), {
44
50
  disposition: :inline,
@@ -24,8 +24,8 @@ class Texrack::LatexToPdf
24
24
  Dir.chdir File.dirname(input)
25
25
  args = %w[-shell-escape -interaction batchmode -halt-on-error] + [input.path]
26
26
 
27
- logger.debug "Texrack executing: pdflatex #{args}"
28
- exec "pdflatex", *args
27
+ logger.debug "Texrack executing: #{command} #{args}"
28
+ exec command, *args
29
29
  rescue
30
30
  logger.error "#{$!.message}:\n#{$!.backtrace.join("\n")}\n"
31
31
  ensure
@@ -46,7 +46,12 @@ class Texrack::LatexToPdf
46
46
  output
47
47
  end
48
48
 
49
+ def command
50
+ Texrack.config[:pdflatex] || "pdflatex"
51
+ end
52
+
49
53
  def has_pdflatex?
54
+ return true if File.exists?(command) && FileTest.executable?(command)
50
55
  ENV["PATH"].split(':').any? {|x| FileTest.executable? "#{x}/pdflatex" }
51
56
  end
52
57
  private :has_pdflatex?
@@ -6,10 +6,14 @@ class Texrack::PdfToPng
6
6
  def initialize(pdf_path, logger)
7
7
  @pdf_path = pdf_path
8
8
  @logger = logger
9
- @line = Cocaine::CommandLine.new("convert",
9
+ @line = Cocaine::CommandLine.new(command,
10
10
  "-density 300x300 -quality 90 :in :out", logger: logger)
11
11
  end
12
12
 
13
+ def command
14
+ Texrack.config[:convert] || "convert"
15
+ end
16
+
13
17
  def to_file(file)
14
18
  line.run(in: pdf_path, out: file.path)
15
19
  file.path
@@ -1,3 +1,3 @@
1
1
  module Texrack
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/texrack.rb CHANGED
@@ -7,4 +7,12 @@ module Texrack
7
7
  class LatexNotFoundError < StandardError; end
8
8
  class ConvertNotFoundError < StandardError; end
9
9
  class LatexFailedError < StandardError; end
10
+
11
+ def self.config
12
+ @config ||= {
13
+ pdflatex: "pdflatex",
14
+ convert: "convert",
15
+ logger: nil
16
+ }
17
+ end
10
18
  end
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
- iQIcBAABAgAGBQJSePZ+AAoJEH1ncb0Txu7XvuoP/0w4NpPnGkp70nQUjdCV4OWv
6
- xYW/7mxq48b/63uLflAQNMtuuySG4bc73C8eYVlvFF39qsxopHmJUDBeh1aQUiW4
7
- 02lv50CqInokYs2CT3grJpGv97YGVy8JnbmP0W2lRdZnp/GdxrRTKEr9IdpsIn60
8
- /PL2pMd94c4g0we5wngis3t/PoFyHLrIEVlixVmF6ofM1BAArZb3JqhHEFyxcuYT
9
- 7/ZKeUkZRbUKAQkwBiTqQzdPujWqcLQDkNWZZWdhie4P/xqK0Uj9kwqLAOFY2mAk
10
- E/K79WFrqwLcKLerwCIqiU+hjIuJpavvbBD8cwwgboYCbSqzC+NbxwDuzPnkB1vO
11
- wEU+rU885KtxI1qKhFXSuHAitvOATHabaOyvQlHn+iexZUtt91SbobwV+sqg0Eda
12
- F42VJ0xnZZrVYjOLfLwkj3PXj5QVTRP2RfnXOVE7Vwqe8K4iSXS4ahQKaRLRQlwZ
13
- OZIwXRk+c8fXsKgXSbiXMxIKWxbh79pTBJ7myFp72L4iN47pZ6z3agBTc+IqCa5Q
14
- 79pNhXRWLAbeTXu6i6+H08EHpDMm7dGBFPb2cmV4KgLjfhZyna1fdnkWqKZP6p3T
15
- wHIxq0tphfvhHdfcYoUcD9iHROn14i0f5z+MpEpMbQvVDzAQfpskRUx6spwyXyIG
16
- ubc4VCkcsK7pxxZRcflN
17
- =km1K
5
+ iQIcBAABAgAGBQJSe5GYAAoJEH1ncb0Txu7XYhcP/1OiDgOwvI2ID2AUtaGhi1yp
6
+ JqsK/zcaBJtf6+2dSCACekxxVe74n7DwI9j4yu2egR7dgFfB1XnG4cg4FFxaOnIK
7
+ 1UW7JQ8+DFHDLEOIzKgg9OECJtvyJQSvZIuDINgOl/R5myK4a5U85U5Ico9mN95Q
8
+ k/6iE9t3nKGYlzUZ/McHw6TiIC9LuGfjvCUgTKmWzkSgWRpXj7tV0N8afvz9PHo0
9
+ doBjux5osSanEvjGapa0tf2m+0r5drrad6p7qcBARCTEmRPqzljoxIAOSfA9Abv6
10
+ enb2clhWAc8UIwt5pud3yuIIcI66Zp56ZWoUyil1JC+ciXer7LHwYZFF6yuOF/L+
11
+ idX4aqF/REtXw8xAzu8QyM6qiD2abH89mKVOaOaS5VvnciN4gwdcDyMBr6AOgRG1
12
+ vwuPtJlA4n4Rjs1CxWLFdsd/RwGXioQmdXYXdzQQ/ocwatH50UE3WgylRwgwX2kP
13
+ 2BEVkpSdCeikFZFWhsfJwYgIoEV0q2p8UiS45nCEnDA+GV2DcW/7VCSZb63wZ2p3
14
+ 0wRaanrZYC59/aJ6apy6VETMLsMKnau5+jKpooWhdl051roGrBkR8Si0SJOMTxWU
15
+ hBhbJgO9/1UggMCErDJHHkoGYxrXP9El72Y5eDOcf4v5VphF+yQ6sGhhnONVO3TO
16
+ RD0PZqRgH62ieTOtjH01
17
+ =2+ib
18
18
  -----END PGP SIGNATURE-----
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.3.0
4
+ version: 0.5.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-05 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
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
- iQIcBAABAgAGBQJSePZ9AAoJEH1ncb0Txu7XD9wP/26fhxMMP+dioXtmzUmPGm5S
6
- BCWF8BztPSrydWQyvFDrjE02C/t9NX71p428L6Qz+xgIb4/8i/dcFVjVwSUPBhcX
7
- dnYUqEnbVnJFU7SkKAU29+cp1lntAyR13D3vb6WquYQNasOlRlFXVCjC7miYWIPE
8
- yWhP5XRkfsnz4N9GflMd5Vt3zGn1BBePMWAvgOgZ464OWF/pMIn7qf6ITB/dKoHo
9
- 4UAXEmhAESmrXgGnAWNSde0Dy6HIrszWcuOOk6i+cGCR74VjnfAM7y9882O92VxI
10
- CtaCTULZdgJaz8pEKtbIL2hKfo+EMfvmKib95ZGZbWTjRLuocGv4Frqoxnm6lIBT
11
- NIR+vKcwH4p9SOyLWVpfeMs0hTGhAUddGv5MuxptqHWUUZysGB15SxkY2prfdYBX
12
- qLGIGOZZd5dPIRdmpFTScW4rduvROybXoPpXnoALMU+X/1B5+pFFhq6GPY8xV1gz
13
- TQoVQfv2wS/IKSf1wKMc43u4lEwAE6SKu50n6lQ0McDgadoY8QSri5S5IdCE17Rj
14
- 2fLK9bjIxOUu1YB0M7gM6py/HONtdhyFi+m7hrOz3pR5n4p+s4wz4JlGnvaFx0mv
15
- W2Vigv62cA3KKqN0dBs+X71KQ9HWlqSGaDcGTjYUn84ZiiN28/loT4iK/XdaZHQI
16
- 9udoJjCfPa9bgMNk+yZw
17
- =V8na
5
+ iQIcBAABAgAGBQJ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