org-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/History.txt +32 -24
  2. data/README.txt +66 -66
  3. data/Rakefile +26 -22
  4. data/bin/org-ruby +40 -40
  5. data/lib/org-ruby.rb +50 -48
  6. data/lib/org-ruby/headline.rb +75 -75
  7. data/lib/org-ruby/html_output_buffer.rb +81 -80
  8. data/lib/org-ruby/line.rb +173 -172
  9. data/lib/org-ruby/output_buffer.rb +154 -154
  10. data/lib/org-ruby/parser.rb +76 -72
  11. data/lib/org-ruby/regexp_helper.rb +156 -156
  12. data/lib/org-ruby/textile_output_buffer.rb +67 -67
  13. data/spec/data/freeform.org +111 -111
  14. data/spec/data/hyp-planning.org +335 -335
  15. data/spec/data/remember.org +53 -53
  16. data/spec/headline_spec.rb +55 -55
  17. data/spec/html_examples/block_code.html +30 -29
  18. data/spec/html_examples/block_code.org +35 -35
  19. data/spec/html_examples/blockquote.html +7 -7
  20. data/spec/html_examples/blockquote.org +13 -13
  21. data/spec/html_examples/escape-pre.html +7 -0
  22. data/spec/html_examples/escape-pre.org +6 -0
  23. data/spec/html_examples/inline-formatting.html +10 -10
  24. data/spec/html_examples/inline-formatting.org +17 -17
  25. data/spec/html_examples/lists.html +19 -19
  26. data/spec/html_examples/lists.org +36 -36
  27. data/spec/html_examples/only-list.html +5 -0
  28. data/spec/html_examples/only-list.org +3 -0
  29. data/spec/html_examples/only-table.html +6 -0
  30. data/spec/html_examples/only-table.org +5 -0
  31. data/spec/html_examples/tables.html +20 -20
  32. data/spec/html_examples/tables.org +26 -26
  33. data/spec/html_examples/text.html +2 -2
  34. data/spec/html_examples/text.org +16 -16
  35. data/spec/line_spec.rb +89 -89
  36. data/spec/parser_spec.rb +86 -86
  37. data/spec/regexp_helper_spec.rb +57 -57
  38. data/spec/spec_helper.rb +20 -20
  39. data/spec/textile_examples/block_code.org +35 -35
  40. data/spec/textile_examples/block_code.textile +29 -29
  41. data/spec/textile_examples/blockquote.org +13 -13
  42. data/spec/textile_examples/blockquote.textile +11 -11
  43. data/spec/textile_examples/keywords.org +13 -13
  44. data/spec/textile_examples/keywords.textile +11 -11
  45. data/spec/textile_examples/links.org +11 -11
  46. data/spec/textile_examples/links.textile +10 -10
  47. data/spec/textile_examples/lists.org +36 -36
  48. data/spec/textile_examples/lists.textile +20 -20
  49. data/spec/textile_examples/single-space-plain-list.org +13 -13
  50. data/spec/textile_examples/single-space-plain-list.textile +10 -10
  51. data/spec/textile_examples/tables.org +26 -26
  52. data/spec/textile_examples/tables.textile +23 -23
  53. data/spec/textile_output_buffer_spec.rb +21 -21
  54. data/tasks/test_case.rake +49 -0
  55. metadata +21 -5
  56. data/.bnsignore +0 -18
@@ -1,24 +1,32 @@
1
- == 0.2.0 / 2009-12-26
2
-
3
- * Renamed the gem to org-ruby
4
- * Added +to_html+ for HTML output
5
- * Now supports the following inline markup:
6
- * bold
7
- * italic
8
- * code
9
- * verbatim
10
- * underline
11
- * strikethrough
12
- * Continued code cleanup and refactoring
13
-
14
- == 0.1.0 / 2009-12-23
15
-
16
- * Added support for block code
17
- * Added support for list items that wrap in the org source
18
- * Major code cleanup:
19
- Added +OutputBuffer+ class that should make the code more maintainable.
20
-
21
- == 0.0.2 / 2009-12-21
22
-
23
- * Initial version. Handles tables (but not headers), headlines,
24
- paragraphs, block quotes, strong & emphasis formatting.
1
+ == 0.3.0 / 2009-12-27
2
+
3
+ * Uses rubypants to get better typography (smart quotes, elipses, etc.).
4
+ * Fixed bugs:
5
+ * Tables and lists did not get properly closed at the end of file
6
+ * You couldn't do inline formatting inside table cells
7
+ * Characters in PRE blocks were not HTML escaped.
8
+
9
+ == 0.2.0 / 2009-12-26
10
+
11
+ * Renamed the gem to org-ruby
12
+ * Added +to_html+ for HTML output
13
+ * Now supports the following inline markup:
14
+ * bold
15
+ * italic
16
+ * code
17
+ * verbatim
18
+ * underline
19
+ * strikethrough
20
+ * Continued code cleanup and refactoring
21
+
22
+ == 0.1.0 / 2009-12-23
23
+
24
+ * Added support for block code
25
+ * Added support for list items that wrap in the org source
26
+ * Major code cleanup:
27
+ Added +OutputBuffer+ class that should make the code more maintainable.
28
+
29
+ == 0.0.2 / 2009-12-21
30
+
31
+ * Initial version. Handles tables (but not headers), headlines,
32
+ paragraphs, block quotes, strong & emphasis formatting.
data/README.txt CHANGED
@@ -1,66 +1,66 @@
1
- org-ruby
2
- by Brian Dewey
3
- http://www.bdewey.com
4
-
5
- == DESCRIPTION:
6
-
7
- This gem contains Ruby routines for parsing org-mode files.The most
8
- significant thing this library does today is convert org-mode files to
9
- HTML or textile. Currently, you cannot do much to customize the
10
- conversion. The supplied textile conversion is optimized for
11
- extracting "content" from the orgfile as opposed to "metadata."
12
-
13
- == FEATURES/PROBLEMS:
14
-
15
- * Converts org-mode files to HTML or Textile
16
- * Supports tables, block quotes, and block code
17
- * Supports bold, italic, underline, strikethrough, and code inline formatting.
18
- * Supports hyperlinks that are in double-brackets
19
- * Upcoming: Handle export options specified in the org buffer.
20
-
21
- == SYNOPSIS:
22
-
23
- From the command line:
24
-
25
- org-ruby sample.org
26
-
27
- ...will output a HTML version of sample.org.
28
-
29
- org-ruby --translate textile sample.org
30
-
31
- ...will output a textile version of sample.org.
32
-
33
- From Ruby code:
34
-
35
- Orgmode::Parser.new(data)
36
-
37
- ...will construct a new +Parser+ object.
38
-
39
- == INSTALL:
40
-
41
- sudo gem install org-ruby
42
-
43
- == LICENSE:
44
-
45
- (The MIT License)
46
-
47
- Copyright (c) 2009 Brian Dewey
48
-
49
- Permission is hereby granted, free of charge, to any person obtaining
50
- a copy of this software and associated documentation files (the
51
- 'Software'), to deal in the Software without restriction, including
52
- without limitation the rights to use, copy, modify, merge, publish,
53
- distribute, sublicense, and/or sell copies of the Software, and to
54
- permit persons to whom the Software is furnished to do so, subject to
55
- the following conditions:
56
-
57
- The above copyright notice and this permission notice shall be
58
- included in all copies or substantial portions of the Software.
59
-
60
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ org-ruby
2
+ by Brian Dewey
3
+ http://github.com/bdewey/org-ruby
4
+
5
+ == DESCRIPTION:
6
+
7
+ This gem contains Ruby routines for parsing org-mode files.The most
8
+ significant thing this library does today is convert org-mode files to
9
+ HTML or textile. Currently, you cannot do much to customize the
10
+ conversion. The supplied textile conversion is optimized for
11
+ extracting "content" from the orgfile as opposed to "metadata."
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * Converts org-mode files to HTML or Textile
16
+ * Supports tables, block quotes, and block code
17
+ * Supports bold, italic, underline, strikethrough, and code inline formatting.
18
+ * Supports hyperlinks that are in double-brackets
19
+ * Upcoming: Handle export options specified in the org buffer.
20
+
21
+ == SYNOPSIS:
22
+
23
+ From the command line:
24
+
25
+ org-ruby sample.org
26
+
27
+ ...will output a HTML version of sample.org.
28
+
29
+ org-ruby --translate textile sample.org
30
+
31
+ ...will output a textile version of sample.org.
32
+
33
+ From Ruby code:
34
+
35
+ Orgmode::Parser.new(data)
36
+
37
+ ...will construct a new +Parser+ object.
38
+
39
+ == INSTALL:
40
+
41
+ sudo gem install org-ruby
42
+
43
+ == LICENSE:
44
+
45
+ (The MIT License)
46
+
47
+ Copyright (c) 2009 Brian Dewey
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,22 +1,26 @@
1
-
2
- begin
3
- require 'bones'
4
- rescue LoadError
5
- abort '### Please install the "bones" gem ###'
6
- end
7
-
8
- ensure_in_path 'lib'
9
- require 'org-ruby'
10
-
11
- task :default => 'test:run'
12
- task 'gem:release' => 'test:run'
13
-
14
- Bones {
15
- name 'org-ruby'
16
- authors 'Brian Dewey'
17
- email 'bdewey@gmail.com'
18
- url 'http://bdewey.com'
19
- version OrgRuby::VERSION
20
- }
21
-
22
- # EOF
1
+
2
+ begin
3
+ require 'bones'
4
+ rescue LoadError
5
+ abort '### Please install the "bones" gem ###'
6
+ end
7
+
8
+ ensure_in_path 'lib'
9
+ require 'org-ruby'
10
+
11
+ task :default => 'test:run'
12
+ task 'gem:release' => 'test:run'
13
+
14
+ Bones {
15
+ name 'org-ruby'
16
+ authors 'Brian Dewey'
17
+ email 'bdewey@gmail.com'
18
+ url 'http://github.com/bdewey/org-ruby'
19
+ version OrgRuby::VERSION
20
+ colorize false # Windows consoles won't colorize
21
+ gem.need_tar false # Can't TAR from Windows
22
+ depend_on 'rubypants'
23
+ }
24
+
25
+
26
+ # EOF
@@ -1,40 +1,40 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(
4
- File.join(File.dirname(__FILE__), %w[.. lib org-ruby]))
5
- require 'optparse'
6
-
7
- # Put your code here
8
-
9
- options = {}
10
- options_parser = OptionParser.new do |opts|
11
- options[:help] = false
12
- options[:format] = :html
13
-
14
- opts.banner = "Usage: org-ruby <file> [options]"
15
-
16
- opts.on("-h", "--help", "Show this message") do |v|
17
- options[:help] = true
18
- end
19
-
20
- opts.on("-t", "--translate FORMAT", [:html, :textile],
21
- "Translate the ORG file to the specified format.") do |v|
22
- options[:format] = v
23
- end
24
- end
25
-
26
- begin
27
- options_parser.parse!
28
- if (ARGV.length == 0) then
29
- puts options_parser
30
- else
31
- data = IO.read(ARGV[0])
32
- p = Orgmode::Parser.new(data)
33
- puts p.to_html if options[:format] == :html
34
- puts p.to_textile if options[:format] == :textile
35
- end
36
- rescue OptionParser::ParseError
37
- puts options_parser
38
- end
39
-
40
-
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib org-ruby]))
5
+ require 'optparse'
6
+
7
+ # Put your code here
8
+
9
+ options = {}
10
+ options_parser = OptionParser.new do |opts|
11
+ options[:help] = false
12
+ options[:format] = :html
13
+
14
+ opts.banner = "Usage: org-ruby <file> [options]"
15
+
16
+ opts.on("-h", "--help", "Show this message") do |v|
17
+ options[:help] = true
18
+ end
19
+
20
+ opts.on("-t", "--translate FORMAT", [:html, :textile],
21
+ "Translate the ORG file to the specified format.") do |v|
22
+ options[:format] = v
23
+ end
24
+ end
25
+
26
+ begin
27
+ options_parser.parse!
28
+ if (ARGV.length == 0) then
29
+ puts options_parser
30
+ else
31
+ data = IO.read(ARGV[0])
32
+ p = Orgmode::Parser.new(data)
33
+ puts p.to_html if options[:format] == :html
34
+ puts p.to_textile if options[:format] == :textile
35
+ end
36
+ rescue OptionParser::ParseError
37
+ puts options_parser
38
+ end
39
+
40
+
@@ -1,48 +1,50 @@
1
-
2
- module OrgRuby
3
-
4
- # :stopdoc:
5
- VERSION = '0.2.0'
6
- LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
- # :startdoc:
9
-
10
- # Returns the version string for the library.
11
- #
12
- def self.version
13
- VERSION
14
- end
15
-
16
- # Returns the library path for the module. If any arguments are given,
17
- # they will be joined to the end of the libray path using
18
- # <tt>File.join</tt>.
19
- #
20
- def self.libpath( *args )
21
- args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
- end
23
-
24
- # Returns the lpath for the module. If any arguments are given,
25
- # they will be joined to the end of the path using
26
- # <tt>File.join</tt>.
27
- #
28
- def self.path( *args )
29
- args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
- end
31
-
32
- # Utility method used to require all files ending in .rb that lie in the
33
- # directory below this file that has the same name as the filename passed
34
- # in. Optionally, a specific _directory_ name can be passed in such that
35
- # the _filename_ does not have to be equivalent to the directory.
36
- #
37
- def self.require_all_libs_relative_to( fname, dir = nil )
38
- dir ||= ::File.basename(fname, '.*')
39
- search_me = ::File.expand_path(
40
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
-
42
- Dir.glob(search_me).sort.each {|rb| require rb}
43
- end
44
-
45
- end # module OrgmodeParser
46
-
47
- OrgRuby.require_all_libs_relative_to(__FILE__)
48
-
1
+ unless defined? ::OrgRuby
2
+
3
+ module OrgRuby
4
+
5
+ # :stopdoc:
6
+ VERSION = '0.3.0'
7
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
8
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
9
+ # :startdoc:
10
+
11
+ # Returns the version string for the library.
12
+ #
13
+ def self.version
14
+ VERSION
15
+ end
16
+
17
+ # Returns the library path for the module. If any arguments are given,
18
+ # they will be joined to the end of the libray path using
19
+ # <tt>File.join</tt>.
20
+ #
21
+ def self.libpath( *args )
22
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
23
+ end
24
+
25
+ # Returns the lpath for the module. If any arguments are given,
26
+ # they will be joined to the end of the path using
27
+ # <tt>File.join</tt>.
28
+ #
29
+ def self.path( *args )
30
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
31
+ end
32
+
33
+ # Utility method used to require all files ending in .rb that lie in the
34
+ # directory below this file that has the same name as the filename passed
35
+ # in. Optionally, a specific _directory_ name can be passed in such that
36
+ # the _filename_ does not have to be equivalent to the directory.
37
+ #
38
+ def self.require_all_libs_relative_to( fname, dir = nil )
39
+ dir ||= ::File.basename(fname, '.*')
40
+ search_me = ::File.expand_path(
41
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
42
+
43
+ Dir.glob(search_me).sort.each {|rb| require rb}
44
+ end
45
+
46
+ end # module OrgmodeParser
47
+
48
+ OrgRuby.require_all_libs_relative_to(__FILE__)
49
+
50
+ end # unless defined?
@@ -1,75 +1,75 @@
1
- require OrgRuby.libpath(*%w[org-ruby line])
2
-
3
- module Orgmode
4
-
5
- # Represents a headline in an orgmode file.
6
- class Headline < Line
7
-
8
- # This is the "level" of the headline
9
- attr_reader :level
10
-
11
- # This is the headline text -- the part of the headline minus the leading
12
- # asterisks, the keywords, and the tags.
13
- attr_reader :headline_text
14
-
15
- # This contains the lines that "belong" to the headline.
16
- attr_reader :body_lines
17
-
18
- # These are the headline tags
19
- attr_reader :tags
20
-
21
- # Optional keyword found at the beginning of the headline.
22
- attr_reader :keyword
23
-
24
- # This is the regex that matches a line
25
- LineRegexp = /^\*+\s+/
26
-
27
- # This matches the tags on a headline
28
- TagsRegexp = /\s*:[\w:]*:\s*$/
29
-
30
- # Special keywords allowed at the start of a line.
31
- Keywords = %w[TODO DONE]
32
-
33
- KeywordsRegexp = Regexp.new("\\s*(#{Keywords.join('|')})\\s*")
34
-
35
- def initialize(line)
36
- super(line)
37
- @body_lines = []
38
- @tags = []
39
- if (@line =~ LineRegexp) then
40
- @level = $&.strip.length
41
- @headline_text = $'.strip
42
- if (@headline_text =~ TagsRegexp) then
43
- @tags = $&.split(/:/) # split tag text on semicolon
44
- @tags.delete_at(0) # the first item will be empty; discard
45
- @headline_text.gsub!(TagsRegexp, "") # Removes the tags from the headline
46
- end
47
- if (@headline_text =~ KeywordsRegexp) then
48
- @headline_text = $'
49
- @keyword = $1
50
- end
51
- else
52
- raise "'#{line}' is not a valid headline"
53
- end
54
- end
55
-
56
- # Determines if a line is an orgmode "headline":
57
- # A headline begins with one or more asterisks.
58
- def self.headline?(line)
59
- line =~ LineRegexp
60
- end
61
-
62
- # Converts this headline and its body to textile.
63
- def to_textile
64
- output = "h#{@level}. #{@headline_text}\n"
65
- output << Line.to_textile(@body_lines)
66
- output
67
- end
68
-
69
- def to_html
70
- output = "<h#{@level}>#{@headline_text}</h#{@level}>\n"
71
- output << Line.to_html(@body_lines)
72
- output
73
- end
74
- end # class Headline
75
- end # class Orgmode
1
+ require OrgRuby.libpath(*%w[org-ruby line])
2
+
3
+ module Orgmode
4
+
5
+ # Represents a headline in an orgmode file.
6
+ class Headline < Line
7
+
8
+ # This is the "level" of the headline
9
+ attr_reader :level
10
+
11
+ # This is the headline text -- the part of the headline minus the leading
12
+ # asterisks, the keywords, and the tags.
13
+ attr_reader :headline_text
14
+
15
+ # This contains the lines that "belong" to the headline.
16
+ attr_reader :body_lines
17
+
18
+ # These are the headline tags
19
+ attr_reader :tags
20
+
21
+ # Optional keyword found at the beginning of the headline.
22
+ attr_reader :keyword
23
+
24
+ # This is the regex that matches a line
25
+ LineRegexp = /^\*+\s+/
26
+
27
+ # This matches the tags on a headline
28
+ TagsRegexp = /\s*:[\w:]*:\s*$/
29
+
30
+ # Special keywords allowed at the start of a line.
31
+ Keywords = %w[TODO DONE]
32
+
33
+ KeywordsRegexp = Regexp.new("\\s*(#{Keywords.join('|')})\\s*")
34
+
35
+ def initialize(line)
36
+ super(line)
37
+ @body_lines = []
38
+ @tags = []
39
+ if (@line =~ LineRegexp) then
40
+ @level = $&.strip.length
41
+ @headline_text = $'.strip
42
+ if (@headline_text =~ TagsRegexp) then
43
+ @tags = $&.split(/:/) # split tag text on semicolon
44
+ @tags.delete_at(0) # the first item will be empty; discard
45
+ @headline_text.gsub!(TagsRegexp, "") # Removes the tags from the headline
46
+ end
47
+ if (@headline_text =~ KeywordsRegexp) then
48
+ @headline_text = $'
49
+ @keyword = $1
50
+ end
51
+ else
52
+ raise "'#{line}' is not a valid headline"
53
+ end
54
+ end
55
+
56
+ # Determines if a line is an orgmode "headline":
57
+ # A headline begins with one or more asterisks.
58
+ def self.headline?(line)
59
+ line =~ LineRegexp
60
+ end
61
+
62
+ # Converts this headline and its body to textile.
63
+ def to_textile
64
+ output = "h#{@level}. #{@headline_text}\n"
65
+ output << Line.to_textile(@body_lines)
66
+ output
67
+ end
68
+
69
+ def to_html
70
+ output = "<h#{@level}>#{@headline_text}</h#{@level}>\n"
71
+ output << Line.to_html(@body_lines)
72
+ output
73
+ end
74
+ end # class Headline
75
+ end # class Orgmode