pandoc-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,14 +40,19 @@ is equivalent to
40
40
 
41
41
  pandoc -s -f markdown --to=rst --no-wrap --table-of-contents /some/file.html
42
42
 
43
- Also provided are `#to_[writer]` instance methods for each of the writers:
43
+ Also provided are `#to_[writer]` instance methods for each of the writers, and these can also accept options:
44
44
 
45
- PandocRuby.new("# Some title").to_html
46
- => "<div id=\"some-title\"\n><h1\n >Some title</h1\n ></div\n>"
45
+ PandocRuby.new("# Some title").to_html(:no_wrap)
46
+ => "<div id=\"some-title\"><h1>Some title</h1></div>"
47
47
  # or
48
48
  PandocRuby.new("# Some title").to_rtf
49
49
  => "{\\pard \\ql \\f0 \\sa180 \\li0 \\fi0 \\b \\fs36 Some title\\par}"
50
50
 
51
+ Similarly, there are class methods for each of the readers, so readers and writers can be specified like this:
52
+
53
+ PandocRuby.html("<h1>hello</h1>").to_latex
54
+ => "\\section{hello}"
55
+
51
56
  PandocRuby assumes the pandoc executables are in the path. If not, set their location
52
57
  with `PandocRuby.bin_path = '/path/to/bin'`
53
58
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -46,16 +46,25 @@ class PandocRuby
46
46
  @options = args
47
47
  end
48
48
 
49
- def convert
49
+ def convert(*args)
50
50
  executable = @@bin_path ? File.join(@@bin_path, @executable) : @executable
51
- execute executable + convert_options
51
+ execute executable + convert_options(args)
52
52
  end
53
53
  alias_method :to_s, :convert
54
54
 
55
+ class << self
56
+ READERS.each_key do |r|
57
+ define_method(r) do |*args|
58
+ args += [{:from => r}]
59
+ new(*args)
60
+ end
61
+ end
62
+ end
63
+
55
64
  WRITERS.each_key do |w|
56
- define_method(:"to_#{w}") do
57
- @options << {:to => w.to_sym}
58
- convert
65
+ define_method(:"to_#{w}") do |*args|
66
+ args += [{:to => w.to_sym}]
67
+ convert(*args)
59
68
  end
60
69
  end
61
70
 
@@ -71,8 +80,8 @@ private
71
80
  output
72
81
  end
73
82
 
74
- def convert_options
75
- @options.inject('') do |string, opt|
83
+ def convert_options(opts = [])
84
+ (@options + opts).flatten.inject('') do |string, opt|
76
85
  string + if opt.respond_to?(:each_pair)
77
86
  convert_opts_with_args(opt)
78
87
  else
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pandoc-ruby}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.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 = %q{2009-11-18}
12
+ s.date = %q{2009-11-20}
13
13
  s.description = %q{Ruby wrapper for Pandoc}
14
14
  s.email = %q{wmelody@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -36,12 +36,18 @@ class TestPandocRuby < Test::Unit::TestCase
36
36
  assert converter.convert
37
37
  end
38
38
 
39
- should "accept a variety of options" do
39
+ should "accept a variety of options in initializer" do
40
40
  converter = PandocRuby.new(@file, :s, {:f => :markdown, :to => :rst}, 'no-wrap')
41
41
  converter.expects(:execute).with('pandoc -s -f markdown --to=rst --no-wrap').returns(true)
42
42
  assert converter.convert
43
43
  end
44
44
 
45
+ should "accept a variety of options in convert" do
46
+ converter = PandocRuby.new(@file)
47
+ converter.expects(:execute).with('pandoc -s -f markdown --to=rst --no-wrap').returns(true)
48
+ assert converter.convert(:s, {:f => :markdown, :to => :rst}, 'no-wrap')
49
+ end
50
+
45
51
  should "convert underscore symbol ares to hyphenated long options" do
46
52
  converter = PandocRuby.new(@file, {:email_obfuscation => :javascript}, :table_of_contents)
47
53
  converter.expects(:execute).with('pandoc --email-obfuscation=javascript --table-of-contents').returns(true)
@@ -60,11 +66,19 @@ class TestPandocRuby < Test::Unit::TestCase
60
66
  assert converter.convert
61
67
  end
62
68
 
69
+ PandocRuby::READERS.each_key do |r|
70
+ should "convert from #{r} with PandocRuby.#{r}" do
71
+ converter = PandocRuby.send(r, @file)
72
+ converter.expects(:execute).with("pandoc --from=#{r}").returns(true)
73
+ assert converter.convert
74
+ end
75
+ end
76
+
63
77
  PandocRuby::WRITERS.each_key do |w|
64
78
  should "convert to #{w} with to_#{w}" do
65
79
  converter = PandocRuby.new(@file)
66
- converter.expects(:execute).with("pandoc --to=#{w}").returns(true)
67
- assert converter.send("to_#{w}")
80
+ converter.expects(:execute).with("pandoc --no-wrap --to=#{w}").returns(true)
81
+ assert converter.send("to_#{w}", :no_wrap)
68
82
  end
69
83
  end
70
84
 
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Melody
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 -06:00
12
+ date: 2009-11-20 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency