pandoku 0.2 → 0.3

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.
@@ -1,9 +1,3 @@
1
1
  require File.dirname(__FILE__) + '/pandoku/document'
2
2
  require File.dirname(__FILE__) + '/pandoku/format'
3
-
4
- # %w<markdown rst html latex
5
- # context man mediawiki texinfo docbook opendocument odt s5 rtf>.each do |f|
6
- %w<markdown rst html odt>.each do |f|
7
- require "#{File.dirname(__FILE__)}/pandoku/formats/#{f}"
8
- end
9
-
3
+ require File.dirname(__FILE__) + '/pandoku/lookup_table'
@@ -0,0 +1,22 @@
1
+ require File.dirname(File.dirname(__FILE__)) + '/format'
2
+
3
+ module Pandoku::Formats
4
+ # ConTeXt format. http://www.pragma-ade.nl/
5
+ #
6
+ # == Available Options
7
+ #
8
+ # <tt>:no_wrap</tt>:: Disable text wrapping in output.
9
+ # (Default is to wrap text.)
10
+ # <tt>:toc</tt>:: Include an instruction to create table of contents.
11
+ class ConTeXt < Pandoku::Format
12
+ include Pandoku::OutputFormat
13
+
14
+ def self.name
15
+ :context
16
+ end
17
+
18
+ def self.default_options
19
+ { :no_wrap => false, :toc => false }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(File.dirname(__FILE__)) + '/format'
2
+
3
+ module Pandoku::Formats
4
+ # LaTeX format. http://www.latex-project.org/
5
+ #
6
+ # == Available Options
7
+ #
8
+ # <tt>:standalone</tt>:: Produce output with an appropriate header and footer.
9
+ # <tt>:parse_raw</tt>:: Parse untranslatable LaTeX environments as raw LaTeX,
10
+ # instead of ignoring them.
11
+ # <tt>:number_sections</tt>:: Number section headings in LaTeX output.
12
+ # (Default is not to number them.)
13
+ # <tt>:no_wrap</tt>:: Disable text wrapping in output.
14
+ # (Default is to wrap text.)
15
+ # <tt>:toc</tt>:: Include an instruction to create table of contents.
16
+ class LaTeX < Pandoku::Format
17
+ include Pandoku::InputFormat, Pandoku::OutputFormat
18
+
19
+ def self.name
20
+ :latex
21
+ end
22
+
23
+ def self.default_options
24
+ { :standalone => false, :parse_raw => false, :number_sections => false,
25
+ :no_wrap => false, :toc => false }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(File.dirname(__FILE__)) + '/format'
2
+
3
+ module Pandoku::Formats
4
+ # Unix man format.
5
+ class Man < Pandoku::Format
6
+ include Pandoku::OutputFormat
7
+
8
+ def self.name
9
+ :man
10
+ end
11
+ end
12
+
13
+ # Aliases.
14
+ Manual = Man
15
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(File.dirname(__FILE__)) + '/format'
2
+
3
+ module Pandoku::Formats
4
+ # MediaWiki markup format. http://www.mediawiki.org/wiki/Help:Formatting
5
+ #
6
+ # == Available Options
7
+ #
8
+ # <tt>:toc</tt>:: Include an instruction to create table of contents.
9
+ class MediaWiki < Pandoku::Format
10
+ include Pandoku::OutputFormat
11
+
12
+ def self.name
13
+ :mediawiki
14
+ end
15
+
16
+ def self.default_options
17
+ { :toc => false }
18
+ end
19
+ end
20
+ end
@@ -23,5 +23,5 @@ module Pandoku::Formats
23
23
  end
24
24
 
25
25
  # Aliases.
26
- ReST = RST = reStructuredText = ReStructuredText
26
+ ReST = RST = ReStructuredText
27
27
  end
@@ -0,0 +1,23 @@
1
+ require File.dirname(File.dirname(__FILE__)) + '/format'
2
+
3
+ module Pandoku::Formats
4
+ # Rich text format.
5
+ #
6
+ # == Available Options
7
+ #
8
+ # <tt>:toc</tt>:: Include an automatically generated table of contents.
9
+ class RichTextFormat < Pandoku::Format
10
+ include Pandoku::OutputFormat
11
+
12
+ def self.name
13
+ :rtf
14
+ end
15
+
16
+ def self.default_options
17
+ { :toc => false }
18
+ end
19
+ end
20
+
21
+ # Aliases.
22
+ RTF = RichTextFormat
23
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/format'
2
+
3
+ module Pandoku
4
+ module Formats
5
+ LOOKUP_TABLE = []
6
+
7
+ class LookupError < IndexError; end
8
+
9
+ # Find a format class by the +name+.
10
+ # It raises +LookupError+ when it is not found,
11
+ # or returns +nil+ if +raises_exception+ is +false+.
12
+ def self.lookup(name, raises_exception = true)
13
+ name = name.to_sym
14
+ require "#{File.dirname(__FILE__)}/formats/#{name}"
15
+ for format in LOOKUP_TABLE
16
+ return format if format.name == name
17
+ end
18
+ return unless raises_exception
19
+ raise LookupError, "there is no formatter named :#{name}"
20
+ end
21
+ end
22
+
23
+ class Format
24
+ def self.inherited(subclass)
25
+ Formats::LOOKUP_TABLE << subclass
26
+ end
27
+ end
28
+
29
+ class ::String
30
+ # Translate the markup.
31
+ #
32
+ # string.pandoku(:markdown => :html)
33
+ # string.pandoku(:markdown, :html)
34
+ # string.pandoku(:markdown, :html, :smart => true)
35
+ def pandoku(from, to = nil, options = {})
36
+ if to.nil? && from.is_a?(Hash) && from.size == 1
37
+ to = from.values.first
38
+ from = from.keys.first
39
+ end
40
+ raise ArgumentError, 'expected two arguments' if to.nil?
41
+ decoder = Formats.lookup(from).new(options)
42
+ encoder = Formats.lookup(to).new
43
+ decoder.parse(self).compile(encoder)
44
+ end
45
+ end
46
+ end
47
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandoku
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hong, MinHee
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-08 00:00:00 +09:00
12
+ date: 2009-10-10 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,11 +23,17 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - lib/pandoku.rb
26
+ - lib/pandoku/formats/rtf.rb
26
27
  - lib/pandoku/formats/odt.rb
28
+ - lib/pandoku/formats/mediawiki.rb
29
+ - lib/pandoku/formats/context.rb
27
30
  - lib/pandoku/formats/html.rb
31
+ - lib/pandoku/formats/man.rb
28
32
  - lib/pandoku/formats/rst.rb
33
+ - lib/pandoku/formats/latex.rb
29
34
  - lib/pandoku/formats/markdown.rb
30
35
  - lib/pandoku/document.rb
36
+ - lib/pandoku/lookup_table.rb
31
37
  - lib/pandoku/format.rb
32
38
  has_rdoc: true
33
39
  homepage: http://github.com/dahlia/pandoku