texd 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8adfd41b8474299e99aabf34619decaf04acd780093e53edeef3df4d7373dbe8
4
- data.tar.gz: 817ea60570bfecc734cfc7ea4500401f136076d0d7cebf8b5d1a8e95b900eed6
3
+ metadata.gz: 33d8cf48e8c880611c853f282bc3db47cf5d627022887dd311ff7a895a3f24e9
4
+ data.tar.gz: c77ab1247262c025cd814d58b22f32f21f241a33fb5d95b15d1d805409546534
5
5
  SHA512:
6
- metadata.gz: 5945f91f78c4d4b7386b5ea109a7306f24573223f1e9e6c5b2a4ce85d766b5564c0c2feb87d682e539560765ed12c65d7f316604ae45b325a2dfcbe1cdc61f76
7
- data.tar.gz: 351d90cadc208506ddc33446dfd182e1a544b2f9cce1fa243d6316515e87d557bcbb759e112bf8f5c6daf2586288e66b9a7fafa70bb516f4567a8651b659a3f9
6
+ metadata.gz: 398a048ca70ecdb2a65ec3466ea900ebd918f7aacc5d4335ea1099cacf9342729a5e232eaed8af9bed261d4ca1e6d6ceb1e19476acea5ccc5a310b1520157afc
7
+ data.tar.gz: 7dd01397f2fdc0975dc0e31d8dcc2fb8de21017af585615333ad34a62ffcbce1793e994f6f6ac25eefa70c79779b8edfa1f5fd3d831b581ce826613b477b05c1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- texd (0.1.0)
4
+ texd (0.2.2)
5
5
  multipart-post (~> 2.0)
6
6
  rails (>= 6.0, < 8)
7
7
 
@@ -81,7 +81,7 @@ GEM
81
81
  activesupport (>= 3.0.0)
82
82
  railties (>= 3.0.0)
83
83
  thor (>= 0.14.6)
84
- concurrent-ruby (1.1.9)
84
+ concurrent-ruby (1.1.10)
85
85
  crass (1.0.6)
86
86
  diff-lcs (1.5.0)
87
87
  digest (3.1.0)
@@ -183,7 +183,7 @@ GEM
183
183
  rspec-mocks (~> 3.10)
184
184
  rspec-support (~> 3.10)
185
185
  rspec-support (3.11.0)
186
- rubocop (1.26.0)
186
+ rubocop (1.26.1)
187
187
  parallel (~> 1.10)
188
188
  parser (>= 3.1.0.0)
189
189
  rainbow (>= 2.2.2, < 4.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- texd (0.1.0)
4
+ texd (0.2.2)
5
5
  multipart-post (~> 2.0)
6
6
  rails (>= 6.0, < 8)
7
7
 
@@ -70,7 +70,7 @@ GEM
70
70
  activesupport (>= 3.0.0)
71
71
  railties (>= 3.0.0)
72
72
  thor (>= 0.14.6)
73
- concurrent-ruby (1.1.9)
73
+ concurrent-ruby (1.1.10)
74
74
  crass (1.0.6)
75
75
  diff-lcs (1.5.0)
76
76
  erubi (1.10.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- texd (0.1.0)
4
+ texd (0.2.2)
5
5
  multipart-post (~> 2.0)
6
6
  rails (>= 6.0, < 8)
7
7
 
@@ -74,7 +74,7 @@ GEM
74
74
  activesupport (>= 3.0.0)
75
75
  railties (>= 3.0.0)
76
76
  thor (>= 0.14.6)
77
- concurrent-ruby (1.1.9)
77
+ concurrent-ruby (1.1.10)
78
78
  crass (1.0.6)
79
79
  diff-lcs (1.5.0)
80
80
  erubi (1.10.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- texd (0.1.0)
4
+ texd (0.2.2)
5
5
  multipart-post (~> 2.0)
6
6
  rails (>= 6.0, < 8)
7
7
 
@@ -80,7 +80,7 @@ GEM
80
80
  activesupport (>= 3.0.0)
81
81
  railties (>= 3.0.0)
82
82
  thor (>= 0.14.6)
83
- concurrent-ruby (1.1.9)
83
+ concurrent-ruby (1.1.10)
84
84
  crass (1.0.6)
85
85
  diff-lcs (1.5.0)
86
86
  digest (3.1.0)
data/lib/texd/document.rb CHANGED
@@ -6,8 +6,8 @@ module Texd
6
6
  attr_reader :attachments
7
7
 
8
8
  # Shorthand for `new.compile`.
9
- def self.compile(*args)
10
- new.compile(*args)
9
+ def self.compile(template:, locals: {})
10
+ new.compile(template: template, locals: locals)
11
11
  end
12
12
 
13
13
  def initialize
@@ -18,14 +18,16 @@ module Texd
18
18
  # Compile converts templates into TeX sources and collects file
19
19
  # references (created with `texd_attach` and `texd_reference` helpers).
20
20
  #
21
- # @param args are forwarded to ApplicationController#render (which in turn
22
- # forwards to ActionView::Renderer#render).
21
+ # @param [String] template name of template file in ActionView's lookup
22
+ # context.
23
+ # @param [Hash, nil] locals will be made available as getter methods in
24
+ # the template.
23
25
  # @return [Compilation]
24
- def compile(*args)
25
- helper_mod = ::Texd.helpers(attachments)
26
+ def compile(template:, locals: {})
27
+ helper_mod = ::Texd.helpers(attachments, locals)
26
28
  tex_source = Class.new(ApplicationController) {
27
29
  helper helper_mod
28
- }.render(*args)
30
+ }.render(template: template, format: :tex)
29
31
 
30
32
  main = attachments.main_input(tex_source)
31
33
  Compilation.new(main.name, attachments)
data/lib/texd/helpers.rb CHANGED
@@ -28,8 +28,9 @@ module Texd
28
28
 
29
29
  # Escapes the given text, making it safe for use in TeX documents.
30
30
  def escape(text, line_break = "\\\\\\", typographic: true)
31
- text = +text
32
- text.to_s.tap do |str|
31
+ return "" if text.blank?
32
+
33
+ text.to_s.dup.tap do |str|
33
34
  str.gsub!(ESCAPE_RE) do |m|
34
35
  if Regexp.last_match(1)
35
36
  "\\#{m}"
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.1.0"
4
+ VERSION = "0.2.2"
5
5
  end
data/lib/texd.rb CHANGED
@@ -55,16 +55,26 @@ module Texd
55
55
  @client
56
56
  end
57
57
 
58
- # Creates a helper module containing (a) the `texd_attach` helper,
59
- # and (b) any other helper configured in Text.config.helpers.
58
+ # Creates a helper module containing:
60
59
  #
61
- # This needs to be dynamic, because the attachment list is volatile.
60
+ # 1. the `texd_attach` and `texd_reference` helper,
61
+ # 2. locals passed in, transformed to helper methods, and
62
+ # 3. any other helper configured in Text.config.helpers.
62
63
  #
63
64
  # @api private
64
- def helpers(attachments)
65
+ # @param [Texd::AttachmentList] attachments
66
+ # @param [Hash, nil] locals
67
+ # @return [Module] a new helper module
68
+ def helpers(attachments, locals) # rubocop:disable Metrics/AbcSize
69
+ locals ||= {}
70
+
65
71
  Module.new do
66
72
  include Texd::Helpers
67
73
 
74
+ Texd.config.helpers.each do |mod|
75
+ include mod
76
+ end
77
+
68
78
  define_method :texd_attach do |path, rename: true, with_extension: true|
69
79
  attachments.attach(path, rename).name(with_extension)
70
80
  end
@@ -75,8 +85,8 @@ module Texd
75
85
 
76
86
  alias_method :texd_references, :texd_reference
77
87
 
78
- Texd.config.helpers.each do |mod|
79
- include mod
88
+ locals.each do |name, value|
89
+ define_method(name) { value }
80
90
  end
81
91
  end
82
92
  end
@@ -84,8 +94,8 @@ module Texd
84
94
  # Render compiles a template, uploads the files to the texd instance,
85
95
  # and returns the PDF.
86
96
  #
87
- # The arguments are directly forwarded to ApplicationController#render
88
- # (which in turn delegates to ActionView::Renderer#render).
97
+ # The arguments are directly forwarded to Texd::Document (and end up in
98
+ # ActionView::Renderer#render).
89
99
  #
90
100
  # @example Render app/views/document/document.tex.erb
91
101
  # begin
@@ -104,12 +114,16 @@ module Texd
104
114
  # # something went wrong before we even got to sent data to the server
105
115
  # end
106
116
  #
117
+ # @param [String] template name of template file in ActionView's lookup
118
+ # context.
119
+ # @param [Hash, nil] locals will be made available as getter methods in
120
+ # the template.
107
121
  # @raise [Texd::Client::ResponseError] on input and queue errors. Also on
108
122
  # compilation errors, if Texd.config.error_format is set to JSON.
109
123
  # @raise [Texd::Error] on other Texd related errors.
110
124
  # @return [String] the PDF object
111
- def render(*args)
112
- doc = Document.compile(*args)
125
+ def render(template:, locals: {})
126
+ doc = Document.compile(template: template, locals: locals)
113
127
 
114
128
  client.render doc.to_upload_ios,
115
129
  input: doc.main_input_name
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.1.0
4
+ version: 0.2.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-21 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -140,7 +140,7 @@ metadata:
140
140
  rubygems_mfa_required: 'true'
141
141
  homepage_uri: https://github.com/digineo/texd-ruby
142
142
  source_code_uri: https://github.com/digineo/texd-ruby
143
- changelog_uri: https://github.com/digineo/texd-ruby/blob/v0.1.0/CHANGELOG.md
143
+ changelog_uri: https://github.com/digineo/texd-ruby/blob/v0.2.2/CHANGELOG.md
144
144
  post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths: