pandoc-ruby 0.1.0 → 0.2.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.
data/README.markdown CHANGED
@@ -8,14 +8,15 @@ Pandoc can read markdown and (subsets of) reStructuredText, HTML, and LaTeX, and
8
8
 
9
9
  First, make sure to [install Pandoc](http://johnmacfarlane.net/pandoc/#installing-pandoc).
10
10
 
11
- Next, install PandocRuby from gemcutter.
12
-
11
+ Next, install PandocRuby from [gemcutter](http://gemcutter.org/gems/pandoc-ruby).
12
+
13
13
  gem install gemcutter
14
- gem tumble
14
+ gem tumble # unless you've already run this.
15
15
  gem install pandoc-ruby
16
16
 
17
17
  ## Usage
18
18
 
19
+ require 'pandoc-ruby'
19
20
  @converter = PandocRuby.new('/some/file.md', :from => :markdown, :to => :rst)
20
21
  puts @converter.convert
21
22
 
@@ -33,11 +34,19 @@ will use Pandoc's `html2markdown` wrapper.
33
34
 
34
35
  Other arguments are simply converted into command line options, accepting symbols or strings for options without arguments and hashes of strings or symbols for options with arguments.
35
36
 
36
- PandocRuby.convert('/some/file.html', :s, {:to => :rst, :f => :markdown}, 'no-wrap')
37
+ PandocRuby.convert('/some/file.html', :s, {:f => :markdown, :to => :rst}, 'no-wrap', :table_of_contents)
38
+
39
+ is equivalent to
40
+
41
+ pandoc -s -f markdown --to=rst --no-wrap --table-of-contents /some/file.html
37
42
 
38
- becomes
43
+ Also provided are `#to_[writer]` instance methods for each of the writers:
39
44
 
40
- pandoc -s --to=rst -f markdown --no-wrap /some/file.html
45
+ PandocRuby.new("# Some title").to_html
46
+ => "<div id=\"some-title\"\n><h1\n >Some title</h1\n ></div\n>"
47
+ # or
48
+ PandocRuby.new("# Some title").to_rtf
49
+ => "{\\pard \\ql \\f0 \\sa180 \\li0 \\fi0 \\b \\fs36 Some title\\par}"
41
50
 
42
51
  PandocRuby assumes the pandoc executables are in the path. If not, set their location
43
52
  with `PandocRuby.bin_path = '/path/to/bin'`
@@ -46,7 +55,7 @@ Available format readers and writers are available in the `PandocRuby::READERS`
46
55
 
47
56
  For more information on Pandoc, see the [Pandoc documentation](http://johnmacfarlane.net/pandoc/) or run `man pandoc`.
48
57
 
49
- If you'd prefer a pure-Ruby extended markdown interpreter that can output a few different formats, take a look at [Maruku](http://maruku.rubyforge.org/).
58
+ If you'd prefer a pure-Ruby extended markdown interpreter that can output a few different formats, take a look at [Maruku](http://maruku.rubyforge.org/). If you want to use the full reStructuredText syntax from within Ruby, check out [RbST](http://rdoc.info/projects/autodata/rbst), a docutils wrapper.
50
59
 
51
60
  This gem was inspired by [Albino](http://github.com/github/albino). For a slightly different approach to using Pandoc with Ruby, see [Pandoku](http://github.com/dahlia/pandoku).
52
61
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/pandoc-ruby.rb CHANGED
@@ -52,9 +52,11 @@ class PandocRuby
52
52
  end
53
53
  alias_method :to_s, :convert
54
54
 
55
- def to_html
56
- @options << {:to => :html}
57
- convert
55
+ WRITERS.each_key do |w|
56
+ define_method(:"to_#{w}") do
57
+ @options << {:to => w.to_sym}
58
+ convert
59
+ end
58
60
  end
59
61
 
60
62
  private
@@ -72,12 +74,17 @@ private
72
74
  def convert_options
73
75
  @options.inject('') do |string, opt|
74
76
  string + if opt.respond_to?(:each_pair)
75
- opt.inject('') do |s, (flag, val)|
76
- s + (flag.to_s.length == 1 ? " -#{flag} #{val}" : " --#{flag}=#{val}")
77
- end
77
+ convert_opts_with_args(opt)
78
78
  else
79
- opt.to_s.length == 1 ? " -#{opt}" : " --#{opt}"
79
+ opt.to_s.length == 1 ? " -#{opt}" : " --#{opt.to_s.gsub(/_/, '-')}"
80
80
  end
81
81
  end
82
82
  end
83
+
84
+ def convert_opts_with_args(opt)
85
+ opt.inject('') do |string, (flag, val)|
86
+ flag = flag.to_s.gsub(/_/, '-')
87
+ string + (flag.length == 1 ? " -#{flag} #{val}" : " --#{flag}=#{val}")
88
+ end
89
+ end
83
90
  end
data/pandoc-ruby.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pandoc-ruby}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.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-04}
12
+ s.date = %q{2009-11-18}
13
13
  s.description = %q{Ruby wrapper for Pandoc}
14
14
  s.email = %q{wmelody@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -26,8 +26,8 @@ Gem::Specification.new do |s|
26
26
  "lib/pandoc-ruby.rb",
27
27
  "pandoc-ruby.gemspec",
28
28
  "test/benchmark.rb",
29
- "test/benchmark.txt",
30
- "test/test.md",
29
+ "test/files/benchmark.txt",
30
+ "test/files/test.md",
31
31
  "test/test_conversions.rb",
32
32
  "test/test_helper.rb",
33
33
  "test/test_pandoc-ruby.rb"
data/test/benchmark.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  # http://tomayko.com/writings/ruby-markdown-libraries-real-cheap-for-you-two-for-price-of-one
5
5
 
6
6
  iterations = 100
7
- test_file = "#{File.dirname(__FILE__)}/benchmark.txt"
7
+ test_file = File.join(File.dirname(__FILE__), 'files', 'benchmark.txt')
8
8
  impl_gems = {
9
9
  'BlueCloth' => 'bluecloth',
10
10
  'RDiscount' => 'rdiscount',
File without changes
File without changes
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'mocha'
3
2
 
4
3
  class TestConversions < Test::Unit::TestCase
5
4
 
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'mocha'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -1,10 +1,9 @@
1
1
  require 'test_helper'
2
- require 'mocha'
3
2
 
4
3
  class TestPandocRuby < Test::Unit::TestCase
5
4
 
6
5
  def setup
7
- @file = File.join(File.dirname(__FILE__), 'test.md')
6
+ @file = File.join(File.dirname(__FILE__), 'files', 'test.md')
8
7
  @converter = PandocRuby.new(@file, :t => :rst)
9
8
  end
10
9
 
@@ -38,8 +37,14 @@ class TestPandocRuby < Test::Unit::TestCase
38
37
  end
39
38
 
40
39
  should "accept a variety of options" do
41
- converter = PandocRuby.new(@file, :s, {:to => :rst, :f => :markdown}, 'no-wrap')
42
- converter.expects(:execute).with('pandoc -s --to=rst -f markdown --no-wrap').returns(true)
40
+ converter = PandocRuby.new(@file, :s, {:f => :markdown, :to => :rst}, 'no-wrap')
41
+ converter.expects(:execute).with('pandoc -s -f markdown --to=rst --no-wrap').returns(true)
42
+ assert converter.convert
43
+ end
44
+
45
+ should "convert underscore symbol ares to hyphenated long options" do
46
+ converter = PandocRuby.new(@file, {:email_obfuscation => :javascript}, :table_of_contents)
47
+ converter.expects(:execute).with('pandoc --email-obfuscation=javascript --table-of-contents').returns(true)
43
48
  assert converter.convert
44
49
  end
45
50
 
@@ -55,10 +60,12 @@ class TestPandocRuby < Test::Unit::TestCase
55
60
  assert converter.convert
56
61
  end
57
62
 
58
- should "convert to html with to_html" do
59
- converter = PandocRuby.new(@file)
60
- converter.expects(:execute).with('pandoc --to=html').returns(true)
61
- assert converter.to_html
63
+ PandocRuby::WRITERS.each_key do |w|
64
+ should "convert to #{w} with to_#{w}" do
65
+ converter = PandocRuby.new(@file)
66
+ converter.expects(:execute).with("pandoc --to=#{w}").returns(true)
67
+ assert converter.send("to_#{w}")
68
+ end
62
69
  end
63
70
 
64
71
  should "work with strings" do
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.1.0
4
+ version: 0.2.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-04 00:00:00 -06:00
12
+ date: 2009-11-18 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,8 +61,8 @@ files:
61
61
  - lib/pandoc-ruby.rb
62
62
  - pandoc-ruby.gemspec
63
63
  - test/benchmark.rb
64
- - test/benchmark.txt
65
- - test/test.md
64
+ - test/files/benchmark.txt
65
+ - test/files/test.md
66
66
  - test/test_conversions.rb
67
67
  - test/test_helper.rb
68
68
  - test/test_pandoc-ruby.rb