Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify soffice existence #54

Merged
merged 2 commits into from
Jun 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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