Skip to content

Commit 5db2bf8

Browse files
committed
Merge pull request #54 from benbalter/soffice_check
Verify soffice existence
2 parents f80d7df + 6c09e82 commit 5db2bf8

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/word-to-markdown.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ def self.soffice_path
6363
end
6464
end
6565

66+
def self.soffice?
67+
@soffice ||= !(soffice_path.nil? || soffice_version.nil?)
68+
end
69+
6670
def self.run_command(*args)
71+
raise "LibreOffice executable not found" unless soffice?
6772
output, status = Open3.capture2e(soffice_path, *args)
6873
raise "Command `#{soffice_path} #{args.join(" ")}` failed: #{output}" if status != 0
6974
output
7075
end
7176

7277
def self.soffice_version
73-
run_command('--version').strip.sub "LibreOffice ", ""
78+
return if soffice_path.nil?
79+
output, status = Open3.capture2e(soffice_path, "--version")
80+
output.strip.sub "LibreOffice ", "" if status == 0
7481
end
7582

7683
# Pretty print the class in console

test/test_word_to_markdown.rb

+4
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ class TestWordToMarkdown < Test::Unit::TestCase
5353
should "handle files with spaces" do
5454
validate_fixture "file with space", "This is paragraph text."
5555
end
56+
57+
should "know the soffice version" do
58+
assert_match /\d\.\d\.\d\.\d .*/, WordToMarkdown.soffice_version
59+
end
5660
end

test/test_word_to_markdown_lists.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class TestWordToMarkdownLists < Test::Unit::TestCase
1111
end
1212

1313
should "parse nested ols" do
14-
validate_fixture "nested-ol", "1. One\n 1. Sub one\n 2. Sub two\n\n2. Two\n 1. Sub one\n 1. Sub sub one\n 2. Sub sub two\n\n 2. Sub two\n\n3. Three"
14+
validate_fixture "nested-ol", "1. One\n 1. Sub one\n 2. Sub two\n2. Two\n 1. Sub one\n 1. Sub sub one\n 2. Sub sub two\n 2. Sub two\n3. Three"
1515
end
1616

1717
should "parse nested uls" do
18-
validate_fixture "nested-ul", "- One\n - Sub one\n - Sub sub one\n - Sub sub two\n\n - Sub two\n\n- Two"
18+
validate_fixture "nested-ul", "- One\n - Sub one\n - Sub sub one\n - Sub sub two\n - Sub two\n- Two"
1919
end
2020

2121
should "parse lists with links" do

0 commit comments

Comments
 (0)