Skip to content

Commit

Permalink
Merge pull request #54 from benbalter/soffice_check
Browse files Browse the repository at this point in the history
Verify soffice existence
  • Loading branch information
benbalter committed Jun 13, 2015
2 parents f80d7df + 6c09e82 commit 5db2bf8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/word-to-markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@ def self.soffice_path
end
end

def self.soffice?
@soffice ||= !(soffice_path.nil? || soffice_version.nil?)
end

def self.run_command(*args)
raise "LibreOffice executable not found" unless soffice?
output, status = Open3.capture2e(soffice_path, *args)
raise "Command `#{soffice_path} #{args.join(" ")}` failed: #{output}" if status != 0
output
end

def self.soffice_version
run_command('--version').strip.sub "LibreOffice ", ""
return if soffice_path.nil?
output, status = Open3.capture2e(soffice_path, "--version")
output.strip.sub "LibreOffice ", "" if status == 0
end

# Pretty print the class in console
Expand Down
4 changes: 4 additions & 0 deletions test/test_word_to_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ class TestWordToMarkdown < Test::Unit::TestCase
should "handle files with spaces" do
validate_fixture "file with space", "This is paragraph text."
end

should "know the soffice version" do
assert_match /\d\.\d\.\d\.\d .*/, WordToMarkdown.soffice_version
end
end
4 changes: 2 additions & 2 deletions test/test_word_to_markdown_lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class TestWordToMarkdownLists < Test::Unit::TestCase
end

should "parse nested ols" do
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"
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"
end

should "parse nested uls" do
validate_fixture "nested-ul", "- One\n - Sub one\n - Sub sub one\n - Sub sub two\n\n - Sub two\n\n- Two"
validate_fixture "nested-ul", "- One\n - Sub one\n - Sub sub one\n - Sub sub two\n - Sub two\n- Two"
end

should "parse lists with links" do
Expand Down

0 comments on commit 5db2bf8

Please sign in to comment.