word-to-markdown 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65c40ca66cec250fa58be0b50f9691c49e80ba6c
4
- data.tar.gz: 0bb6276f14bfbcbb6ff11b47f2b0fd0fbff94c10
3
+ metadata.gz: 8d0a6d4dbb16a5c53ffc336d781b5ca275acaf61
4
+ data.tar.gz: 16c255b3f304c01a89d215500cdc9e235149e119
5
5
  SHA512:
6
- metadata.gz: f20b0252fab914e0a412fdab1b76005d5ce2daa10392bcce0daafd6fae9a7744f66cd26259fb65f1272a7ba3845b460ca0c772bb924a72a09303240bf4586dce
7
- data.tar.gz: 84c8ab75b71bc19933cbe6860e8511c31d5dbb370898229b9d67e933aa8f754cfe8dd85a1f3220a4454199011691d2185422076a65bda7d86257a9abd6a7cf8e
6
+ metadata.gz: 4b6ecd85ac312939fff436970472dc3d350b6d75d8a42bb82d3633a06f95ac8a970f04765da64f2ac5a2221ef492ed6ba7efd5b06a8e4ea850998826cc85a4b4
7
+ data.tar.gz: 4612cadf0ba9f7b3409a7d0d378f960084bcca8980e3b6ca1e7436dc67011a33dbbb7817641cb177b769f83e92abb09f29e8758b151e2d4076e3395d00ccd4f7
@@ -23,8 +23,8 @@ class WordToMarkdown
23
23
  # input - a HTML string or path to an HTML file
24
24
  #
25
25
  # Returns the WordToMarkdown object
26
- def initialize(path)
27
- @document = WordToMarkdown::Document.new path
26
+ def initialize(path, tmpdir = nil)
27
+ @document = WordToMarkdown::Document.new path, tmpdir
28
28
  @converter = WordToMarkdown::Converter.new @document
29
29
  converter.convert!
30
30
  end
@@ -44,7 +44,9 @@ class WordToMarkdown
44
44
 
45
45
  def self.soffice_path
46
46
  if RUBY_PLATFORM.include?("darwin")
47
- "/Applications/LibreOffice.app/Contents/MacOS/soffice"
47
+ %w[~/Applications /Applications]
48
+ .map { |f| File.join(f, "/LibreOffice.app/Contents/MacOS/soffice") }
49
+ .find { |f| File.file?(f) } || -> { raise RuntimeError.new("Coudln't find LibreOffice on your machine.") }.call
48
50
  else
49
51
  soffice_path ||= which("soffice")
50
52
  soffice_path ||= which("soffice.bin")
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  class WordToMarkdown
2
3
  class Converter
3
4
 
@@ -1,11 +1,13 @@
1
+ # encoding: utf-8
1
2
  class WordToMarkdown
2
3
  class Document
3
4
  class NotFoundError < StandardError; end
4
5
 
5
- attr_reader :path, :raw_html
6
+ attr_reader :path, :raw_html, :tmpdir
6
7
 
7
- def initialize(path)
8
+ def initialize(path, tmpdir = nil)
8
9
  @path = File.expand_path path, Dir.pwd
10
+ @tmpdir = tmpdir || Dir.mktmpdir
9
11
  raise NotFoundError, "File #{@path} does not exist" unless File.exist?(@path)
10
12
  end
11
13
 
@@ -76,10 +78,6 @@ class WordToMarkdown
76
78
  string
77
79
  end
78
80
 
79
- def tmpdir
80
- @tmpdir ||= Dir.mktmpdir
81
- end
82
-
83
81
  def dest_path
84
82
  dest_filename = File.basename(path).gsub(/#{Regexp.escape(extension)}$/, ".html")
85
83
  File.expand_path(dest_filename, tmpdir)
@@ -87,7 +85,7 @@ class WordToMarkdown
87
85
 
88
86
  def raw_html
89
87
  @raw_html ||= begin
90
- WordToMarkdown::run_command '--headless', '--convert-to', 'html', path, '--outdir', tmpdir
88
+ WordToMarkdown::run_command '--headless', '--convert-to', 'html', "'#{path}'", '--outdir', tmpdir
91
89
  html = File.read dest_path
92
90
  File.delete dest_path
93
91
  html
@@ -1,3 +1,3 @@
1
1
  class WordToMarkdown
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word-to-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reverse_markdown