Module: Texd
- Extended by:
- Texd
- Included in:
- Texd
- Defined in:
- lib/texd.rb,
lib/texd.rb,
lib/texd/cache.rb,
lib/texd/client.rb,
lib/texd/config.rb,
lib/texd/helpers.rb,
lib/texd/railtie.rb,
lib/texd/version.rb,
lib/texd/document.rb,
lib/texd/attachment.rb,
lib/texd/lookup_context.rb
Defined Under Namespace
Modules: Attachment, Helpers Classes: AttachmentList, Cache, Client, Configuration, Document, Error, LookupContext, Railtie
Constant Summary collapse
- VERSION =
"0.6.0"
Instance Method Summary collapse
-
#client ⇒ Texd::Client
The currently configured HTTP client.
-
#config ⇒ Texd::Configuration
The current config object.
-
#configure {|Texd::Configuration| ... } ⇒ Texd::Configuration
Reconfigures Texd.
-
#helpers(attachments, locals) ⇒ Module
private
Creates a helper module containing:.
-
#render(template:, locals: {}, layout: true) ⇒ String
Render compiles a template, uploads the files to the texd instance, and returns the PDF.
Instance Method Details
#client ⇒ Texd::Client
Returns the currently configured HTTP client.
50 51 52 53 54 55 56 57 |
# File 'lib/texd.rb', line 50 def client if (new_hash = config.hash) && new_hash != @config_hash @client = Client.new(config) @config_hash = new_hash end @client end |
#config ⇒ Texd::Configuration
Returns the current config object.
45 46 47 |
# File 'lib/texd.rb', line 45 def config @config ||= Configuration.new end |
#configure {|Texd::Configuration| ... } ⇒ Texd::Configuration
Reconfigures Texd. Should be called once in your initializer.
39 40 41 42 |
# File 'lib/texd.rb', line 39 def configure yield config if block_given? config end |
#helpers(attachments, locals) ⇒ Module
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.
Creates a helper module containing:
-
the ‘texd_attach` and `texd_reference` helper,
-
locals passed in, transformed to helper methods, and
-
any other helper configured in Text.config.helpers.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/texd.rb', line 69 def helpers(, locals) # rubocop:disable Metrics/AbcSize locals ||= {} Module.new do include Texd::Helpers Texd.config.helpers.each do |mod| include mod end define_method :texd_attach do |path, rename: true, with_extension: true| .attach(path, rename).name(with_extension) end define_method :texd_inline do |data, name, with_extension: true| .inline(data, name).name(with_extension) end define_method :texd_reference do |path, rename: true, with_extension: true| .reference(path, rename).name(with_extension) end alias_method :texd_references, :texd_reference locals.each do |name, value| define_method(name) { value } end end end |
#render(template:, locals: {}, layout: true) ⇒ String
Render compiles a template, uploads the files to the texd instance, and returns the PDF.
The arguments are directly forwarded to Texd::Document (and end up in ActionView::Renderer#render).
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/texd.rb', line 132 def render(template:, locals: {}, layout: true) doc = Document.compile(template: template, locals: locals, layout: layout) client.render doc.to_upload_ios, input: doc.main_input_name rescue Client::ReferenceError => err # retry once with resolved references client.render doc.to_upload_ios(missing_refs: err.references), input: doc.main_input_name rescue Client::CompilationError => err config.error_handler.call(err, doc) nil end |