org-ruby 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +36 -0
  4. data/History.txt +9 -0
  5. data/README.rdoc +2 -1
  6. data/Rakefile +10 -10
  7. data/announcement.txt +7 -12
  8. data/lib/org-ruby.rb +1 -1
  9. data/lib/org-ruby/headline.rb +8 -0
  10. data/lib/org-ruby/html_output_buffer.rb +12 -1
  11. data/lib/org-ruby/line.rb +36 -2
  12. data/lib/org-ruby/output_buffer.rb +6 -3
  13. data/lib/org-ruby/parser.rb +25 -7
  14. data/lib/org-ruby/regexp_helper.rb +7 -5
  15. data/lib/org-ruby/textile_symbol_replace.rb +1 -0
  16. data/lib/org-ruby/tilt.rb +29 -0
  17. data/org-ruby.gemspec +19 -23
  18. data/spec/headline_spec.rb +5 -0
  19. data/spec/html_examples/advanced-code.html +53 -18
  20. data/spec/html_examples/advanced-code.org +40 -0
  21. data/spec/html_examples/comment-trees.html +4 -0
  22. data/spec/html_examples/comment-trees.org +13 -0
  23. data/spec/html_examples/horizontal_rule.html +4 -0
  24. data/spec/html_examples/horizontal_rule.org +5 -0
  25. data/spec/html_examples/inline-formatting.html +7 -0
  26. data/spec/html_examples/inline-formatting.org +16 -0
  27. data/spec/line_spec.rb +8 -1
  28. data/spec/parser_spec.rb +6 -0
  29. metadata +55 -118
  30. data/doc/History_txt.html +0 -272
  31. data/doc/OrgRuby.html +0 -149
  32. data/doc/Orgmode.html +0 -960
  33. data/doc/Orgmode/Headline.html +0 -522
  34. data/doc/Orgmode/HtmlOutputBuffer.html +0 -480
  35. data/doc/Orgmode/Line.html +0 -1251
  36. data/doc/Orgmode/OutputBuffer.html +0 -810
  37. data/doc/Orgmode/Parser.html +0 -852
  38. data/doc/Orgmode/RegexpHelper.html +0 -639
  39. data/doc/Orgmode/TextileOutputBuffer.html +0 -456
  40. data/doc/README_rdoc.html +0 -178
  41. data/doc/announcement_txt.html +0 -142
  42. data/doc/bin/org-ruby.html +0 -54
  43. data/doc/created.rid +0 -15
  44. data/doc/images/brick.png +0 -0
  45. data/doc/images/brick_link.png +0 -0
  46. data/doc/images/bug.png +0 -0
  47. data/doc/images/bullet_black.png +0 -0
  48. data/doc/images/bullet_toggle_minus.png +0 -0
  49. data/doc/images/bullet_toggle_plus.png +0 -0
  50. data/doc/images/date.png +0 -0
  51. data/doc/images/find.png +0 -0
  52. data/doc/images/loadingAnimation.gif +0 -0
  53. data/doc/images/macFFBgHack.png +0 -0
  54. data/doc/images/package.png +0 -0
  55. data/doc/images/page_green.png +0 -0
  56. data/doc/images/page_white_text.png +0 -0
  57. data/doc/images/page_white_width.png +0 -0
  58. data/doc/images/plugin.png +0 -0
  59. data/doc/images/ruby.png +0 -0
  60. data/doc/images/tag_green.png +0 -0
  61. data/doc/images/wrench.png +0 -0
  62. data/doc/images/wrench_orange.png +0 -0
  63. data/doc/images/zoom.png +0 -0
  64. data/doc/index.html +0 -306
  65. data/doc/js/darkfish.js +0 -116
  66. data/doc/js/jquery.js +0 -32
  67. data/doc/js/quicksearch.js +0 -114
  68. data/doc/js/thickbox-compressed.js +0 -10
  69. data/doc/lib/org-ruby/headline_rb.html +0 -52
  70. data/doc/lib/org-ruby/html_output_buffer_rb.html +0 -52
  71. data/doc/lib/org-ruby/html_symbol_replace_rb.html +0 -54
  72. data/doc/lib/org-ruby/line_rb.html +0 -52
  73. data/doc/lib/org-ruby/output_buffer_rb.html +0 -54
  74. data/doc/lib/org-ruby/parser_rb.html +0 -56
  75. data/doc/lib/org-ruby/regexp_helper_rb.html +0 -54
  76. data/doc/lib/org-ruby/textile_output_buffer_rb.html +0 -54
  77. data/doc/lib/org-ruby/textile_symbol_replace_rb.html +0 -54
  78. data/doc/lib/org-ruby_rb.html +0 -52
  79. data/doc/rdoc.css +0 -763
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.tmproj
2
+ /util/gen-special-replace.elc
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rspec'
7
+ gem 'tilt'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ org-ruby (0.6.1)
5
+ rubypants (>= 0.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ bones (3.8.0)
11
+ little-plugger (~> 1.1.3)
12
+ loquacious (~> 1.9.1)
13
+ rake (>= 0.8.7)
14
+ diff-lcs (1.1.3)
15
+ little-plugger (1.1.3)
16
+ loquacious (1.9.1)
17
+ rake (0.9.2.2)
18
+ rspec (2.9.0)
19
+ rspec-core (~> 2.9.0)
20
+ rspec-expectations (~> 2.9.0)
21
+ rspec-mocks (~> 2.9.0)
22
+ rspec-core (2.9.0)
23
+ rspec-expectations (2.9.1)
24
+ diff-lcs (~> 1.1.3)
25
+ rspec-mocks (2.9.0)
26
+ rubypants (0.2.0)
27
+ tilt (1.3.3)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bones (>= 3.8.0)
34
+ org-ruby!
35
+ rspec
36
+ tilt
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ == 0.6.2 / 2012-04-14
2
+
3
+ * Added encoding directive to support Ruby 1.9.2
4
+ * Headlines with the COMMENT keyword, and the PROPERTIES drawer are not exported
5
+ * Angle links in org-mode are embedded in anchor tags on html output
6
+ * #+BEGIN/END_SRC lang code blocks are embedded in code tags with class that specifies the coding language
7
+ * Fixed bug in code blocks when a colon was at the beginning
8
+ * More than five dashes create an horizontal rule in html output
9
+
1
10
  == 0.6.0 / 2011-09-03
2
11
 
3
12
  * Added support for a "header offset" -- turns one star into an H2, etc. (thanks, niku)
data/README.rdoc CHANGED
@@ -16,6 +16,7 @@ extracting "content" from the orgfile as opposed to "metadata."
16
16
  * Supports tables, block quotes, and block code
17
17
  * Supports bold, italic, underline, strikethrough, and code inline formatting.
18
18
  * Supports hyperlinks that are in double-brackets
19
+ * Supports +.org+ views in Rails through Tilt.
19
20
  * Upcoming: Handle export options specified in the org buffer.
20
21
 
21
22
  == SYNOPSIS:
@@ -34,7 +35,7 @@ From Ruby code:
34
35
 
35
36
  Orgmode::Parser.new(data)
36
37
 
37
- ...will construct a new +Parser+ object.
38
+ ...will construct a new +Parser+ object.
38
39
 
39
40
  == INSTALL:
40
41
 
data/Rakefile CHANGED
@@ -1,15 +1,16 @@
1
-
2
- begin
3
- require 'bones'
4
- rescue LoadError
5
- abort '### Please install the "bones" gem ###'
6
- end
7
-
1
+ require 'bones'
8
2
  ensure_in_path 'lib'
9
3
  require 'org-ruby'
10
4
 
11
- task :default => 'spec:run'
12
- task 'gem:release' => 'spec:run'
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ task :default => 'spec'
13
+ task 'gem:release' => 'spec'
13
14
 
14
15
  Bones {
15
16
  readme_file 'README.rdoc'
@@ -19,7 +20,6 @@ Bones {
19
20
  url 'http://github.com/bdewey/org-ruby'
20
21
  version OrgRuby::VERSION
21
22
  depend_on 'rubypants'
22
- spec.opts ['--color']
23
23
  }
24
24
 
25
25
 
data/announcement.txt CHANGED
@@ -1,4 +1,4 @@
1
- org-ruby version 0.6.0
1
+ org-ruby version 0.6.2
2
2
  by Brian Dewey
3
3
  http://github.com/bdewey/org-ruby
4
4
 
@@ -11,14 +11,9 @@ conversion. The supplied textile conversion is optimized for
11
11
  extracting "content" from the orgfile as opposed to "metadata."
12
12
 
13
13
  == CHANGES
14
- * The anchor text for a link can now be an image, and will get an img tag (thanks, punchagan)
15
- * Fixed bug in tables; only the first row is a header even if others have divider lines (thanks, leathekd)
16
- * Fixed bug in the list regular expression; lists require a space after the item delimiter (thanks, punchagan)
17
- * Lots from ruediger:
18
- * subscript / superscript
19
- * definition lists
20
- * centered text
21
- * symbol replacement
22
-
23
- * Minor enhancement: Displays inline images
24
-
14
+ * Added encoding directive to support Ruby 1.9.2
15
+ * Headlines with the COMMENT keyword, and the PROPERTIES drawer are not exported
16
+ * Angle links in org-mode are embedded in anchor tags on html output
17
+ * #+BEGIN/END_SRC lang code blocks are embedded in code tags with class that specifies the coding language
18
+ * Fixed bug in code blocks when a colon was at the beginning
19
+ * More than five dashes create an horizontal rule in html output (thanks Neil-Smithline!)
data/lib/org-ruby.rb CHANGED
@@ -3,7 +3,7 @@ unless defined? ::OrgRuby
3
3
  module OrgRuby
4
4
 
5
5
  # :stopdoc:
6
- VERSION = '0.6.0'
6
+ VERSION = '0.6.2'
7
7
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
8
8
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
9
9
  # :startdoc:
@@ -41,6 +41,9 @@ module Orgmode
41
41
 
42
42
  KeywordsRegexp = Regexp.new("^(#{Keywords.join('|')})\$")
43
43
 
44
+ # This matches a headline marked as COMMENT
45
+ CommentHeadlineRegexp = /^COMMENT\s+/
46
+
44
47
  def initialize(line, parser = nil, offset=0)
45
48
  super(line, parser)
46
49
  @body_lines = []
@@ -74,6 +77,11 @@ module Orgmode
74
77
  line =~ LineRegexp
75
78
  end
76
79
 
80
+ # Determines if a headline has the COMMENT keyword.
81
+ def comment_headline?
82
+ @headline_text =~ CommentHeadlineRegexp
83
+ end
84
+
77
85
  # Overrides Line.paragraph_type.
78
86
  def paragraph_type
79
87
  :"heading#{@level}"
@@ -59,6 +59,11 @@ module Orgmode
59
59
  css_class = " style=\"text-align: center\"" if mode == :center
60
60
  @logger.debug "#{mode}: <#{ModeTag[mode]}#{css_class}>\n"
61
61
  @output << "<#{ModeTag[mode]}#{css_class}>\n" unless mode == :table and skip_tables?
62
+ # Special case to add code tags to src blogs and specify language
63
+ if mode == :src
64
+ @logger.debug "<code class=\"#{@block_lang}\">\n"
65
+ @output << "<code class=\"#{@block_lang}\">\n"
66
+ end
62
67
  # Entering a new mode obliterates the title decoration
63
68
  @title_decoration = ""
64
69
  end
@@ -71,6 +76,10 @@ module Orgmode
71
76
  m = super(mode)
72
77
  if ModeTag[m] then
73
78
  output_indentation
79
+ if mode == :src
80
+ @logger.debug "</code>\n"
81
+ @output << "</code>\n"
82
+ end
74
83
  @logger.debug "</#{ModeTag[m]}>\n"
75
84
  @output << "</#{ModeTag[m]}>\n" unless mode == :table and skip_tables?
76
85
  end
@@ -84,7 +93,9 @@ module Orgmode
84
93
  @logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
85
94
  @output << @buffer << "\n"
86
95
  else
87
- if @buffer.length > 0 and @output_type == :definition_list then
96
+ if @buffer.length > 0 and @output_type == :horizontal_rule then
97
+ @output << "<hr />\n"
98
+ elsif @buffer.length > 0 and @output_type == :definition_list then
88
99
  unless buffer_mode_is_table? and skip_tables?
89
100
  output_indentation
90
101
  d = @buffer.split("::", 2)
data/lib/org-ruby/line.rb CHANGED
@@ -41,6 +41,26 @@ module Orgmode
41
41
  return @line =~ /^#/
42
42
  end
43
43
 
44
+ PropertyDrawerRegexp = /^\s*:(PROPERTIES|END):/i
45
+
46
+ def property_drawer_begin_block?
47
+ @line =~ PropertyDrawerRegexp && $1 =~ /PROPERTIES/
48
+ end
49
+
50
+ def property_drawer_end_block?
51
+ @line =~ PropertyDrawerRegexp && $1 =~ /END/
52
+ end
53
+
54
+ def property_drawer?
55
+ check_assignment_or_regexp(:property_drawer, PropertyDrawerRegexp)
56
+ end
57
+
58
+ PropertyDrawerItemRegexp = /^\s*:(\w+):\s*(.*)$/i
59
+
60
+ def property_drawer_item?
61
+ @line =~ PropertyDrawerItemRegexp
62
+ end
63
+
44
64
  # Tests if a line contains metadata instead of actual content.
45
65
  def metadata?
46
66
  check_assignment_or_regexp(:metadata, /^\s*(CLOCK|DEADLINE|START|CLOSED|SCHEDULED):/)
@@ -74,6 +94,12 @@ module Orgmode
74
94
  check_assignment_or_regexp(:definition_list, DefinitionListRegexp)
75
95
  end
76
96
 
97
+ HorizontalRuleRegexp = /^\s*-{5,}\s*$/
98
+
99
+ def horizontal_rule?
100
+ check_assignment_or_regexp(:horizontal_rule, HorizontalRuleRegexp)
101
+ end
102
+
77
103
  OrderedListRegexp = /^\s*\d+(\.|\))\s+/
78
104
 
79
105
  def ordered_list?
@@ -120,7 +146,7 @@ module Orgmode
120
146
  table_row? or table_separator? or table_header?
121
147
  end
122
148
 
123
- BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)/i
149
+ BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)\s*(\w*)?/i
124
150
 
125
151
  def begin_block?
126
152
  @line =~ BlockRegexp && $1 =~ /BEGIN/i
@@ -134,11 +160,15 @@ module Orgmode
134
160
  $2 if @line =~ BlockRegexp
135
161
  end
136
162
 
163
+ def block_lang
164
+ $3 if @line =~ BlockRegexp
165
+ end
166
+
137
167
  def code_block_type?
138
168
  block_type =~ /^(EXAMPLE|SRC)$/i
139
169
  end
140
170
 
141
- InlineExampleRegexp = /^\s*:/
171
+ InlineExampleRegexp = /^\s*:\s/
142
172
 
143
173
  # Test if the line matches the "inline example" case:
144
174
  # the first character on the line is a colon.
@@ -173,6 +203,9 @@ module Orgmode
173
203
  return :definition_list if definition_list? # order is important! A definition_list is also an unordered_list!
174
204
  return :ordered_list if ordered_list?
175
205
  return :unordered_list if unordered_list?
206
+ return :property_drawer_begin_block if property_drawer_begin_block?
207
+ return :property_drawer_end_block if property_drawer_end_block?
208
+ return :property_drawer_item if property_drawer_item?
176
209
  return :metadata if metadata?
177
210
  return :begin_block if begin_block?
178
211
  return :end_block if end_block?
@@ -181,6 +214,7 @@ module Orgmode
181
214
  return :table_row if table_row?
182
215
  return :table_header if table_header?
183
216
  return :inline_example if inline_example?
217
+ return :horizontal_rule if horizontal_rule?
184
218
  return :paragraph
185
219
  end
186
220
 
@@ -54,7 +54,7 @@ module Orgmode
54
54
  push_mode(:normal)
55
55
  end
56
56
 
57
- Modes = [:normal, :ordered_list, :unordered_list, :definition_list, :blockquote, :src, :example, :table, :inline_example, :center]
57
+ Modes = [:normal, :ordered_list, :unordered_list, :definition_list, :blockquote, :src, :example, :table, :inline_example, :center, :property_drawer]
58
58
 
59
59
  def current_mode
60
60
  @mode_stack.last
@@ -80,12 +80,15 @@ module Orgmode
80
80
  def prepare(line)
81
81
  @logger.debug "Looking at #{line.paragraph_type}: #{line.to_s}"
82
82
  if not should_accumulate_output?(line) then
83
+ @block_lang = line.block_lang if line.begin_block? and line.code_block_type?
83
84
  flush!
84
85
  maintain_list_indent_stack(line)
85
86
  @output_type = line.paragraph_type
86
87
  end
87
- push_mode(:inline_example) if line.inline_example? and current_mode != :inline_example
88
- pop_mode(:inline_example) if current_mode == :inline_example && !line.inline_example?
88
+ push_mode(:inline_example) if line.inline_example? and current_mode != :inline_example and not line.property_drawer?
89
+ pop_mode(:inline_example) if current_mode == :inline_example and !line.inline_example?
90
+ push_mode(:property_drawer) if line.property_drawer? and current_mode != :property_drawer
91
+ pop_mode(:property_drawer) if current_mode == :property_drawer and line.property_drawer_end_block?
89
92
  push_mode(:table) if enter_table?
90
93
  pop_mode(:table) if exit_table?
91
94
  @buffered_lines.push(line)
@@ -77,7 +77,7 @@ module Orgmode
77
77
  # Should we export sub/superscripts? (_{foo}/^{foo})
78
78
  # only {} mode is currently supported.
79
79
  def use_sub_superscripts?
80
- @options["^"] != "nil"
80
+ @options["^"] != "nil"
81
81
  end
82
82
 
83
83
  # I can construct a parser object either with an array of lines
@@ -122,6 +122,7 @@ module Orgmode
122
122
  table_header_set = false if !line.table?
123
123
  mode = :code if line.begin_block? and line.block_type == "EXAMPLE"
124
124
  mode = :block_comment if line.begin_block? and line.block_type == "COMMENT"
125
+ mode = :property_drawer if line.property_drawer_begin_block?
125
126
  if (@current_headline) then
126
127
  @current_headline.body_lines << line
127
128
  else
@@ -152,6 +153,20 @@ module Orgmode
152
153
  else
153
154
  @header_lines << line
154
155
  end
156
+
157
+ when :property_drawer
158
+
159
+ line = Line.new line, self
160
+ if line.property_drawer_end_block?
161
+ mode = :normal
162
+ else
163
+ line.assigned_paragraph_type = :property_drawer unless line.blank?
164
+ end
165
+ if (@current_headline) then
166
+ @current_headline.body_lines << line
167
+ else
168
+ @header_lines << line
169
+ end
155
170
  end # case
156
171
  previous_line = line
157
172
  end # @lines.each
@@ -186,7 +201,7 @@ module Orgmode
186
201
  export_options[:skip_tables] = true if not export_tables?
187
202
  output = ""
188
203
  output_buffer = HtmlOutputBuffer.new(output, export_options)
189
-
204
+
190
205
  if @in_buffer_settings["TITLE"] then
191
206
 
192
207
  # If we're given a new title, then just create a new line
@@ -195,7 +210,7 @@ module Orgmode
195
210
  Parser.translate([title], output_buffer)
196
211
  end
197
212
  Parser.translate(@header_lines, output_buffer) unless skip_header_lines?
198
-
213
+
199
214
  # If we've output anything at all, remove the :decorate_title option.
200
215
  export_options.delete(:decorate_title) if (output.length > 0)
201
216
  @headlines.each do |headline|
@@ -224,11 +239,10 @@ module Orgmode
224
239
  # See if we're carrying paragraph payload, and output
225
240
  # it if we're about to switch to some other output type.
226
241
  output_buffer.prepare(line)
227
-
228
242
  case line.paragraph_type
229
- when :metadata, :table_separator, :blank, :comment
243
+ when :metadata, :table_separator, :blank, :comment, :property_drawer_item, :property_drawer_begin_block, :property_drawer_end_block
230
244
 
231
- output_buffer << line.line if output_buffer.preserve_whitespace?
245
+ output_buffer << line.line if output_buffer.preserve_whitespace?
232
246
 
233
247
  when :begin_block
234
248
 
@@ -249,7 +263,7 @@ module Orgmode
249
263
  output_buffer << line.line.lstrip
250
264
 
251
265
  when :unordered_list, :ordered_list, :definition_list
252
-
266
+
253
267
  output_buffer << line.output_text << " "
254
268
 
255
269
  when :inline_example
@@ -315,6 +329,10 @@ module Orgmode
315
329
  inherit_export_level = headline.level
316
330
  end
317
331
  end
332
+ if headline.comment_headline?
333
+ headline.export_state = :exclude
334
+ inherit_export_level = headline.level
335
+ end
318
336
  end
319
337
  end
320
338
  end
@@ -141,14 +141,15 @@ module Orgmode
141
141
  # HTML-style link, and that is how things will get recorded in
142
142
  # +result+.
143
143
  def rewrite_links(str) # :yields: link, text
144
- i = str.gsub(@org_link_regexp) do |match|
144
+ str.gsub(@org_link_regexp) do |match|
145
145
  yield $1, nil
146
- end
147
- i.gsub(@org_link_text_regexp) do |match|
148
- yield $1, $2
146
+ end.gsub(@org_link_text_regexp) do |match|
147
+ yield $1, $2
148
+ end.gsub(@org_angle_link_text_regexp) do |match|
149
+ yield "#{$2}:#{$3}", nil
149
150
  end
150
151
  end
151
-
152
+
152
153
  # Rewrites all of the inline image tags.
153
154
  def rewrite_images(str) # :yields: image_link
154
155
  str.gsub(@org_img_regexp) do |match|
@@ -180,6 +181,7 @@ module Orgmode
180
181
  \]\[
181
182
  ([^\]]*) # This is the friendly text
182
183
  \]\]/x
184
+ @org_angle_link_text_regexp = /(<|&lt;)(\w+):([^\]\t\n\r<> ][^\]\t\n\r<> ]*)(>|&gt;)/x
183
185
  end
184
186
  end # class Emphasis
185
187
  end # module Orgmode
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # Autogenerated by util/gen-special-replace.el
2
3
 
3
4
  module Orgmode
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'tilt'
3
+
4
+ module Tilt
5
+ class OrgTemplate < Template
6
+ def self.engine_initialized?
7
+ defined? ::Orgmode
8
+ end
9
+
10
+ def initialize_engine
11
+ require 'org-ruby'
12
+ end
13
+
14
+ def prepare
15
+ @engine = Orgmode::Parser.new(data)
16
+ @output = nil
17
+ end
18
+
19
+ def evaluate(scope, locals, &block)
20
+ @output ||= @engine.to_html
21
+ end
22
+ end
23
+ end
24
+
25
+ Tilt.register Tilt::OrgTemplate, 'org'
26
+
27
+ rescue LoadError
28
+ # Tilt is not available.
29
+ end