Class: Texd::Configuration
- Inherits:
-
Object
- Object
- Texd::Configuration
- Defined in:
- lib/texd/config.rb
Defined Under Namespace
Classes: InvalidConfig
Constant Summary collapse
- DEFAULT_CONFIGURATION =
This is the default configuration. It is applied in the constructor.
{ endpoint: ENV.fetch("TEXD_ENDPOINT", "http://localhost:2201/"), open_timeout: ENV.fetch("TEXD_OPEN_TIMEOUT", 60), read_timeout: ENV.fetch("TEXD_READ_TIMEOUT", 180), write_timeout: ENV.fetch("TEXD_WRITE_TIMEOUT", 60), error_format: ENV.fetch("TEXD_ERRORS", "full"), error_handler: ENV.fetch("TEXD_ERROR_HANDLER", "raise"), tex_engine: ENV.fetch("TEXD_ENGINE", nil), tex_image: ENV.fetch("TEXD_IMAGE", nil), helpers: Set.new, lookup_paths: [], # Rails.root.join("app/tex") is inserted in railtie.rb ref_cache_size: 128, }.freeze
- ENDPOINT_CLASSES =
Supported endpoint protocols.
[URI::HTTP, URI::HTTPS].freeze
- ERROR_FORMATS =
Supported error formats.
%w[json full condensed].freeze
- ERROR_HANDLERS =
Default error handlers. One might provide a custom proc, if desired.
{ "raise" => proc { |err, _doc| raise err }, "stderr" => proc { |err, _doc| err.write_to($stderr) }, "ignore" => proc { |_err, _doc| }, }.freeze
- TEX_ENGINES =
Supported TeX engines.
%w[xelatex lualatex pdflatex].freeze
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Endpoint is a URI pointing to the texd server instance.
-
#error_format ⇒ Object
The texd server usually reports errors in JSON format, however, when the compilation fails, the TeX compiler’s output ist often most useful.
-
#error_handler ⇒ Object
This setting defines how to handle Texd::Client::CompilationError errors.
-
#helpers ⇒ Object
List of additional helper modules to make available in the template views.
-
#lookup_paths ⇒ Object
Set of paths to perform file lookups in.
-
#open_timeout ⇒ Object
Timeout (in seconds) for the initial connect to the endpoint.
-
#read_timeout ⇒ Object
Timeout (in seconds) for reads from the endpoint.
-
#ref_cache_size ⇒ Object
Cache size for file hashes computed by Texd::Attachment::Reference.
-
#tex_engine ⇒ Object
This is the selected TeX engine.
-
#tex_image ⇒ Object
When texd runs in container mode, it may provide multiple Docker images to select from.
-
#write_timeout ⇒ Object
Timeout (in seconds) for writing the request to the endpoint.
Instance Method Summary collapse
- #default_render_params ⇒ Object private
-
#initialize(**options) ⇒ Configuration
constructor
A new instance of Configuration.
- #to_h ⇒ Object
Constructor Details
#initialize(**options) ⇒ Configuration
Returns a new instance of Configuration.
142 143 144 145 146 |
# File 'lib/texd/config.rb', line 142 def initialize(**) DEFAULT_CONFIGURATION.each do |key, default_value| public_send "#{key}=", .fetch(key, default_value.dup) end end |
Instance Attribute Details
#endpoint ⇒ Object
Endpoint is a URI pointing to the texd server instance.
The default is ‘localhost:2201/` and can be overriden by the `TEXD_ENDPOINT` environment variable.
58 59 60 |
# File 'lib/texd/config.rb', line 58 def endpoint @endpoint end |
#error_format ⇒ Object
The texd server usually reports errors in JSON format, however, when the compilation fails, the TeX compiler’s output ist often most useful.
Supported values are described in ERROR_FORMATS.
The default is “full” and can be overriden by the ‘TEXD_ERRORS` environment variable.
87 88 89 |
# File 'lib/texd/config.rb', line 87 def error_format @error_format end |
#error_handler ⇒ Object
This setting defines how to handle Texd::Client::CompilationError errors.
Supported values are:
-
“raise”, which will not process the error,
-
“stderr”, which will print the error to stderr,
-
“ignore”, which will silently discard,
-
a Proc instance, which will delegate the error handling to it.
The setter will lookup “raise”, “stderr”, and “ignore” from ERROR_HANDLERS, so this attribute will always be of kind Proc.
The default value is “raise” and can be overridden by the ‘TEXD_ERROR_HANDLER` environment variable.
103 104 105 |
# File 'lib/texd/config.rb', line 103 def error_handler @error_handler end |
#helpers ⇒ Object
List of additional helper modules to make available in the template views. Texd::Helpers is always included, and you may add additional ones.
This can’t be influenced by environment variables.
123 124 125 |
# File 'lib/texd/config.rb', line 123 def helpers @helpers end |
#lookup_paths ⇒ Object
Set of paths to perform file lookups in. The set is searched in order, meaning files found in later entries won’t be returned if entries with the same name exist in earlier entries.
By default, this only contains ‘Rails.root.join(“app/tex”)`, however Rails engines might append additional entries.
A Texd::LookupContext is constructed from this set.
133 134 135 |
# File 'lib/texd/config.rb', line 133 def lookup_paths @lookup_paths end |
#open_timeout ⇒ Object
Timeout (in seconds) for the initial connect to the endpoint.
The default is 60 (1 min) and can be overriden by the ‘TEXD_OPEN_TIMEOUT` environment variable.
64 65 66 |
# File 'lib/texd/config.rb', line 64 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Timeout (in seconds) for reads from the endpoint. You want this value to be in the same ballbark as texd’s ‘–compile-timoeut` option.
The default is 180 (3 min) and can be overriden by the ‘TEXD_OPEN_TIMEOUT` environment variable.
71 72 73 |
# File 'lib/texd/config.rb', line 71 def read_timeout @read_timeout end |
#ref_cache_size ⇒ Object
Cache size for file hashes computed by Texd::Attachment::Reference. Cannot be changed after the first document (using the ‘texd_reference` helper) was renderered.
By default, the cache keeps hashes of the last 128 reference files.
140 141 142 |
# File 'lib/texd/config.rb', line 140 def ref_cache_size @ref_cache_size end |
#tex_engine ⇒ Object
This is the selected TeX engine. Supported values are described in TEX_ENGINES.
The default is blank (meaning the server shall default to its ‘–tex-engine` option), and can be overriden by the `TEXD_ENGINE` environment variable.
110 111 112 |
# File 'lib/texd/config.rb', line 110 def tex_engine @tex_engine end |
#tex_image ⇒ Object
When texd runs in container mode, it may provide multiple Docker images to select from. This setting selects a specific container image.
The default value is blank (meaning texd will select an image), and can be overriden byt the ‘TEXD_IMAGE` environment variable.
117 118 119 |
# File 'lib/texd/config.rb', line 117 def tex_image @tex_image end |
#write_timeout ⇒ Object
Timeout (in seconds) for writing the request to the endpoint. You want this value to be in the same ballpark as texd’s ‘–queue-timeout` option.
The default is 60 (1 min) and can be overriden by the ‘TEXD_WRITE_TIMEOUT` environment variable.
78 79 80 |
# File 'lib/texd/config.rb', line 78 def write_timeout @write_timeout end |
Instance Method Details
#default_render_params ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 158 159 160 161 |
# File 'lib/texd/config.rb', line 155 def default_render_params { errors: error_format, engine: tex_engine, image: tex_image, }.compact end |
#to_h ⇒ Object
148 149 150 151 152 |
# File 'lib/texd/config.rb', line 148 def to_h DEFAULT_CONFIGURATION.keys.index_with do |key| public_send(key) end end |