texd 0.3.2 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,74 +1,74 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- texd (0.3.2)
4
+ texd (0.4.2)
5
5
  multipart-post (~> 2.0)
6
6
  rails (>= 6.0, < 8)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.2.3)
12
- actionpack (= 7.0.2.3)
13
- activesupport (= 7.0.2.3)
11
+ actioncable (7.0.3)
12
+ actionpack (= 7.0.3)
13
+ activesupport (= 7.0.3)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.2.3)
17
- actionpack (= 7.0.2.3)
18
- activejob (= 7.0.2.3)
19
- activerecord (= 7.0.2.3)
20
- activestorage (= 7.0.2.3)
21
- activesupport (= 7.0.2.3)
16
+ actionmailbox (7.0.3)
17
+ actionpack (= 7.0.3)
18
+ activejob (= 7.0.3)
19
+ activerecord (= 7.0.3)
20
+ activestorage (= 7.0.3)
21
+ activesupport (= 7.0.3)
22
22
  mail (>= 2.7.1)
23
23
  net-imap
24
24
  net-pop
25
25
  net-smtp
26
- actionmailer (7.0.2.3)
27
- actionpack (= 7.0.2.3)
28
- actionview (= 7.0.2.3)
29
- activejob (= 7.0.2.3)
30
- activesupport (= 7.0.2.3)
26
+ actionmailer (7.0.3)
27
+ actionpack (= 7.0.3)
28
+ actionview (= 7.0.3)
29
+ activejob (= 7.0.3)
30
+ activesupport (= 7.0.3)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  net-imap
33
33
  net-pop
34
34
  net-smtp
35
35
  rails-dom-testing (~> 2.0)
36
- actionpack (7.0.2.3)
37
- actionview (= 7.0.2.3)
38
- activesupport (= 7.0.2.3)
36
+ actionpack (7.0.3)
37
+ actionview (= 7.0.3)
38
+ activesupport (= 7.0.3)
39
39
  rack (~> 2.0, >= 2.2.0)
40
40
  rack-test (>= 0.6.3)
41
41
  rails-dom-testing (~> 2.0)
42
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.2.3)
44
- actionpack (= 7.0.2.3)
45
- activerecord (= 7.0.2.3)
46
- activestorage (= 7.0.2.3)
47
- activesupport (= 7.0.2.3)
43
+ actiontext (7.0.3)
44
+ actionpack (= 7.0.3)
45
+ activerecord (= 7.0.3)
46
+ activestorage (= 7.0.3)
47
+ activesupport (= 7.0.3)
48
48
  globalid (>= 0.6.0)
49
49
  nokogiri (>= 1.8.5)
50
- actionview (7.0.2.3)
51
- activesupport (= 7.0.2.3)
50
+ actionview (7.0.3)
51
+ activesupport (= 7.0.3)
52
52
  builder (~> 3.1)
53
53
  erubi (~> 1.4)
54
54
  rails-dom-testing (~> 2.0)
55
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.2.3)
57
- activesupport (= 7.0.2.3)
56
+ activejob (7.0.3)
57
+ activesupport (= 7.0.3)
58
58
  globalid (>= 0.3.6)
59
- activemodel (7.0.2.3)
60
- activesupport (= 7.0.2.3)
61
- activerecord (7.0.2.3)
62
- activemodel (= 7.0.2.3)
63
- activesupport (= 7.0.2.3)
64
- activestorage (7.0.2.3)
65
- actionpack (= 7.0.2.3)
66
- activejob (= 7.0.2.3)
67
- activerecord (= 7.0.2.3)
68
- activesupport (= 7.0.2.3)
59
+ activemodel (7.0.3)
60
+ activesupport (= 7.0.3)
61
+ activerecord (7.0.3)
62
+ activemodel (= 7.0.3)
63
+ activesupport (= 7.0.3)
64
+ activestorage (7.0.3)
65
+ actionpack (= 7.0.3)
66
+ activejob (= 7.0.3)
67
+ activerecord (= 7.0.3)
68
+ activesupport (= 7.0.3)
69
69
  marcel (~> 1.0)
70
70
  mini_mime (>= 1.1.0)
71
- activesupport (7.0.2.3)
71
+ activesupport (7.0.3)
72
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
73
73
  i18n (>= 1.6, < 2)
74
74
  minitest (>= 5.1)
@@ -76,7 +76,7 @@ GEM
76
76
  builder (3.2.4)
77
77
  byebug (11.1.3)
78
78
  coderay (1.1.3)
79
- combustion (1.3.5)
79
+ combustion (1.3.7)
80
80
  activesupport (>= 3.0.0)
81
81
  railties (>= 3.0.0)
82
82
  thor (>= 0.14.6)
@@ -89,8 +89,7 @@ GEM
89
89
  activesupport (>= 5.0)
90
90
  i18n (1.10.0)
91
91
  concurrent-ruby (~> 1.0)
92
- io-wait (0.2.1)
93
- loofah (2.15.0)
92
+ loofah (2.18.0)
94
93
  crass (~> 1.0.2)
95
94
  nokogiri (>= 1.5.9)
96
95
  mail (2.7.1)
@@ -98,8 +97,9 @@ GEM
98
97
  marcel (1.0.2)
99
98
  method_source (1.0.0)
100
99
  mini_mime (1.1.2)
101
- minitest (5.15.0)
102
- multipart-post (2.1.1)
100
+ mini_portile2 (2.8.0)
101
+ minitest (5.16.1)
102
+ multipart-post (2.2.3)
103
103
  net-imap (0.2.3)
104
104
  digest
105
105
  net-protocol
@@ -108,15 +108,17 @@ GEM
108
108
  digest
109
109
  net-protocol
110
110
  timeout
111
- net-protocol (0.1.2)
112
- io-wait
111
+ net-protocol (0.1.3)
113
112
  timeout
114
113
  net-smtp (0.3.1)
115
114
  digest
116
115
  net-protocol
117
116
  timeout
118
117
  nio4r (2.5.8)
119
- nokogiri (1.13.3-x86_64-linux)
118
+ nokogiri (1.13.6)
119
+ mini_portile2 (~> 2.8.0)
120
+ racc (~> 1.4)
121
+ nokogiri (1.13.6-x86_64-linux)
120
122
  racc (~> 1.4)
121
123
  pry (0.13.1)
122
124
  coderay (~> 1.1)
@@ -125,31 +127,31 @@ GEM
125
127
  byebug (~> 11.0)
126
128
  pry (~> 0.13.0)
127
129
  racc (1.6.0)
128
- rack (2.2.3)
129
- rack-test (1.1.0)
130
- rack (>= 1.0, < 3)
131
- rails (7.0.2.3)
132
- actioncable (= 7.0.2.3)
133
- actionmailbox (= 7.0.2.3)
134
- actionmailer (= 7.0.2.3)
135
- actionpack (= 7.0.2.3)
136
- actiontext (= 7.0.2.3)
137
- actionview (= 7.0.2.3)
138
- activejob (= 7.0.2.3)
139
- activemodel (= 7.0.2.3)
140
- activerecord (= 7.0.2.3)
141
- activestorage (= 7.0.2.3)
142
- activesupport (= 7.0.2.3)
130
+ rack (2.2.3.1)
131
+ rack-test (2.0.1)
132
+ rack (>= 1.3)
133
+ rails (7.0.3)
134
+ actioncable (= 7.0.3)
135
+ actionmailbox (= 7.0.3)
136
+ actionmailer (= 7.0.3)
137
+ actionpack (= 7.0.3)
138
+ actiontext (= 7.0.3)
139
+ actionview (= 7.0.3)
140
+ activejob (= 7.0.3)
141
+ activemodel (= 7.0.3)
142
+ activerecord (= 7.0.3)
143
+ activestorage (= 7.0.3)
144
+ activesupport (= 7.0.3)
143
145
  bundler (>= 1.15.0)
144
- railties (= 7.0.2.3)
146
+ railties (= 7.0.3)
145
147
  rails-dom-testing (2.0.3)
146
148
  activesupport (>= 4.2.0)
147
149
  nokogiri (>= 1.6)
148
- rails-html-sanitizer (1.4.2)
150
+ rails-html-sanitizer (1.4.3)
149
151
  loofah (~> 2.3)
150
- railties (7.0.2.3)
151
- actionpack (= 7.0.2.3)
152
- activesupport (= 7.0.2.3)
152
+ railties (7.0.3)
153
+ actionpack (= 7.0.3)
154
+ activesupport (= 7.0.3)
153
155
  method_source
154
156
  rake (>= 12.2)
155
157
  thor (~> 1.0)
@@ -164,10 +166,10 @@ GEM
164
166
  rspec-expectations (3.11.0)
165
167
  diff-lcs (>= 1.2.0, < 2.0)
166
168
  rspec-support (~> 3.11.0)
167
- rspec-mocks (3.11.0)
169
+ rspec-mocks (3.11.1)
168
170
  diff-lcs (>= 1.2.0, < 2.0)
169
171
  rspec-support (~> 3.11.0)
170
- rspec-rails (5.1.1)
172
+ rspec-rails (5.1.2)
171
173
  actionpack (>= 5.2)
172
174
  activesupport (>= 5.2)
173
175
  railties (>= 5.2)
@@ -176,17 +178,18 @@ GEM
176
178
  rspec-mocks (~> 3.10)
177
179
  rspec-support (~> 3.10)
178
180
  rspec-support (3.11.0)
179
- strscan (3.0.1)
181
+ strscan (3.0.3)
180
182
  thor (1.2.1)
181
- timeout (0.2.0)
183
+ timeout (0.3.0)
182
184
  tzinfo (2.0.4)
183
185
  concurrent-ruby (~> 1.0)
184
186
  websocket-driver (0.7.5)
185
187
  websocket-extensions (>= 0.1.0)
186
188
  websocket-extensions (0.1.5)
187
- zeitwerk (2.5.4)
189
+ zeitwerk (2.6.0)
188
190
 
189
191
  PLATFORMS
192
+ ruby
190
193
  x86_64-linux
191
194
 
192
195
  DEPENDENCIES
@@ -132,7 +132,7 @@ module Texd
132
132
 
133
133
  Dynamic = Struct.new(:name, :contents) do
134
134
  def to_upload_io(**)
135
- UploadIO.new(StringIO.new(contents), nil, name).tap { |io|
135
+ Multipart::Post::UploadIO.new(StringIO.new(contents), nil, name).tap { |io|
136
136
  io.instance_variable_set :@original_filename, name
137
137
  }
138
138
  end
@@ -177,7 +177,7 @@ module Texd
177
177
  class File < Base
178
178
  # @api private
179
179
  def to_upload_io(**)
180
- UploadIO.new(absolute_path.open("rb"), nil, name).tap { |io|
180
+ Multipart::Post::UploadIO.new(absolute_path.open("rb"), nil, name).tap { |io|
181
181
  io.instance_variable_set :@original_filename, name
182
182
  }
183
183
  end
@@ -197,7 +197,7 @@ module Texd
197
197
  f = full ? absolute_path.open("rb") : StringIO.new(checksum)
198
198
  ct = full ? STORE_REF : USE_REF
199
199
 
200
- UploadIO.new(f, ct, name).tap { |io|
200
+ Multipart::Post::UploadIO.new(f, ct, name).tap { |io|
201
201
  io.instance_variable_set :@original_filename, name
202
202
  }
203
203
  end
data/lib/texd/client.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "net/http"
4
4
  require "net/http/post/multipart"
5
5
  require "json"
6
+ require "pp"
6
7
 
7
8
  module Texd
8
9
  class Client
@@ -39,6 +40,20 @@ module Texd
39
40
  @logs = logs
40
41
  super(message, details: details)
41
42
  end
43
+
44
+ def write_to(io)
45
+ io << "Compilation failed: #{message}\n"
46
+ if details
47
+ io.print "Details: "
48
+ PP.pp(details, io)
49
+ end
50
+
51
+ if logs
52
+ io << "Logs:\n" << logs
53
+ else
54
+ io << "Logs: not available"
55
+ end
56
+ end
42
57
  end
43
58
 
44
59
  # Raised when the texd server encountered one or more unknown file
data/lib/texd/config.rb CHANGED
@@ -27,8 +27,9 @@ module Texd
27
27
  read_timeout: ENV.fetch("TEXD_READ_TIMEOUT", 180),
28
28
  write_timeout: ENV.fetch("TEXD_WRITE_TIMEOUT", 60),
29
29
  error_format: ENV.fetch("TEXD_ERRORS", "full"),
30
- tex_engine: ENV["TEXD_ENGINE"],
31
- tex_image: ENV["TEXD_IMAGE"],
30
+ error_handler: ENV.fetch("TEXD_ERROR_HANDLER", "raise"),
31
+ tex_engine: ENV.fetch("TEXD_ENGINE", nil),
32
+ tex_image: ENV.fetch("TEXD_IMAGE", nil),
32
33
  helpers: Set.new,
33
34
  lookup_paths: [], # Rails.root.join("app/tex") is inserted in railtie.rb
34
35
  ref_cache_size: 128,
@@ -40,6 +41,13 @@ module Texd
40
41
  # Supported error formats.
41
42
  ERROR_FORMATS = %w[json full condensed].freeze
42
43
 
44
+ # Default error handlers. One might provide a custom proc, if desired.
45
+ ERROR_HANDLERS = {
46
+ "raise" => proc { |err, _doc| raise err },
47
+ "stderr" => proc { |err, _doc| err.write_to($stderr) },
48
+ "ignore" => proc { |_err, _doc| },
49
+ }.freeze
50
+
43
51
  # Supported TeX engines.
44
52
  TEX_ENGINES = %w[xelatex lualatex pdflatex].freeze
45
53
 
@@ -74,10 +82,26 @@ module Texd
74
82
  #
75
83
  # Supported values are described in ERROR_FORMATS.
76
84
  #
77
- # The default is "full" and can be overriden by the `TEXD_WRITE_TIMEOUT`
85
+ # The default is "full" and can be overriden by the `TEXD_ERRORS`
78
86
  # environment variable.
79
87
  attr_reader :error_format
80
88
 
89
+ # This setting defines how to handle Texd::Client::CompilationError errors.
90
+ #
91
+ # Supported values are:
92
+ #
93
+ # - "raise", which will not process the error,
94
+ # - "stderr", which will print the error to stderr,
95
+ # - "ignore", which will silently discard,
96
+ # - a Proc instance, which will delegate the error handling to it.
97
+ #
98
+ # The setter will lookup "raise", "stderr", and "ignore" from ERROR_HANDLERS,
99
+ # so this attribute will always be of kind Proc.
100
+ #
101
+ # The default value is "raise" and can be overridden by the `TEXD_ERROR_HANDLER`
102
+ # environment variable.
103
+ attr_reader :error_handler
104
+
81
105
  # This is the selected TeX engine. Supported values are described in
82
106
  # TEX_ENGINES.
83
107
  #
@@ -122,8 +146,8 @@ module Texd
122
146
  end
123
147
 
124
148
  def to_h
125
- DEFAULT_CONFIGURATION.keys.each_with_object({}) do |key, hash|
126
- hash[key] = public_send(key)
149
+ DEFAULT_CONFIGURATION.keys.index_with do |key|
150
+ public_send(key)
127
151
  end
128
152
  end
129
153
 
@@ -163,12 +187,30 @@ module Texd
163
187
  val = val.to_s
164
188
 
165
189
  unless ERROR_FORMATS.include?(val)
166
- raise InvalidConfig.new(nil, got: val, expected: ERROR_FORMATS)
190
+ raise InvalidConfig.new(nil,
191
+ option: :error_format,
192
+ got: val,
193
+ expected: ERROR_FORMATS)
167
194
  end
168
195
 
169
196
  @error_format = val
170
197
  end
171
198
 
199
+ def error_handler=(val)
200
+ val ||= "raise"
201
+ val = ERROR_HANDLERS.fetch(val.to_s, nil) unless val.respond_to?(:call)
202
+
203
+ if val
204
+ @error_handler = val
205
+ return
206
+ end
207
+
208
+ raise InvalidConfig.new(nil,
209
+ option: :error_handler,
210
+ got: val,
211
+ expected: ERROR_HANDLERS.keys + ["a Proc instance"])
212
+ end
213
+
172
214
  def tex_engine=(val)
173
215
  unless val.nil?
174
216
  val = val.to_s
data/lib/texd/document.rb CHANGED
@@ -40,6 +40,12 @@ module Texd
40
40
  def to_upload_ios(missing_refs: Set.new)
41
41
  attachments.to_upload_ios(missing_refs)
42
42
  end
43
+
44
+ # Convenience accessor for the main input file.
45
+ # @returns [String] main input file contents
46
+ def main_input_contents
47
+ attachments.items.fetch(main_input_name).contents
48
+ end
43
49
  end
44
50
  end
45
51
  end
data/lib/texd/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Texd
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.2"
5
5
  end
data/lib/texd.rb CHANGED
@@ -105,7 +105,6 @@ module Texd
105
105
  # # Compilation failed and we might have a log in err.logs (only
106
106
  # # Texd.config.error_format is "full" or "condensed").
107
107
  # # Otherwise some details might be available in err.details.
108
- # # have a log in err.details
109
108
  # rescue Texd::Client::InputError => err
110
109
  # # something failed during input file processing. For details see
111
110
  # # err.details
@@ -135,5 +134,8 @@ module Texd
135
134
  # retry once with resolved references
136
135
  client.render doc.to_upload_ios(missing_refs: err.references),
137
136
  input: doc.main_input_name
137
+ rescue Client::CompilationError => err
138
+ config.error_handler.call(err, doc)
139
+ nil
138
140
  end
139
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Menke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-28 00:00:00.000000000 Z
11
+ date: 2022-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -141,7 +141,7 @@ metadata:
141
141
  rubygems_mfa_required: 'true'
142
142
  homepage_uri: https://github.com/digineo/texd-ruby
143
143
  source_code_uri: https://github.com/digineo/texd-ruby
144
- changelog_uri: https://github.com/digineo/texd-ruby/blob/v0.3.2/CHANGELOG.md
144
+ changelog_uri: https://github.com/digineo/texd-ruby/blob/v0.4.2/CHANGELOG.md
145
145
  post_install_message:
146
146
  rdoc_options: []
147
147
  require_paths: