paru 0.3.0a2 → 0.3.0a3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paru/pandoc.rb +31 -22
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19f82be37cb030a88a74527fbef0c91e75a77130
4
- data.tar.gz: 1353cc90313623b40b3ad1180359ffcf8224e351
3
+ metadata.gz: 8e6c500a0b739b0dad6ed1e06336b5eae2e49bcd
4
+ data.tar.gz: 78d1a4e26f51d5cb7e4231b7978146618cd3726d
5
5
  SHA512:
6
- metadata.gz: 7adfa9079dfe0f2ab45237929f662e1321294eaae8c25edb7d8c4bcabc68bb6974646c2f8f53d2f9399efe870f3df1afa0684cfa8d6b7682a561a422cdd61014
7
- data.tar.gz: ee623452bd3b682b5ab1aaf6fbc8a29e905c31fba328552783f8454d91a46d5f196ec1702204b76f6183dbb2bb917c2814ec71a8b92a07e1ca271a74db662fc6
6
+ metadata.gz: e63bc28ecc944bbb69a33ba17d9638d62e0cfc0741ae2176c84cc0323a3dcbd3caba96f1c325b75afefb9678e17dd74c09b40f1ea2e22fd1448c8958642a0874
7
+ data.tar.gz: 382bf1d24b42cebb7d543a33e96441938eb56470904d95b6f09f86473272b91448ac55b7daa966830e0a1cc291d8fe5ef4d07fda4173e639b2c7e4937f43ef2f
data/lib/paru/pandoc.rb CHANGED
@@ -16,6 +16,7 @@
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
+ require "open3"
19
20
  require "shellwords"
20
21
  require "yaml"
21
22
 
@@ -149,17 +150,7 @@ module Paru
149
150
  # @example Using <<
150
151
  # output = converter << 'this is a *strong* word'
151
152
  def convert(input)
152
- begin
153
- output = ''
154
- IO.popen(to_command, 'r+') do |p|
155
- p << input
156
- p.close_write
157
- output << p.read
158
- end
159
- output
160
- rescue StandardError => err
161
- throw Error.new "Error while running '#{to_command}' on input:\n\n#{input}\n\nPandoc responds: '#{err.message}'"
162
- end
153
+ run_converter to_command, input
163
154
  end
164
155
  alias << convert
165
156
 
@@ -175,17 +166,7 @@ module Paru
175
166
  # @example Using convert_file
176
167
  # output = converter.convert_file 'files/document.md'
177
168
  def convert_file(input_file)
178
- command = "#{to_command} #{input_file}"
179
- begin
180
- output = ''
181
- IO.popen(command, 'r+') do |p|
182
- p.close_write
183
- output << p.read
184
- end
185
- output
186
- rescue StandardError => err
187
- throw Error.new "Error while running '#{command}' on input:\n\n#{input}\n\nPandoc responds: '#{err.message}'"
188
- end
169
+ run_converter "#{to_command} #{input_file}"
189
170
  end
190
171
 
191
172
  # Create a string representation of this converter's pandoc command
@@ -295,6 +276,34 @@ module Paru
295
276
  end
296
277
  end
297
278
 
279
+ private
280
+
281
+ def run_converter(command, input = nil)
282
+ begin
283
+ output = ''
284
+ error = ''
285
+ status = 0
286
+
287
+ Open3.popen3(command) do |stdin, stdout, stderr, thread|
288
+ stdin << input unless input.nil?
289
+ stdin.close
290
+ output << stdout.read
291
+ error << stderr.read
292
+ status = thread.value.exitstatus
293
+ end
294
+
295
+ if 0 < status
296
+ # pandoc exited with an error
297
+ raise Paru::Error.new "error while running:\n\n#{command}\n\nPandoc responded with:\n\n#{error}\n"
298
+ end
299
+
300
+ output
301
+ rescue Paru::Error => err
302
+ raise err
303
+ rescue StandardError => err
304
+ throw Error.new "Unable to run pandoc via command '#{command}': #{err.message}"
305
+ end
306
+ end
298
307
  end
299
308
 
300
309
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0a2
4
+ version: 0.3.0a3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huub de Beer
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: 1.3.1
108
108
  requirements: []
109
109
  rubyforge_project:
110
- rubygems_version: 2.5.2
110
+ rubygems_version: 2.6.11
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Paru is a ruby wrapper around pandoc (pandoc 2)