org-ruby 0.5.1 → 0.5.2

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.
Files changed (89) hide show
  1. data/History.txt +81 -77
  2. data/README.rdoc +66 -66
  3. data/Rakefile +28 -28
  4. data/bin/org-ruby +40 -40
  5. data/lib/org-ruby.rb +50 -50
  6. data/lib/org-ruby/headline.rb +102 -120
  7. data/lib/org-ruby/html_output_buffer.rb +174 -156
  8. data/lib/org-ruby/line.rb +206 -260
  9. data/lib/org-ruby/output_buffer.rb +227 -191
  10. data/lib/org-ruby/parser.rb +320 -272
  11. data/lib/org-ruby/regexp_helper.rb +156 -156
  12. data/lib/org-ruby/textile_output_buffer.rb +67 -68
  13. data/spec/data/freeform-example.org +113 -113
  14. data/spec/data/freeform.org +111 -111
  15. data/spec/data/hyp-planning.org +335 -335
  16. data/spec/data/remember.org +53 -53
  17. data/spec/headline_spec.rb +55 -55
  18. data/spec/html_examples/advanced-code.html +36 -36
  19. data/spec/html_examples/advanced-code.org +53 -53
  20. data/spec/html_examples/advanced-lists.html +31 -31
  21. data/spec/html_examples/advanced-lists.org +31 -31
  22. data/spec/html_examples/block_code.html +28 -28
  23. data/spec/html_examples/block_code.org +35 -35
  24. data/spec/html_examples/blockquote.html +7 -7
  25. data/spec/html_examples/blockquote.org +13 -13
  26. data/spec/html_examples/code-comment.html +18 -18
  27. data/spec/html_examples/code-comment.org +22 -22
  28. data/spec/html_examples/custom-seq-todo.html +15 -15
  29. data/spec/html_examples/custom-seq-todo.org +24 -24
  30. data/spec/html_examples/custom-todo.html +15 -15
  31. data/spec/html_examples/custom-todo.org +24 -24
  32. data/spec/html_examples/custom-typ-todo.html +15 -15
  33. data/spec/html_examples/custom-typ-todo.org +24 -24
  34. data/spec/html_examples/entities.html +4 -4
  35. data/spec/html_examples/entities.org +11 -11
  36. data/spec/html_examples/escape-pre.html +6 -6
  37. data/spec/html_examples/escape-pre.org +6 -6
  38. data/spec/html_examples/export-exclude-only.html +13 -13
  39. data/spec/html_examples/export-exclude-only.org +81 -81
  40. data/spec/html_examples/export-keywords.html +4 -4
  41. data/spec/html_examples/export-keywords.org +18 -18
  42. data/spec/html_examples/export-tags.html +8 -8
  43. data/spec/html_examples/export-tags.org +82 -82
  44. data/spec/html_examples/export-title.html +2 -2
  45. data/spec/html_examples/export-title.org +4 -4
  46. data/spec/html_examples/html-literal.html +2 -2
  47. data/spec/html_examples/html-literal.org +6 -6
  48. data/spec/html_examples/inline-formatting.html +10 -10
  49. data/spec/html_examples/inline-formatting.org +17 -17
  50. data/spec/html_examples/link-features.html +8 -8
  51. data/spec/html_examples/link-features.org +19 -19
  52. data/spec/html_examples/lists.html +19 -19
  53. data/spec/html_examples/lists.org +36 -36
  54. data/spec/html_examples/metadata-comment.html +27 -27
  55. data/spec/html_examples/metadata-comment.org +30 -30
  56. data/spec/html_examples/only-list.html +5 -5
  57. data/spec/html_examples/only-list.org +3 -3
  58. data/spec/html_examples/only-table.html +6 -6
  59. data/spec/html_examples/only-table.org +5 -5
  60. data/spec/html_examples/skip-header.html +3 -3
  61. data/spec/html_examples/skip-header.org +28 -28
  62. data/spec/html_examples/skip-table.html +4 -4
  63. data/spec/html_examples/skip-table.org +19 -19
  64. data/spec/html_examples/tables.html +20 -20
  65. data/spec/html_examples/tables.org +26 -26
  66. data/spec/html_examples/text.html +2 -2
  67. data/spec/html_examples/text.org +16 -16
  68. data/spec/line_spec.rb +151 -151
  69. data/spec/output_buffer_spec.rb +19 -0
  70. data/spec/parser_spec.rb +152 -166
  71. data/spec/regexp_helper_spec.rb +57 -57
  72. data/spec/spec_helper.rb +21 -21
  73. data/spec/textile_examples/block_code.org +35 -35
  74. data/spec/textile_examples/block_code.textile +29 -29
  75. data/spec/textile_examples/blockquote.org +13 -13
  76. data/spec/textile_examples/blockquote.textile +11 -11
  77. data/spec/textile_examples/keywords.org +13 -13
  78. data/spec/textile_examples/keywords.textile +11 -11
  79. data/spec/textile_examples/links.org +11 -11
  80. data/spec/textile_examples/links.textile +10 -10
  81. data/spec/textile_examples/lists.org +36 -36
  82. data/spec/textile_examples/lists.textile +20 -20
  83. data/spec/textile_examples/single-space-plain-list.org +13 -13
  84. data/spec/textile_examples/single-space-plain-list.textile +10 -10
  85. data/spec/textile_examples/tables.org +26 -26
  86. data/spec/textile_examples/tables.textile +23 -23
  87. data/spec/textile_output_buffer_spec.rb +21 -21
  88. data/tasks/test_case.rake +49 -49
  89. metadata +3 -2
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe Orgmode::OutputBuffer do
4
+
5
+ it "computes outline level numbering" do
6
+ output_buffer = Orgmode::OutputBuffer.new ""
7
+ output_buffer.get_next_headline_number(1).should eql("1")
8
+ output_buffer.get_next_headline_number(1).should eql("2")
9
+ output_buffer.get_next_headline_number(1).should eql("3")
10
+ output_buffer.get_next_headline_number(1).should eql("4")
11
+ output_buffer.get_next_headline_number(2).should eql("4.1")
12
+ output_buffer.get_next_headline_number(2).should eql("4.2")
13
+ output_buffer.get_next_headline_number(1).should eql("5")
14
+ output_buffer.get_next_headline_number(2).should eql("5.1")
15
+ output_buffer.get_next_headline_number(2).should eql("5.2")
16
+ output_buffer.get_next_headline_number(4).should eql("5.2.0.1")
17
+ end
18
+
19
+ end
data/spec/parser_spec.rb CHANGED
@@ -1,166 +1,152 @@
1
-
2
- require File.join(File.dirname(__FILE__), %w[spec_helper])
3
-
4
- describe Orgmode::Parser do
5
- it "should open ORG files" do
6
- parser = Orgmode::Parser.load(RememberFile)
7
- end
8
-
9
- it "should fail on non-existant files" do
10
- lambda { parser = Orgmode::Parser.load("does-not-exist.org") }.should raise_error
11
- end
12
-
13
- it "should load all of the lines" do
14
- parser = Orgmode::Parser.load(RememberFile)
15
- parser.lines.length.should eql(53)
16
- end
17
-
18
- it "should find all headlines" do
19
- parser = Orgmode::Parser.load(RememberFile)
20
- parser.should have(12).headlines
21
- end
22
-
23
- it "can find a headline by index" do
24
- parser = Orgmode::Parser.load(RememberFile)
25
- parser.headlines[1].line.should eql("** YAML header in Webby\n")
26
- end
27
-
28
- it "should determine headline levels" do
29
- parser = Orgmode::Parser.load(RememberFile)
30
- parser.headlines[0].level.should eql(1)
31
- parser.headlines[1].level.should eql(2)
32
- end
33
-
34
- it "should put body lines in headlines" do
35
- parser = Orgmode::Parser.load(RememberFile)
36
- parser.headlines[0].should have(0).body_lines
37
- parser.headlines[1].should have(6).body_lines
38
- end
39
-
40
- it "should understand lines before the first headline" do
41
- parser = Orgmode::Parser.load(FreeformFile)
42
- parser.should have(19).header_lines
43
- end
44
-
45
- it "should load in-buffer settings" do
46
- parser = Orgmode::Parser.load(FreeformFile)
47
- parser.should have(12).in_buffer_settings
48
- parser.in_buffer_settings["TITLE"].should eql("Freeform")
49
- parser.in_buffer_settings["EMAIL"].should eql("bdewey@gmail.com")
50
- parser.in_buffer_settings["LANGUAGE"].should eql("en")
51
- end
52
-
53
- it "should understand OPTIONS" do
54
- parser = Orgmode::Parser.load(FreeformFile)
55
- parser.should have(19).options
56
- parser.options["TeX"].should eql("t")
57
- parser.options["todo"].should eql("t")
58
- parser.options["\\n"].should eql("nil")
59
- parser.export_todo?.should be_true
60
- parser.options.delete("todo")
61
- parser.export_todo?.should be_false
62
- end
63
-
64
- it "computes outline level numbering" do
65
- parser = Orgmode::Parser.new ""
66
- parser.get_next_headline_number(1).should eql("1")
67
- parser.get_next_headline_number(1).should eql("2")
68
- parser.get_next_headline_number(1).should eql("3")
69
- parser.get_next_headline_number(1).should eql("4")
70
- parser.get_next_headline_number(2).should eql("4.1")
71
- parser.get_next_headline_number(2).should eql("4.2")
72
- parser.get_next_headline_number(1).should eql("5")
73
- parser.get_next_headline_number(2).should eql("5.1")
74
- parser.get_next_headline_number(2).should eql("5.2")
75
- parser.get_next_headline_number(4).should eql("5.2.0.1")
76
- end
77
-
78
- it "should skip in-buffer settings inside EXAMPLE blocks" do
79
- parser = Orgmode::Parser.load(FreeformExampleFile)
80
- parser.should have(0).in_buffer_settings
81
- end
82
-
83
- it "should return a textile string" do
84
- parser = Orgmode::Parser.load(FreeformFile)
85
- parser.to_textile.should be_kind_of(String)
86
- end
87
-
88
- it "should understand export table option" do
89
- fname = File.join(File.dirname(__FILE__), %w[html_examples skip-table.org])
90
- data = IO.read(fname)
91
- p = Orgmode::Parser.new(data)
92
- p.export_tables?.should be_false
93
- end
94
-
95
- describe "Custom keyword parser" do
96
- fname = File.join(File.dirname(__FILE__), %w[html_examples custom-todo.org])
97
- p = Orgmode::Parser.load(fname)
98
- valid_keywords = %w[TODO INPROGRESS WAITING DONE CANCELED]
99
- invalid_keywords = %w[TODOX todo inprogress Waiting done cANCELED NEXT |]
100
- valid_keywords.each do |kw|
101
- it "should match custom keyword #{kw}" do
102
- (kw =~ p.custom_keyword_regexp).should be_true
103
- end
104
- end
105
- invalid_keywords.each do |kw|
106
- it "should not match custom keyword #{kw}" do
107
- (kw =~ p.custom_keyword_regexp).should be_nil
108
- end
109
- end
110
- it "should not match blank as a custom keyword" do
111
- ("" =~ p.custom_keyword_regexp).should be_nil
112
- end
113
- end
114
-
115
- describe "Custom include/exclude parser" do
116
- fname = File.join(File.dirname(__FILE__), %w[html_examples export-tags.org])
117
- p = Orgmode::Parser.load(fname)
118
- it "should load tags" do
119
- p.should have(2).export_exclude_tags
120
- p.should have(1).export_select_tags
121
- end
122
- end
123
-
124
- describe "Export to Textile test cases" do
125
- data_directory = File.join(File.dirname(__FILE__), "textile_examples")
126
- org_files = File.expand_path(File.join(data_directory, "*.org" ))
127
- files = Dir.glob(org_files)
128
- files.each do |file|
129
- basename = File.basename(file, ".org")
130
- textile_name = File.join(data_directory, basename + ".textile")
131
- textile_name = File.expand_path(textile_name)
132
-
133
- it "should convert #{basename}.org to Textile" do
134
- expected = IO.read(textile_name)
135
- expected.should be_kind_of(String)
136
- parser = Orgmode::Parser.new(IO.read(file))
137
- actual = parser.to_textile
138
- actual.should be_kind_of(String)
139
- actual.should == expected
140
- end
141
- end
142
- end
143
-
144
- describe "Export to HTML test cases" do
145
- # Dynamic generation of examples from each *.org file in html_examples.
146
- # Each of these files is convertable to HTML.
147
- data_directory = File.join(File.dirname(__FILE__), "html_examples")
148
- org_files = File.expand_path(File.join(data_directory, "*.org" ))
149
- files = Dir.glob(org_files)
150
- files.each do |file|
151
- basename = File.basename(file, ".org")
152
- textile_name = File.join(data_directory, basename + ".html")
153
- textile_name = File.expand_path(textile_name)
154
-
155
- it "should convert #{basename}.org to HTML" do
156
- expected = IO.read(textile_name)
157
- expected.should be_kind_of(String)
158
- parser = Orgmode::Parser.new(IO.read(file))
159
- actual = parser.to_html
160
- actual.should be_kind_of(String)
161
- actual.should == expected
162
- end
163
- end
164
- end
165
- end
166
-
1
+
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+
4
+ describe Orgmode::Parser do
5
+ it "should open ORG files" do
6
+ parser = Orgmode::Parser.load(RememberFile)
7
+ end
8
+
9
+ it "should fail on non-existant files" do
10
+ lambda { parser = Orgmode::Parser.load("does-not-exist.org") }.should raise_error
11
+ end
12
+
13
+ it "should load all of the lines" do
14
+ parser = Orgmode::Parser.load(RememberFile)
15
+ parser.lines.length.should eql(53)
16
+ end
17
+
18
+ it "should find all headlines" do
19
+ parser = Orgmode::Parser.load(RememberFile)
20
+ parser.should have(12).headlines
21
+ end
22
+
23
+ it "can find a headline by index" do
24
+ parser = Orgmode::Parser.load(RememberFile)
25
+ parser.headlines[1].line.should eql("** YAML header in Webby\n")
26
+ end
27
+
28
+ it "should determine headline levels" do
29
+ parser = Orgmode::Parser.load(RememberFile)
30
+ parser.headlines[0].level.should eql(1)
31
+ parser.headlines[1].level.should eql(2)
32
+ end
33
+
34
+ it "should put body lines in headlines" do
35
+ parser = Orgmode::Parser.load(RememberFile)
36
+ parser.headlines[0].should have(1).body_lines
37
+ parser.headlines[1].should have(7).body_lines
38
+ end
39
+
40
+ it "should understand lines before the first headline" do
41
+ parser = Orgmode::Parser.load(FreeformFile)
42
+ parser.should have(19).header_lines
43
+ end
44
+
45
+ it "should load in-buffer settings" do
46
+ parser = Orgmode::Parser.load(FreeformFile)
47
+ parser.should have(12).in_buffer_settings
48
+ parser.in_buffer_settings["TITLE"].should eql("Freeform")
49
+ parser.in_buffer_settings["EMAIL"].should eql("bdewey@gmail.com")
50
+ parser.in_buffer_settings["LANGUAGE"].should eql("en")
51
+ end
52
+
53
+ it "should understand OPTIONS" do
54
+ parser = Orgmode::Parser.load(FreeformFile)
55
+ parser.should have(19).options
56
+ parser.options["TeX"].should eql("t")
57
+ parser.options["todo"].should eql("t")
58
+ parser.options["\\n"].should eql("nil")
59
+ parser.export_todo?.should be_true
60
+ parser.options.delete("todo")
61
+ parser.export_todo?.should be_false
62
+ end
63
+
64
+ it "should skip in-buffer settings inside EXAMPLE blocks" do
65
+ parser = Orgmode::Parser.load(FreeformExampleFile)
66
+ parser.should have(0).in_buffer_settings
67
+ end
68
+
69
+ it "should return a textile string" do
70
+ parser = Orgmode::Parser.load(FreeformFile)
71
+ parser.to_textile.should be_kind_of(String)
72
+ end
73
+
74
+ it "should understand export table option" do
75
+ fname = File.join(File.dirname(__FILE__), %w[html_examples skip-table.org])
76
+ data = IO.read(fname)
77
+ p = Orgmode::Parser.new(data)
78
+ p.export_tables?.should be_false
79
+ end
80
+
81
+ describe "Custom keyword parser" do
82
+ fname = File.join(File.dirname(__FILE__), %w[html_examples custom-todo.org])
83
+ p = Orgmode::Parser.load(fname)
84
+ valid_keywords = %w[TODO INPROGRESS WAITING DONE CANCELED]
85
+ invalid_keywords = %w[TODOX todo inprogress Waiting done cANCELED NEXT |]
86
+ valid_keywords.each do |kw|
87
+ it "should match custom keyword #{kw}" do
88
+ (kw =~ p.custom_keyword_regexp).should be_true
89
+ end
90
+ end
91
+ invalid_keywords.each do |kw|
92
+ it "should not match custom keyword #{kw}" do
93
+ (kw =~ p.custom_keyword_regexp).should be_nil
94
+ end
95
+ end
96
+ it "should not match blank as a custom keyword" do
97
+ ("" =~ p.custom_keyword_regexp).should be_nil
98
+ end
99
+ end
100
+
101
+ describe "Custom include/exclude parser" do
102
+ fname = File.join(File.dirname(__FILE__), %w[html_examples export-tags.org])
103
+ p = Orgmode::Parser.load(fname)
104
+ it "should load tags" do
105
+ p.should have(2).export_exclude_tags
106
+ p.should have(1).export_select_tags
107
+ end
108
+ end
109
+
110
+ describe "Export to Textile test cases" do
111
+ data_directory = File.join(File.dirname(__FILE__), "textile_examples")
112
+ org_files = File.expand_path(File.join(data_directory, "*.org" ))
113
+ files = Dir.glob(org_files)
114
+ files.each do |file|
115
+ basename = File.basename(file, ".org")
116
+ textile_name = File.join(data_directory, basename + ".textile")
117
+ textile_name = File.expand_path(textile_name)
118
+
119
+ it "should convert #{basename}.org to Textile" do
120
+ expected = IO.read(textile_name)
121
+ expected.should be_kind_of(String)
122
+ parser = Orgmode::Parser.new(IO.read(file))
123
+ actual = parser.to_textile
124
+ actual.should be_kind_of(String)
125
+ actual.should == expected
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "Export to HTML test cases" do
131
+ # Dynamic generation of examples from each *.org file in html_examples.
132
+ # Each of these files is convertable to HTML.
133
+ data_directory = File.join(File.dirname(__FILE__), "html_examples")
134
+ org_files = File.expand_path(File.join(data_directory, "*.org" ))
135
+ files = Dir.glob(org_files)
136
+ files.each do |file|
137
+ basename = File.basename(file, ".org")
138
+ textile_name = File.join(data_directory, basename + ".html")
139
+ textile_name = File.expand_path(textile_name)
140
+
141
+ it "should convert #{basename}.org to HTML" do
142
+ expected = IO.read(textile_name)
143
+ expected.should be_kind_of(String)
144
+ parser = Orgmode::Parser.new(IO.read(file))
145
+ actual = parser.to_html
146
+ actual.should be_kind_of(String)
147
+ actual.should == expected
148
+ end
149
+ end
150
+ end
151
+ end
152
+
@@ -1,57 +1,57 @@
1
- require File.join(File.dirname(__FILE__), %w[spec_helper])
2
-
3
- describe Orgmode::RegexpHelper do
4
- it "should recognize simple markup" do
5
- e = Orgmode::RegexpHelper.new
6
- total = 0
7
- e.match_all("/italic/") do |border, string|
8
- border.should eql("/")
9
- string.should eql("italic")
10
- total += 1
11
- end
12
- total.should eql(1)
13
-
14
- total = 0
15
- borders = %w[* / ~]
16
- strings = %w[bold italic verbatim]
17
- e.match_all("This string contains *bold*, /italic/, and ~verbatim~ text.")\
18
- do |border, str|
19
- border.should eql(borders[total])
20
- str.should eql(strings[total])
21
- total += 1
22
- end
23
- total.should eql(3)
24
- end
25
-
26
- it "should not get confused by links" do
27
- e = Orgmode::RegexpHelper.new
28
- total = 0
29
- # Make sure the slashes in these links aren't treated as italics
30
- e.match_all("[[http://www.bing.com/twitter]]") do |border, str|
31
- total += 1
32
- end
33
- total.should eql(0)
34
- end
35
-
36
- it "should correctly perform substitutions" do
37
- e = Orgmode::RegexpHelper.new
38
- map = {
39
- "*" => "strong",
40
- "/" => "i",
41
- "~" => "pre"
42
- }
43
- n = e.rewrite_emphasis("This string contains *bold*, /italic/, and ~verbatim~ text.") do |border, str|
44
- "<#{map[border]}>#{str}</#{map[border]}>"
45
- end
46
- n.should eql("This string contains <strong>bold</strong>, <i>italic</i>, and <pre>verbatim</pre> text.")
47
- end
48
-
49
- it "should allow link rewriting" do
50
- e = Orgmode::RegexpHelper.new
51
- str = e.rewrite_links("[[http://www.bing.com]]") do |link,text|
52
- text ||= link
53
- "\"#{text}\":#{link}"
54
- end
55
- str.should eql("\"http://www.bing.com\":http://www.bing.com")
56
- end
57
- end # describe Orgmode::RegexpHelper
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe Orgmode::RegexpHelper do
4
+ it "should recognize simple markup" do
5
+ e = Orgmode::RegexpHelper.new
6
+ total = 0
7
+ e.match_all("/italic/") do |border, string|
8
+ border.should eql("/")
9
+ string.should eql("italic")
10
+ total += 1
11
+ end
12
+ total.should eql(1)
13
+
14
+ total = 0
15
+ borders = %w[* / ~]
16
+ strings = %w[bold italic verbatim]
17
+ e.match_all("This string contains *bold*, /italic/, and ~verbatim~ text.")\
18
+ do |border, str|
19
+ border.should eql(borders[total])
20
+ str.should eql(strings[total])
21
+ total += 1
22
+ end
23
+ total.should eql(3)
24
+ end
25
+
26
+ it "should not get confused by links" do
27
+ e = Orgmode::RegexpHelper.new
28
+ total = 0
29
+ # Make sure the slashes in these links aren't treated as italics
30
+ e.match_all("[[http://www.bing.com/twitter]]") do |border, str|
31
+ total += 1
32
+ end
33
+ total.should eql(0)
34
+ end
35
+
36
+ it "should correctly perform substitutions" do
37
+ e = Orgmode::RegexpHelper.new
38
+ map = {
39
+ "*" => "strong",
40
+ "/" => "i",
41
+ "~" => "pre"
42
+ }
43
+ n = e.rewrite_emphasis("This string contains *bold*, /italic/, and ~verbatim~ text.") do |border, str|
44
+ "<#{map[border]}>#{str}</#{map[border]}>"
45
+ end
46
+ n.should eql("This string contains <strong>bold</strong>, <i>italic</i>, and <pre>verbatim</pre> text.")
47
+ end
48
+
49
+ it "should allow link rewriting" do
50
+ e = Orgmode::RegexpHelper.new
51
+ str = e.rewrite_links("[[http://www.bing.com]]") do |link,text|
52
+ text ||= link
53
+ "\"#{text}\":#{link}"
54
+ end
55
+ str.should eql("\"http://www.bing.com\":http://www.bing.com")
56
+ end
57
+ end # describe Orgmode::RegexpHelper