[DRE-commits] [ruby-org] 54/303: Preparing to improve lexer. Added assigned_paragraph_type property to lines.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:26 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 85ea1e91f68ba8a4ac106d2800e15c5eb15f0614
Author: Brian Dewey <bdewey at gmail.com>
Date: Tue Dec 29 08:11:48 2009 -0800
Preparing to improve lexer. Added assigned_paragraph_type property to lines.
---
lib/org-ruby/line.rb | 9 +++++++++
spec/line_spec.rb | 20 ++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index e39da47..ebb154d 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -11,11 +11,19 @@ module Orgmode
# TODO 2009-12-20 bdewey: Handle tabs
attr_reader :indent
+ # A line can have its type assigned instead of inferred from its
+ # content. For example, something that parses as a "table" on its
+ # own ("| one | two|\n") may just be a paragraph if it's inside
+ # #+BEGIN_EXAMPLE. Set this property on the line to assign its type. This
+ # will then affect the value of +paragraph_type+.
+ attr_accessor :assigned_paragraph_type
+
def initialize(line)
@line = line
@indent = 0
@line =~ /\s*/
@indent = $&.length unless blank?
+ @assigned_paragraph_type = nil
end
def to_s
@@ -102,6 +110,7 @@ module Orgmode
# Determines the paragraph type of the current line.
def paragraph_type
+ return @assigned_paragraph_type if @assigned_paragraph_type
return :blank if blank?
return :ordered_list if ordered_list?
return :unordered_list if unordered_list?
diff --git a/spec/line_spec.rb b/spec/line_spec.rb
index 141e139..c22090e 100644
--- a/spec/line_spec.rb
+++ b/spec/line_spec.rb
@@ -86,4 +86,24 @@ describe Orgmode::Line do
line.block_type.should eql(end_examples[str])
end
end
+
+ it "should accept assigned types" do
+ cases = {
+ "# this looks like a comment" => :comment,
+ " 1. This looks like an ordered list" => :ordered_list,
+ " - this looks like an # unordered list" => :unordered_list,
+ " | one | two | table! | \n" => :table_row,
+ "\n" => :blank,
+ " |-----+-----+--------| \n" => :table_separator
+ }
+
+ cases.each_pair do |key, value|
+ l = Orgmode::Line.new key
+ l.paragraph_type.should eql(value)
+ l.assigned_paragraph_type = :paragraph
+ l.paragraph_type.should eql(:paragraph)
+ l.assigned_paragraph_type = nil
+ l.paragraph_type.should eql(value)
+ end
+ end
end
--
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