[DRE-commits] [ruby-org] 68/303: Supports option skip:nil. WAAY harder than it should have been.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:29 UTC 2013
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository ruby-org.
commit dcd5084a66a8f1347237472ff172d140ae34f472
Author: Brian Dewey <bdewey at gmail.com>
Date: Tue Dec 29 22:17:11 2009 -0800
Supports option skip:nil. WAAY harder than it should have been.
---
History.txt | 1 +
lib/org-ruby/headline.rb | 3 ++-
lib/org-ruby/html_output_buffer.rb | 28 ++++++++++++++++++++++------
lib/org-ruby/parser.rb | 21 +++++++++++++++------
spec/html_examples/skip-table.html | 4 ++++
spec/html_examples/skip-table.org | 19 +++++++++++++++++++
spec/parser_spec.rb | 7 +++++++
7 files changed, 70 insertions(+), 13 deletions(-)
diff --git a/History.txt b/History.txt
index dccf2c6..1606762 100644
--- a/History.txt
+++ b/History.txt
@@ -6,6 +6,7 @@
* Exporting todo keywords (option todo:t)
* Numbering headlines (option num:t)
* Skipping text before the first headline (option skip:t)
+ * Skipping tables (option |:nil)
* Rewrite "file:(blah).org" links to "http:(blah).html" links. This
makes the inter-links to other org-mode files work.
* Uses <th> tags inside table rows that precede table separators.
diff --git a/lib/org-ruby/headline.rb b/lib/org-ruby/headline.rb
index 43ea64d..4ead6a2 100644
--- a/lib/org-ruby/headline.rb
+++ b/lib/org-ruby/headline.rb
@@ -70,6 +70,7 @@ module Orgmode
def to_html(opts = {})
if opts[:decorate_title]
decoration = " class=\"title\""
+ opts.delete(:decorate_title)
else
decoration = ""
end
@@ -82,7 +83,7 @@ module Orgmode
output << "<span class=\"todo-keyword #{@keyword}\">#{@keyword} </span>"
end
output << "#{@headline_text}</h#{@level}>\n"
- output << Line.to_html(@body_lines)
+ output << Line.to_html(@body_lines, opts)
output
end
end # class Headline
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 409e3ae..f74e6f2 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -20,6 +20,8 @@ module Orgmode
:code => "pre"
}
+ attr_reader :options
+
def initialize(output, opts = {})
super(output)
if opts[:decorate_title] then
@@ -27,13 +29,15 @@ module Orgmode
else
@title_decoration = ""
end
+ @options = opts
+ @logger.debug "HTML export options: #{@options.inspect}"
end
def push_mode(mode)
if ModeTag[mode] then
output_indentation
@logger.debug "<#{ModeTag[mode]}>\n"
- @output << "<#{ModeTag[mode]}>\n"
+ @output << "<#{ModeTag[mode]}>\n" unless mode == :table and skip_tables?
# Entering a new mode obliterates the title decoration
@title_decoration = ""
end
@@ -45,7 +49,7 @@ module Orgmode
if ModeTag[m] then
output_indentation
@logger.debug "</#{ModeTag[m]}>\n"
- @output << "</#{ModeTag[m]}>\n"
+ @output << "</#{ModeTag[m]}>\n" unless mode == :table and skip_tables?
end
end
@@ -61,12 +65,16 @@ module Orgmode
@output << @buffer << "\n"
else
if (@buffer.length > 0) then
- @logger.debug "FLUSH ==========> #{@output_type}"
- output_indentation
- @output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>" \
+ unless buffer_mode_is_table? and skip_tables?
+ @logger.debug "FLUSH ==========> #{@buffer_mode}"
+ output_indentation
+ @output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>" \
<< inline_formatting(@buffer) \
<< "</#{HtmlBlockTag[@output_type]}>\n"
- @title_decoration = ""
+ @title_decoration = ""
+ else
+ @logger.debug "SKIP ==========> #{@buffer_mode}"
+ end
end
end
@buffer = ""
@@ -76,6 +84,14 @@ module Orgmode
######################################################################
private
+ def skip_tables?
+ @options[:skip_tables]
+ end
+
+ def buffer_mode_is_table?
+ @buffer_mode == :table
+ end
+
# Escapes any HTML content in the output accumulation buffer @buffer.
def escape_buffer!
@buffer.gsub!(/&/, "&")
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 02f7a47..3cead4c 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -43,6 +43,12 @@ module Orgmode
"t" == @options["skip"]
end
+ # Should we export tables? Defaults to true, must be overridden
+ # with an explicit "nil"
+ def export_tables?
+ "nil" != @options["|"]
+ end
+
# Gets the next headline number for a given level. The intent is
# this function is called sequentially for each headline that
# needs to get numbered. It does standard outline numbering.
@@ -141,18 +147,21 @@ module Orgmode
# Converts the loaded org-mode file to HTML.
def to_html
@headline_number_stack = []
+ export_options = { }
+ export_options[:skip_tables] = true if not export_tables?
output = ""
if @in_buffer_settings["TITLE"] then
output << "<p class=\"title\">#{@in_buffer_settings["TITLE"]}</p>\n"
- decorate = false
else
- decorate = true
+ export_options[:decorate_title] = true
end
- output << Line.to_html(@header_lines, :decorate_title => decorate) unless skip_header_lines?
- decorate = (output.length == 0)
+ output << Line.to_html(@header_lines, export_options) unless skip_header_lines?
+
+ # If we've output anything at all, remove the :decorate_title option.
+ export_options.delete(:decorate_title) if (output.length > 0)
@headlines.each do |headline|
- output << headline.to_html(:decorate_title => decorate)
- decorate = (output.length == 0)
+ output << headline.to_html(export_options)
+ export_options.delete(:decorate_title) if (output.length > 0)
end
rp = RubyPants.new(output)
rp.to_html
diff --git a/spec/html_examples/skip-table.html b/spec/html_examples/skip-table.html
new file mode 100644
index 0000000..0d01ce4
--- /dev/null
+++ b/spec/html_examples/skip-table.html
@@ -0,0 +1,4 @@
+<p class="title">skip-table.org</p>
+<p>Checking that tables are skipped when directed.</p>
+<p>For grins, here’s another table without a header. Just keep the bases covered.</p>
+<p>Again, in the HTML output, you should see <b>no tables</b>.</p>
diff --git a/spec/html_examples/skip-table.org b/spec/html_examples/skip-table.org
new file mode 100644
index 0000000..31a5006
--- /dev/null
+++ b/spec/html_examples/skip-table.org
@@ -0,0 +1,19 @@
+#+TITLE: skip-table.org
+#+OPTIONS: |:nil
+
+Checking that tables are skipped when directed.
+
+| One | Two | Three |
+|-------+-------+-------|
+| Four | Five | Six |
+| Seven | Eight | Nine |
+
+
+For grins, here's another table without a header. Just keep the bases
+covered.
+
+| One | Two | Three |
+| Four | Five | Six |
+| Seven | Eight | Nine |
+
+Again, in the HTML output, you should see *no tables*.
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index 0da8fbd..1f3abe3 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -85,6 +85,13 @@ describe Orgmode::Parser do
parser.to_textile.should be_kind_of(String)
end
+ it "should understand export table option" do
+ fname = File.join(File.dirname(__FILE__), %w[html_examples skip-table.org])
+ data = IO.read(fname)
+ p = Orgmode::Parser.new(data)
+ p.export_tables?.should be_false
+ end
+
data_directory = File.join(File.dirname(__FILE__), "textile_examples")
org_files = File.expand_path(File.join(data_directory, "*.org" ))
files = Dir.glob(org_files)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git
More information about the Pkg-ruby-extras-commits
mailing list