pandoc-ruby 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +11 -11
- data/README.markdown +1 -2
- data/VERSION +1 -1
- data/lib/pandoc-ruby.rb +40 -6
- data/pandoc-ruby.gemspec +2 -2
- data/test/test_pandoc-ruby.rb +18 -3
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (3.2.
|
5
|
-
i18n (
|
4
|
+
activesupport (3.2.13)
|
5
|
+
i18n (= 0.6.1)
|
6
6
|
multi_json (~> 1.0)
|
7
7
|
git (1.2.5)
|
8
8
|
i18n (0.6.1)
|
@@ -11,19 +11,19 @@ GEM
|
|
11
11
|
git (>= 1.2.5)
|
12
12
|
rake
|
13
13
|
rdoc
|
14
|
-
json (1.
|
14
|
+
json (1.8.0)
|
15
15
|
metaclass (0.0.1)
|
16
16
|
mocha (0.13.3)
|
17
17
|
metaclass (~> 0.0.1)
|
18
|
-
multi_json (1.3
|
19
|
-
rake (0.
|
20
|
-
rdoc (3.12)
|
18
|
+
multi_json (1.7.3)
|
19
|
+
rake (10.0.4)
|
20
|
+
rdoc (3.12.2)
|
21
21
|
json (~> 1.4)
|
22
|
-
shoulda (3.
|
23
|
-
shoulda-context (~> 1.0)
|
24
|
-
shoulda-matchers (
|
25
|
-
shoulda-context (1.
|
26
|
-
shoulda-matchers (1.
|
22
|
+
shoulda (3.5.0)
|
23
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
24
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
25
|
+
shoulda-context (1.1.2)
|
26
|
+
shoulda-matchers (2.1.0)
|
27
27
|
activesupport (>= 3.0.0)
|
28
28
|
|
29
29
|
PLATFORMS
|
data/README.markdown
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Wrapper for [Pandoc](http://johnmacfarlane.net/pandoc/), a Haskell library with command line tools for converting one markup format to another.
|
4
4
|
|
5
|
-
Pandoc can
|
5
|
+
Pandoc can convert documents in markdown, reStructuredText, textile, HTML, DocBook, LaTeX, or MediaWiki markup to a variety of formats, including markdown, reStructuredText, HTML, LaTeX, ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki markup, groff man pages, HTML slide shows, EPUB, and Microsoft Word docx.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -76,7 +76,6 @@ If you are trying to generate a standalone file with full file headers rather th
|
|
76
76
|
## Caveats
|
77
77
|
|
78
78
|
* This has only been tested on \*nix systems.
|
79
|
-
* ODT is not currently supported because it is a binary format.
|
80
79
|
* PDF conversion may require additional dependencies and has not been tested.
|
81
80
|
|
82
81
|
## Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/pandoc-ruby.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'open3'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
class PandocRuby
|
4
5
|
@@bin_path = nil
|
@@ -43,10 +44,14 @@ class PandocRuby
|
|
43
44
|
'textile' => 'textile',
|
44
45
|
'rtf' => 'rich text format',
|
45
46
|
'org' => 'emacs org mode',
|
46
|
-
'asciidoc' => 'asciidoc'
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
'asciidoc' => 'asciidoc'
|
48
|
+
}
|
49
|
+
|
50
|
+
BINARY_WRITERS = {
|
51
|
+
'odt' => 'OpenDocument',
|
52
|
+
'docx' => 'Word docx',
|
53
|
+
'epub' => 'EPUB V2',
|
54
|
+
'epub3' => 'EPUB V3'
|
50
55
|
}
|
51
56
|
|
52
57
|
def self.bin_path=(path)
|
@@ -72,9 +77,24 @@ class PandocRuby
|
|
72
77
|
@options = args
|
73
78
|
end
|
74
79
|
|
80
|
+
def convert_binary(executable, *args)
|
81
|
+
tmp_file = Tempfile.new('pandoc-conversion')
|
82
|
+
begin
|
83
|
+
args += [{:output => tmp_file.path}]
|
84
|
+
execute executable + convert_options(args)
|
85
|
+
return IO.binread(tmp_file)
|
86
|
+
ensure
|
87
|
+
tmp_file.unlink
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
75
91
|
def convert(*args)
|
76
92
|
executable = @@bin_path ? File.join(@@bin_path, @executable) : @executable
|
77
|
-
|
93
|
+
if will_output_binary?(args)
|
94
|
+
convert_binary(executable, *args)
|
95
|
+
else
|
96
|
+
execute executable + convert_options(args)
|
97
|
+
end
|
78
98
|
end
|
79
99
|
alias_method :to_s, :convert
|
80
100
|
|
@@ -87,7 +107,7 @@ class PandocRuby
|
|
87
107
|
end
|
88
108
|
end
|
89
109
|
|
90
|
-
WRITERS.each_key do |w|
|
110
|
+
WRITERS.merge(BINARY_WRITERS).each_key do |w|
|
91
111
|
define_method(:"to_#{w}") do |*args|
|
92
112
|
args += [{:to => w.to_sym}]
|
93
113
|
convert(*args)
|
@@ -122,4 +142,18 @@ private
|
|
122
142
|
string + (flag.length == 1 ? " -#{flag} #{val}" : " --#{flag}=#{val}")
|
123
143
|
end
|
124
144
|
end
|
145
|
+
|
146
|
+
def will_output_binary?(opts = [])
|
147
|
+
(@options+opts).flatten.each do |opt|
|
148
|
+
if opt.respond_to?(:each_pair)
|
149
|
+
opt.each_pair do |opt_key, opt_value|
|
150
|
+
if opt_key == :to && BINARY_WRITERS.keys.include?(opt_value.to_s)
|
151
|
+
return true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
false
|
157
|
+
end
|
158
|
+
|
125
159
|
end
|
data/pandoc-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "pandoc-ruby"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["William Melody"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-05-19"
|
13
13
|
s.description = "Ruby wrapper for Pandoc"
|
14
14
|
s.email = "hi@williammelody.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_pandoc-ruby.rb
CHANGED
@@ -109,6 +109,17 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
PandocRuby::BINARY_WRITERS.each_key do |w|
|
113
|
+
should "convert to #{w} with to_#{w}" do
|
114
|
+
converter = PandocRuby.new(@file)
|
115
|
+
converter \
|
116
|
+
.expects(:execute) \
|
117
|
+
.with(regexp_matches(/^pandoc --no-wrap --to=#{w} --output=/)) \
|
118
|
+
.returns(true)
|
119
|
+
assert converter.send("to_#{w}", :no_wrap)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
112
123
|
should "work with strings" do
|
113
124
|
converter = PandocRuby.new('## this is a title')
|
114
125
|
assert_match %r(h2), converter.convert
|
@@ -148,7 +159,6 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
148
159
|
"mediawiki" => "MediaWiki markup",
|
149
160
|
"html" => "HTML",
|
150
161
|
"plain" => "plain",
|
151
|
-
"docx" => "docx",
|
152
162
|
"latex" => "LaTeX",
|
153
163
|
"s5" => "S5 HTML slideshow",
|
154
164
|
"textile" => "textile",
|
@@ -156,7 +166,6 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
156
166
|
"docbook" => "DocBook XML",
|
157
167
|
"html5" => "HTML5",
|
158
168
|
"native" => "pandoc native",
|
159
|
-
"epub" => "epub",
|
160
169
|
"org" => "emacs org mode",
|
161
170
|
"rtf" => "rich text format",
|
162
171
|
"markdown" => "markdown",
|
@@ -168,9 +177,15 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
168
177
|
"slidy" => "Slidy HTML slideshow",
|
169
178
|
"rst" => "reStructuredText",
|
170
179
|
"context" => "ConTeXt",
|
171
|
-
"odt" => "odt",
|
172
180
|
"asciidoc" => "asciidoc"
|
173
181
|
}
|
174
182
|
|
183
|
+
assert_equal PandocRuby::BINARY_WRITERS, {
|
184
|
+
"odt" => "OpenDocument",
|
185
|
+
"docx" => "Word docx",
|
186
|
+
"epub" => "EPUB V2",
|
187
|
+
"epub3" => "EPUB V3"
|
188
|
+
}
|
189
|
+
|
175
190
|
end
|
176
191
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandoc-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jeweler
|
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
segments:
|
115
115
|
- 0
|
116
|
-
hash:
|
116
|
+
hash: 1655115057340333945
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|