pandoc-ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/VERSION +1 -1
- data/lib/pandoc-ruby.rb +6 -9
- data/pandoc-ruby.gemspec +1 -1
- data/test/pandoc-ruby_test.rb +23 -11
- metadata +1 -1
data/README.markdown
CHANGED
@@ -19,13 +19,13 @@ Next, install PandocRuby from gemcutter.
|
|
19
19
|
@converter = PandocRuby.new('/some/file.md', :from => :markdown, :to => :rst)
|
20
20
|
puts @converter.convert
|
21
21
|
|
22
|
-
This takes the
|
22
|
+
This takes the Markdown formatted file and converts it to reStructuredText.
|
23
23
|
|
24
|
-
You can
|
24
|
+
You can use the `#convert` class method:
|
25
25
|
|
26
26
|
puts PandocRuby.convert('/some/file.md', :from => :markdown, :to => :html)
|
27
27
|
|
28
|
-
|
28
|
+
Included is a `#to_s` method for somewhat nicer use in Rails views.
|
29
29
|
|
30
30
|
... helper file ...
|
31
31
|
def format(text)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/pandoc-ruby.rb
CHANGED
@@ -10,7 +10,7 @@ class PandocRuby
|
|
10
10
|
]
|
11
11
|
|
12
12
|
def self.bin_path=(path)
|
13
|
-
@@bin_path =
|
13
|
+
@@bin_path = path
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.convert(*args)
|
@@ -35,20 +35,17 @@ class PandocRuby
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def convert
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
execute @executable + convert_options
|
42
|
-
end
|
38
|
+
executable = @@bin_path ? File.join(@@bin_path, @executable) : @executable
|
39
|
+
execute executable + convert_options
|
43
40
|
end
|
44
41
|
alias_method :to_s, :convert
|
45
42
|
|
46
43
|
def convert_options
|
47
44
|
@options.inject('') do |string, (flag, value)|
|
48
|
-
if flag.to_s.length == 1
|
49
|
-
|
45
|
+
string + if flag.to_s.length == 1
|
46
|
+
" -#{flag} #{value}"
|
50
47
|
else
|
51
|
-
|
48
|
+
" --#{flag}=#{value}"
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
data/pandoc-ruby.gemspec
CHANGED
data/test/pandoc-ruby_test.rb
CHANGED
@@ -8,33 +8,45 @@ class PandocRubyTest < Test::Unit::TestCase
|
|
8
8
|
@converter = PandocRuby.new(@file, :t => :rst)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
def teardown
|
12
|
+
PandocRuby.bin_path = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
should "call bare pandoc when passed no options" do
|
16
|
+
converter = PandocRuby.new(@file)
|
17
|
+
converter.expects(:execute).with('pandoc').returns(true)
|
18
|
+
assert converter.convert
|
19
|
+
end
|
20
|
+
|
21
|
+
should "convert with altered bin_path" do
|
22
|
+
path = %x[which pandoc].strip
|
23
|
+
PandocRuby.bin_path = path
|
12
24
|
converter = PandocRuby.new(@file)
|
13
|
-
|
14
|
-
converter.convert
|
25
|
+
converter.expects(:execute).with("#{path}/pandoc").returns(true)
|
26
|
+
assert converter.convert
|
15
27
|
end
|
16
28
|
|
17
29
|
should "accept short options" do
|
18
|
-
|
19
|
-
@converter.convert
|
30
|
+
@converter.expects(:execute).with('pandoc -t rst').returns(true)
|
31
|
+
assert @converter.convert
|
20
32
|
end
|
21
33
|
|
22
34
|
should "accept long options" do
|
23
35
|
converter = PandocRuby.new(@file, :to => :rst)
|
24
|
-
|
25
|
-
converter.convert
|
36
|
+
converter.expects(:execute).with('pandoc --to=rst').returns(true)
|
37
|
+
assert converter.convert
|
26
38
|
end
|
27
39
|
|
28
40
|
should "accept optional executable" do
|
29
41
|
converter = PandocRuby.new(@file, 'html2markdown')
|
30
|
-
|
31
|
-
converter.convert
|
42
|
+
converter.expects(:execute).with('html2markdown').returns(true)
|
43
|
+
assert converter.convert
|
32
44
|
end
|
33
45
|
|
34
46
|
should "not accept non-pandoc optional executable" do
|
35
47
|
converter = PandocRuby.new(@file, 'ls')
|
36
|
-
|
37
|
-
converter.convert
|
48
|
+
converter.expects(:execute).with('pandoc').returns(true)
|
49
|
+
assert converter.convert
|
38
50
|
end
|
39
51
|
|
40
52
|
should "work with strings" do
|