texd 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 8adfd41b8474299e99aabf34619decaf04acd780093e53edeef3df4d7373dbe8
4
- data.tar.gz: 817ea60570bfecc734cfc7ea4500401f136076d0d7cebf8b5d1a8e95b900eed6
3
+ metadata.gz: 676222ee01af1a31facb86ee1a4416f4f5b3307e0c8e7de9b6ee7357b5e8a838
4
+ data.tar.gz: 153a30b56379209ba62ec860de87ae3fc6dd322b6828df73557bef90cb526bc9
5
5
  SHA512:
6
- metadata.gz: 5945f91f78c4d4b7386b5ea109a7306f24573223f1e9e6c5b2a4ce85d766b5564c0c2feb87d682e539560765ed12c65d7f316604ae45b325a2dfcbe1cdc61f76
7
- data.tar.gz: 351d90cadc208506ddc33446dfd182e1a544b2f9cce1fa243d6316515e87d557bcbb759e112bf8f5c6daf2586288e66b9a7fafa70bb516f4567a8651b659a3f9
6
+ metadata.gz: 210eab22723d4f043cad09601022fa577769a3235bbbac5984c538594d83015559b2f1d92d8f537cd230e301fc97425c75aca12a310d210f60ff85a05b3e0df8
7
+ data.tar.gz: 82c1ebfedabb268f92871ad707aa0b1d611440bb641a134a449e112eac76d24476e3ddcf25c788b6620b364650085e09a2e5ffad0a8fcc4592b04e953d2583c5
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.0)
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.0)
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.0)
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.0)
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
@@ -22,7 +22,9 @@ module Texd
22
22
  # forwards to ActionView::Renderer#render).
23
23
  # @return [Compilation]
24
24
  def compile(*args)
25
- helper_mod = ::Texd.helpers(attachments)
25
+ locals = args.last.delete(:locals) if args.last.is_a?(Hash)
26
+ helper_mod = ::Texd.helpers(attachments, locals)
27
+
26
28
  tex_source = Class.new(ApplicationController) {
27
29
  helper helper_mod
28
30
  }.render(*args)
data/lib/texd/helpers.rb CHANGED
@@ -28,8 +28,8 @@ 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
+ text = +text.to_s # text might be nil or a frozen string
32
+ text.tap do |str|
33
33
  str.gsub!(ESCAPE_RE) do |m|
34
34
  if Regexp.last_match(1)
35
35
  "\\#{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.0"
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
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.0
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.0/CHANGELOG.md
144
144
  post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths: