[DRE-commits] [ruby-org] 59/303: Simple option parsing.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:27 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 aac4f93861682b1da61e96c1f54403d8abc839d3
Author: Brian Dewey <bdewey at gmail.com>
Date: Tue Dec 29 15:07:13 2009 -0800
Simple option parsing.
---
lib/org-ruby/parser.rb | 27 ++++++++++++++++++++++++++-
spec/parser_spec.rb | 10 +++++++++-
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 11285f5..0b9c538 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -21,6 +21,9 @@ module Orgmode
# This contains any in-buffer settings from the org-mode file.
# See http://orgmode.org/manual/In_002dbuffer-settings.html#In_002dbuffer-settings
attr_reader :in_buffer_settings
+
+ # This contains in-buffer options; a special case of in-buffer settings.
+ attr_reader :options
# I can construct a parser object either with an array of lines
# or with a single string that I will split along \n boundaries.
@@ -37,6 +40,7 @@ module Orgmode
@current_headline = nil
@header_lines = []
@in_buffer_settings = { }
+ @options = { }
mode = :normal
@lines.each do |line|
case mode
@@ -49,7 +53,7 @@ module Orgmode
line = Line.new line
# If there is a setting on this line, remember it.
line.in_buffer_setting? do |key, value|
- @in_buffer_settings[key] = value
+ store_in_buffer_setting key, value
end
mode = :code if line.begin_block? and line.block_type == "EXAMPLE"
if (@current_headline) then
@@ -107,5 +111,26 @@ module Orgmode
rp = RubyPants.new(output)
rp.to_html
end
+
+ ######################################################################
+ private
+
+ # Stores an in-buffer setting.
+ def store_in_buffer_setting(key, value)
+ if key == "OPTIONS" then
+
+ # Options are stored in a hash. Special-case.
+
+ value.split.each do |opt|
+ if opt =~ /^(.*):(.*?)$/ then
+ @options[$1] = $2
+ else
+ raise "Unexpected option: #{opt}"
+ end
+ end
+ else
+ @in_buffer_settings[key] = value
+ end
+ end
end # class Parser
end # module Orgmode
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index a58d511..0e5884a 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -44,12 +44,20 @@ describe Orgmode::Parser do
it "should load in-buffer settings" do
parser = Orgmode::Parser.load(FreeformFile)
- parser.should have(13).in_buffer_settings
+ parser.should have(12).in_buffer_settings
parser.in_buffer_settings["TITLE"].should eql("Freeform")
parser.in_buffer_settings["EMAIL"].should eql("bdewey at gmail.com")
parser.in_buffer_settings["LANGUAGE"].should eql("en")
end
+ it "should understand OPTIONS" do
+ parser = Orgmode::Parser.load(FreeformFile)
+ parser.should have(19).options
+ parser.options["TeX"].should eql("t")
+ parser.options["todo"].should eql("t")
+ parser.options["\\n"].should eql("nil")
+ end
+
it "should skip in-buffer settings inside EXAMPLE blocks" do
parser = Orgmode::Parser.load(FreeformExampleFile)
parser.should have(0).in_buffer_settings
--
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