texd 0.4.2 → 0.5.1
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 +4 -4
- data/.rubocop.yml +10 -0
- data/CHANGELOG.md +20 -1
- data/Gemfile.lock +85 -91
- data/Makefile +32 -18
- data/gemfiles/{rails-6.0 → rails-6.0/Gemfile} +1 -1
- data/gemfiles/{rails-6.0.lock → rails-6.0/Gemfile.lock} +67 -67
- data/gemfiles/{rails-6.1 → rails-6.1/Gemfile} +1 -1
- data/gemfiles/{rails-6.1.lock → rails-6.1/Gemfile.lock} +70 -70
- data/gemfiles/{rails-7.0 → rails-7.0/Gemfile} +1 -1
- data/gemfiles/{rails-7.0.lock → rails-7.0/Gemfile.lock} +73 -81
- data/gemfiles/rails-main/Gemfile +7 -0
- data/gemfiles/rails-main/Gemfile.lock +201 -0
- data/lib/texd/attachment.rb +49 -7
- data/lib/texd/version.rb +1 -1
- data/lib/texd.rb +4 -0
- metadata +11 -9
data/lib/texd/attachment.rb
CHANGED
@@ -53,6 +53,33 @@ module Texd
|
|
53
53
|
add(Attachment::File, path, rename)
|
54
54
|
end
|
55
55
|
|
56
|
+
# Includes a file with the given `content` to the list. This is useful
|
57
|
+
# if you generate the content on-the-fly (like creating CSV data from
|
58
|
+
# database records), and don't want to save that content to disk first.
|
59
|
+
#
|
60
|
+
# In short, these examples should be mostly equivalent:
|
61
|
+
#
|
62
|
+
# # use a temporary file to write contents to, and attach that file:
|
63
|
+
# tmp = Tempfile.new ["foo", ".csv"]
|
64
|
+
# tmp.write @record.to_csv
|
65
|
+
# tmp.flush
|
66
|
+
# tmp.close
|
67
|
+
# text_attach tmp.name
|
68
|
+
#
|
69
|
+
# # skip writing to disk and inline the file:
|
70
|
+
# texd_inline @record.to_csv, "foo.csv"
|
71
|
+
#
|
72
|
+
# @param [<Type>] contents <description>
|
73
|
+
# @param [<Type>] path <description>
|
74
|
+
#
|
75
|
+
# @return [<Type>] <description>
|
76
|
+
def inline(contents, path)
|
77
|
+
att = Attachment::Dynamic.new(path, contents)
|
78
|
+
|
79
|
+
items[att.name] ||= att
|
80
|
+
items[att.name]
|
81
|
+
end
|
82
|
+
|
56
83
|
# Adds a file reference with the given path to the list. Similar to #attach,
|
57
84
|
# the file path must either be an absolute filename or be relative to
|
58
85
|
# app/tex/ of the host application.
|
@@ -130,12 +157,33 @@ module Texd
|
|
130
157
|
end
|
131
158
|
end
|
132
159
|
|
160
|
+
# Computes the file name of a given path, and returns it with or without
|
161
|
+
# file extension.
|
162
|
+
#
|
163
|
+
# @param [String, Pathname] path A Pathname instance or just a plain file name.
|
164
|
+
# @param [Boolean] with_extension If true, returns the file path's basename
|
165
|
+
# unmodified, otherwise the file extension, including its ".", is removed.
|
166
|
+
# @return [String] File path with or without extension.
|
167
|
+
def self.name(path, with_extension = true) # rubocop:disable Style/OptionalBooleanParameter
|
168
|
+
basename = ::File.basename(path)
|
169
|
+
return basename if with_extension
|
170
|
+
|
171
|
+
dot = basename.rindex(".")
|
172
|
+
return basename if dot == 0 # file starts with "."
|
173
|
+
|
174
|
+
basename.slice(0, dot)
|
175
|
+
end
|
176
|
+
|
133
177
|
Dynamic = Struct.new(:name, :contents) do
|
134
178
|
def to_upload_io(**)
|
135
179
|
Multipart::Post::UploadIO.new(StringIO.new(contents), nil, name).tap { |io|
|
136
180
|
io.instance_variable_set :@original_filename, name
|
137
181
|
}
|
138
182
|
end
|
183
|
+
|
184
|
+
def name(with_extension = true) # rubocop:disable Style/OptionalBooleanParameter
|
185
|
+
Attachment.name(self[:name], with_extension)
|
186
|
+
end
|
139
187
|
end
|
140
188
|
|
141
189
|
class Base
|
@@ -164,13 +212,7 @@ module Texd
|
|
164
212
|
# @param [Boolean] with_extension
|
165
213
|
# @return [String] output file name
|
166
214
|
def name(with_extension = true) # rubocop:disable Style/OptionalBooleanParameter
|
167
|
-
|
168
|
-
return basename if with_extension
|
169
|
-
|
170
|
-
dot = basename.rindex(".")
|
171
|
-
return basename if dot == 0 # file starts with "."
|
172
|
-
|
173
|
-
basename.slice(0, dot)
|
215
|
+
Attachment.name(@name, with_extension)
|
174
216
|
end
|
175
217
|
end
|
176
218
|
|
data/lib/texd/version.rb
CHANGED
data/lib/texd.rb
CHANGED
@@ -80,6 +80,10 @@ module Texd
|
|
80
80
|
attachments.attach(path, rename).name(with_extension)
|
81
81
|
end
|
82
82
|
|
83
|
+
define_method :texd_inline do |data, name, with_extension: true|
|
84
|
+
attachments.inline(data, name).name(with_extension)
|
85
|
+
end
|
86
|
+
|
83
87
|
define_method :texd_reference do |path, rename: true, with_extension: true|
|
84
88
|
attachments.reference(path, rename).name(with_extension)
|
85
89
|
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.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2022-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multipart-post
|
@@ -117,12 +117,14 @@ files:
|
|
117
117
|
- Makefile
|
118
118
|
- README.md
|
119
119
|
- Rakefile
|
120
|
-
- gemfiles/rails-6.0
|
121
|
-
- gemfiles/rails-6.0.lock
|
122
|
-
- gemfiles/rails-6.1
|
123
|
-
- gemfiles/rails-6.1.lock
|
124
|
-
- gemfiles/rails-7.0
|
125
|
-
- gemfiles/rails-7.0.lock
|
120
|
+
- gemfiles/rails-6.0/Gemfile
|
121
|
+
- gemfiles/rails-6.0/Gemfile.lock
|
122
|
+
- gemfiles/rails-6.1/Gemfile
|
123
|
+
- gemfiles/rails-6.1/Gemfile.lock
|
124
|
+
- gemfiles/rails-7.0/Gemfile
|
125
|
+
- gemfiles/rails-7.0/Gemfile.lock
|
126
|
+
- gemfiles/rails-main/Gemfile
|
127
|
+
- gemfiles/rails-main/Gemfile.lock
|
126
128
|
- lib/texd.rb
|
127
129
|
- lib/texd/attachment.rb
|
128
130
|
- lib/texd/cache.rb
|
@@ -141,7 +143,7 @@ metadata:
|
|
141
143
|
rubygems_mfa_required: 'true'
|
142
144
|
homepage_uri: https://github.com/digineo/texd-ruby
|
143
145
|
source_code_uri: https://github.com/digineo/texd-ruby
|
144
|
-
changelog_uri: https://github.com/digineo/texd-ruby/blob/v0.
|
146
|
+
changelog_uri: https://github.com/digineo/texd-ruby/blob/v0.5.1/CHANGELOG.md
|
145
147
|
post_install_message:
|
146
148
|
rdoc_options: []
|
147
149
|
require_paths:
|