org-ruby 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/History.txt +18 -0
  2. data/lib/org-ruby.rb +1 -1
  3. data/lib/org-ruby/headline.rb +49 -9
  4. data/lib/org-ruby/html_output_buffer.rb +37 -7
  5. data/lib/org-ruby/line.rb +34 -3
  6. data/lib/org-ruby/output_buffer.rb +2 -2
  7. data/lib/org-ruby/parser.rb +180 -10
  8. data/spec/data/freeform-example.org +113 -0
  9. data/spec/html_examples/custom-seq-todo.html +15 -0
  10. data/spec/html_examples/custom-seq-todo.org +24 -0
  11. data/spec/html_examples/custom-todo.html +15 -0
  12. data/spec/html_examples/custom-todo.org +24 -0
  13. data/spec/html_examples/custom-typ-todo.html +15 -0
  14. data/spec/html_examples/custom-typ-todo.org +24 -0
  15. data/spec/html_examples/entities.html +1 -0
  16. data/spec/html_examples/entities.org +3 -0
  17. data/spec/html_examples/export-exclude-only.html +13 -0
  18. data/spec/html_examples/export-exclude-only.org +81 -0
  19. data/spec/html_examples/export-keywords.html +4 -0
  20. data/spec/html_examples/export-keywords.org +18 -0
  21. data/spec/html_examples/export-tags.html +8 -0
  22. data/spec/html_examples/export-tags.org +82 -0
  23. data/spec/html_examples/export-title.html +2 -0
  24. data/spec/html_examples/export-title.org +4 -0
  25. data/spec/html_examples/link-features.html +8 -0
  26. data/spec/html_examples/link-features.org +19 -0
  27. data/spec/html_examples/only-table.html +1 -1
  28. data/spec/html_examples/skip-header.html +3 -0
  29. data/spec/html_examples/skip-header.org +28 -0
  30. data/spec/html_examples/skip-table.html +4 -0
  31. data/spec/html_examples/skip-table.org +19 -0
  32. data/spec/html_examples/tables.html +1 -1
  33. data/spec/line_spec.rb +35 -0
  34. data/spec/parser_spec.rb +94 -14
  35. data/spec/spec_helper.rb +1 -0
  36. metadata +23 -2
@@ -0,0 +1,2 @@
1
+ <p class="title">Export Title</p>
2
+ <p>This simple org document should get a title from the <code>TITLE</code> option at the front of the file.</p>
@@ -0,0 +1,4 @@
1
+ #+TITLE: Export Title
2
+
3
+ This simple org document should get a title from the =TITLE= option at
4
+ the front of the file.
@@ -0,0 +1,8 @@
1
+ <p class="title">link-features.org</p>
2
+ <p>Org-mode export supports a lot of link features. I&#8217;ve covered &#8220;simple&#8221; HTML links elsewhere. Now let&#8217;s cover links to other org files, other sections within documents, etc.</p>
3
+ <h1>Links to other org files</h1>
4
+ <p>This is a link to the <code>code-comment.org</code> file in the same directory. In <code>emacs</code>, if you click it, the other file opens. We want the same behavior in the HTML export.</p>
5
+ <p><a href="code-comment.html">Code Comment</a></p>
6
+ <h1>Search links</h1>
7
+ <p>This is a search link into code-comment.org.</p>
8
+ <p><a href="code-comment.html">Code Comment</a></p>
@@ -0,0 +1,19 @@
1
+ #+TITLE: link-features.org
2
+
3
+ Org-mode export supports a lot of link features. I've covered "simple"
4
+ HTML links elsewhere. Now let's cover links to other org files, other
5
+ sections within documents, etc.
6
+
7
+ * Links to other org files
8
+
9
+ This is a link to the ~code-comment.org~ file in the same
10
+ directory. In ~emacs~, if you click it, the other file opens. We
11
+ want the same behavior in the HTML export.
12
+
13
+ [[file:code-comment.org][Code Comment]]
14
+
15
+ * Search links
16
+
17
+ This is a search link into code-comment.org.
18
+
19
+ [[file:code-comment.org::*Code%20Comment][Code Comment]]
@@ -1,5 +1,5 @@
1
1
  <table>
2
- <tr><td>One</td><td>Two</td><td>Three</td><td>Four</td></tr>
2
+ <tr><th>One</th><th>Two</th><th>Three</th><th>Four</th></tr>
3
3
  <tr><td>Five</td><td>Six</td><td>Seven</td><td>Eight</td></tr>
4
4
  <tr><td>Nine</td><td>Ten</td><td>Eleven</td><td>Twelve</td></tr>
5
5
  <tr><td><b>format</b></td><td><i>text</i></td><td><code>in</code></td><td><span style="text-decoration:underline;">cells</span></td></tr>
@@ -0,0 +1,3 @@
1
+ <p class="title">skip-header.org</p>
2
+ <h1><span class="heading-number heading-number-1">1 </span>First heading</h1>
3
+ <p>This should be the first text in the output.</p>
@@ -0,0 +1,28 @@
1
+ #+TITLE: skip-header.org
2
+ #+AUTHOR:
3
+ #+EMAIL: brian@BRIAN-DESK
4
+ #+DATE: 2009-12-29 Tue
5
+ #+DESCRIPTION:
6
+ #+KEYWORDS:
7
+ #+LANGUAGE: en
8
+ #+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
9
+ #+OPTIONS: TeX:t LaTeX:nil skip:t d:nil todo:t pri:nil tags:not-in-toc
10
+ #+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
11
+ #+EXPORT_SELECT_TAGS: export
12
+ #+EXPORT_EXCLUDE_TAGS: noexport
13
+ #+LINK_UP:
14
+ #+LINK_HOME:
15
+ This is header text.
16
+ It exists in the org-file, but shouldn't show up in the HTML output.
17
+
18
+ - Same with this list
19
+ - Nope, shouldn't be in the output.
20
+
21
+ #+BEGIN_EXAMPLE
22
+ Even this code snippet shouldn't be there.
23
+ Like a ninja. You can't see me.
24
+ #+END_EXAMPLE
25
+
26
+ * First heading
27
+
28
+ This should be the first text in the output.
@@ -0,0 +1,4 @@
1
+ <p class="title">skip-table.org</p>
2
+ <p>Checking that tables are skipped when directed.</p>
3
+ <p>For grins, here&#8217;s another table without a header. Just keep the bases covered.</p>
4
+ <p>Again, in the HTML output, you should see <b>no tables</b>.</p>
@@ -0,0 +1,19 @@
1
+ #+TITLE: skip-table.org
2
+ #+OPTIONS: |:nil
3
+
4
+ Checking that tables are skipped when directed.
5
+
6
+ | One | Two | Three |
7
+ |-------+-------+-------|
8
+ | Four | Five | Six |
9
+ | Seven | Eight | Nine |
10
+
11
+
12
+ For grins, here's another table without a header. Just keep the bases
13
+ covered.
14
+
15
+ | One | Two | Three |
16
+ | Four | Five | Six |
17
+ | Seven | Eight | Nine |
18
+
19
+ Again, in the HTML output, you should see *no tables*.
@@ -13,7 +13,7 @@
13
13
  <p>And here&#8217;s some paragraph content. The line breaks will need to get removed here, but not for the tables.</p>
14
14
  <h1>Table with header</h1>
15
15
  <table>
16
- <tr><td>One</td><td>Two</td><td>Three</td></tr>
16
+ <tr><th>One</th><th>Two</th><th>Three</th></tr>
17
17
  <tr><td>Four</td><td>Five</td><td>Six</td></tr>
18
18
  <tr><td>Seven</td><td>Eight</td><td>Nine</td></tr>
19
19
  </table>
@@ -106,4 +106,39 @@ describe Orgmode::Line do
106
106
  l.paragraph_type.should eql(value)
107
107
  end
108
108
  end
109
+
110
+ it "should parse in-buffer settings" do
111
+ cases = {
112
+ "#+ARCHIVE: %s_done" => { :key => "ARCHIVE", :value => "%s_done" },
113
+ "#+CATEGORY: foo" => { :key => "CATEGORY", :value => "foo"},
114
+ "#+BEGIN_EXAMPLE:" => { :key => "BEGIN_EXAMPLE", :value => "" },
115
+ "#+A:" => { :key => "A", :value => "" } # Boundary: Smallest keyword is one letter
116
+ }
117
+ cases.each_pair do |key, value|
118
+ l = Orgmode::Line.new key
119
+ l.in_buffer_setting?.should be_true
120
+ called = nil
121
+ l.in_buffer_setting? do |k, v|
122
+ k.should eql(value[:key])
123
+ v.should eql(value[:value])
124
+ called = true
125
+ end
126
+ called.should be_true
127
+ end
128
+ end
129
+
130
+ it "should reject ill-formed settings" do
131
+ cases = [
132
+ "##+ARCHIVE: blah",
133
+ "#CATEGORY: foo",
134
+ "",
135
+ "\n",
136
+ " #+BEGIN_EXAMPLE:\n"
137
+ ]
138
+
139
+ cases.each do |c|
140
+ l = Orgmode::Line.new c
141
+ l.in_buffer_setting?.should be_nil
142
+ end
143
+ end
109
144
  end
@@ -42,12 +42,86 @@ describe Orgmode::Parser do
42
42
  parser.should have(19).header_lines
43
43
  end
44
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
+
45
83
  it "should return a textile string" do
46
84
  parser = Orgmode::Parser.load(FreeformFile)
47
85
  parser.to_textile.should be_kind_of(String)
48
86
  end
49
87
 
50
- it "can translate textile files" do
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
51
125
  data_directory = File.join(File.dirname(__FILE__), "textile_examples")
52
126
  org_files = File.expand_path(File.join(data_directory, "*.org" ))
53
127
  files = Dir.glob(org_files)
@@ -56,16 +130,20 @@ describe Orgmode::Parser do
56
130
  textile_name = File.join(data_directory, basename + ".textile")
57
131
  textile_name = File.expand_path(textile_name)
58
132
 
59
- expected = IO.read(textile_name)
60
- expected.should be_kind_of(String)
61
- parser = Orgmode::Parser.new(IO.read(file))
62
- actual = parser.to_textile
63
- actual.should be_kind_of(String)
64
- actual.should == expected
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
65
141
  end
66
142
  end
67
143
 
68
- it "can translate to html" do
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.
69
147
  data_directory = File.join(File.dirname(__FILE__), "html_examples")
70
148
  org_files = File.expand_path(File.join(data_directory, "*.org" ))
71
149
  files = Dir.glob(org_files)
@@ -74,12 +152,14 @@ describe Orgmode::Parser do
74
152
  textile_name = File.join(data_directory, basename + ".html")
75
153
  textile_name = File.expand_path(textile_name)
76
154
 
77
- expected = IO.read(textile_name)
78
- expected.should be_kind_of(String)
79
- parser = Orgmode::Parser.new(IO.read(file))
80
- actual = parser.to_html
81
- actual.should be_kind_of(String)
82
- actual.should == expected
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
83
163
  end
84
164
  end
85
165
  end
@@ -5,6 +5,7 @@ require File.expand_path(
5
5
 
6
6
  RememberFile = File.join(File.dirname(__FILE__), %w[data remember.org])
7
7
  FreeformFile = File.join(File.dirname(__FILE__), %w[data freeform.org])
8
+ FreeformExampleFile = File.join(File.dirname(__FILE__), %w[data freeform-example.org])
8
9
 
9
10
 
10
11
  Spec::Runner.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: org-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dewey
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-29 00:00:00 -08:00
12
+ date: 2009-12-30 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,7 @@ files:
60
60
  - lib/org-ruby/parser.rb
61
61
  - lib/org-ruby/regexp_helper.rb
62
62
  - lib/org-ruby/textile_output_buffer.rb
63
+ - spec/data/freeform-example.org
63
64
  - spec/data/freeform.org
64
65
  - spec/data/hyp-planning.org
65
66
  - spec/data/remember.org
@@ -72,14 +73,30 @@ files:
72
73
  - spec/html_examples/blockquote.org
73
74
  - spec/html_examples/code-comment.html
74
75
  - spec/html_examples/code-comment.org
76
+ - spec/html_examples/custom-seq-todo.html
77
+ - spec/html_examples/custom-seq-todo.org
78
+ - spec/html_examples/custom-todo.html
79
+ - spec/html_examples/custom-todo.org
80
+ - spec/html_examples/custom-typ-todo.html
81
+ - spec/html_examples/custom-typ-todo.org
75
82
  - spec/html_examples/entities.html
76
83
  - spec/html_examples/entities.org
77
84
  - spec/html_examples/escape-pre.html
78
85
  - spec/html_examples/escape-pre.org
86
+ - spec/html_examples/export-exclude-only.html
87
+ - spec/html_examples/export-exclude-only.org
88
+ - spec/html_examples/export-keywords.html
89
+ - spec/html_examples/export-keywords.org
90
+ - spec/html_examples/export-tags.html
91
+ - spec/html_examples/export-tags.org
92
+ - spec/html_examples/export-title.html
93
+ - spec/html_examples/export-title.org
79
94
  - spec/html_examples/html-literal.html
80
95
  - spec/html_examples/html-literal.org
81
96
  - spec/html_examples/inline-formatting.html
82
97
  - spec/html_examples/inline-formatting.org
98
+ - spec/html_examples/link-features.html
99
+ - spec/html_examples/link-features.org
83
100
  - spec/html_examples/lists.html
84
101
  - spec/html_examples/lists.org
85
102
  - spec/html_examples/metadata-comment.html
@@ -88,6 +105,10 @@ files:
88
105
  - spec/html_examples/only-list.org
89
106
  - spec/html_examples/only-table.html
90
107
  - spec/html_examples/only-table.org
108
+ - spec/html_examples/skip-header.html
109
+ - spec/html_examples/skip-header.org
110
+ - spec/html_examples/skip-table.html
111
+ - spec/html_examples/skip-table.org
91
112
  - spec/html_examples/tables.html
92
113
  - spec/html_examples/tables.org
93
114
  - spec/html_examples/text.html