[DRE-commits] [ruby-org] 110/303: Added support header offset.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:38 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 878aa16db52a124b82fd8af60f0e6864fca7afb9
Author: niku <niku at niku.name>
Date: Sun Jul 3 01:43:41 2011 +0900
Added support header offset.
---
lib/org-ruby/headline.rb | 4 ++--
lib/org-ruby/parser.rb | 4 ++--
spec/headline_spec.rb | 5 +++++
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/org-ruby/headline.rb b/lib/org-ruby/headline.rb
index 8f33364..b3f609b 100644
--- a/lib/org-ruby/headline.rb
+++ b/lib/org-ruby/headline.rb
@@ -41,14 +41,14 @@ module Orgmode
KeywordsRegexp = Regexp.new("^(#{Keywords.join('|')})\$")
- def initialize(line, parser = nil)
+ def initialize(line, parser = nil, offset=0)
super(line, parser)
@body_lines = []
@body_lines << self # Make @body_lines contain the headline?
@tags = []
@export_state = :exclude
if (@line =~ LineRegexp) then
- @level = $&.strip.length
+ @level = $&.strip.length + offset
@headline_text = $'.strip
if (@headline_text =~ TagsRegexp) then
@tags = $&.split(/:/) # split tag text on semicolon
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index c490872..03b6da1 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -82,7 +82,7 @@ module Orgmode
# I can construct a parser object either with an array of lines
# or with a single string that I will split along \n boundaries.
- def initialize(lines)
+ def initialize(lines, offset=0)
if lines.is_a? Array then
@lines = lines
elsif lines.is_a? String then
@@ -105,7 +105,7 @@ module Orgmode
when :normal
if (Headline.headline? line) then
- @current_headline = Headline.new line, self
+ @current_headline = Headline.new line, self, offset
@headlines << @current_headline
else
line = Line.new line, self
diff --git a/spec/headline_spec.rb b/spec/headline_spec.rb
index 06d3521..bc0193b 100644
--- a/spec/headline_spec.rb
+++ b/spec/headline_spec.rb
@@ -26,6 +26,11 @@ describe Orgmode::Headline do
end
end
+ it "should properly determine headline level with offset" do
+ h = Orgmode::Headline.new("* one", nil, 1)
+ h.level.should eql(2)
+ end
+
it "should find simple headline text" do
h = Orgmode::Headline.new "*** sample"
h.headline_text.should eql("sample")
--
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