Class: Orgmode::OutputBuffer
- Inherits:
-
Object
- Object
- Orgmode::OutputBuffer
- Defined in:
- lib/org-ruby/output_buffer.rb
Overview
The OutputBuffer is used to accumulate multiple lines of orgmode text, and then emit them to the output all in one go. The class will do the final textile substitution for inline formatting and add a newline character prior emitting the output.
Direct Known Subclasses
Constant Summary collapse
- Modes =
[:normal, :ordered_list, :unordered_list, :blockquote, :code, :table]
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
This is the accumulation buffer.
-
#buffer_mode ⇒ Object
readonly
This is the output mode of the accumulation buffer.
-
#output ⇒ Object
readonly
This is the overall output buffer.
-
#output_type ⇒ Object
This is the current type of output being accumulated.
Instance Method Summary collapse
-
#<<(str) ⇒ Object
Accumulate the string @str@.
- #current_mode ⇒ Object
- #current_mode_list? ⇒ Boolean
-
#enter_table? ⇒ Boolean
Tests if we are entering a table mode.
-
#exit_table? ⇒ Boolean
Tests if we are existing a table mode.
-
#initialize(output) ⇒ OutputBuffer
constructor
Creates a new OutputBuffer object that is bound to an output object.
-
#list_indent_level ⇒ Object
Gets the current list indent level.
- #pop_mode(mode = nil) ⇒ Object
-
#prepare(line) ⇒ Object
Prepares the output buffer to receive content from a line.
-
#preserve_whitespace? ⇒ Boolean
Test if we’re in an output mode in which whitespace is significant.
- #push_mode(mode) ⇒ Object
Constructor Details
#initialize(output) ⇒ OutputBuffer
Creates a new OutputBuffer object that is bound to an output object. The output will get flushed to =output=.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/org-ruby/output_buffer.rb', line 27 def initialize(output) @output = output @buffer = "" @buffer_mode = nil @output_type = :start @list_indent_stack = [] @paragraph_modifier = nil @cancel_modifier = false @mode_stack = [] @logger = Logger.new(STDERR) if ENV['DEBUG'] @logger.level = Logger::DEBUG else @logger.level = Logger::WARN end @re_help = RegexpHelper.new push_mode(:normal) end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
This is the accumulation buffer. It’s a holding pen so consecutive lines of the right type can get stuck together without intervening newlines.
14 15 16 |
# File 'lib/org-ruby/output_buffer.rb', line 14 def buffer @buffer end |
#buffer_mode ⇒ Object (readonly)
This is the output mode of the accumulation buffer.
17 18 19 |
# File 'lib/org-ruby/output_buffer.rb', line 17 def buffer_mode @buffer_mode end |
#output ⇒ Object (readonly)
This is the overall output buffer
20 21 22 |
# File 'lib/org-ruby/output_buffer.rb', line 20 def output @output end |
#output_type ⇒ Object
This is the current type of output being accumulated.
23 24 25 |
# File 'lib/org-ruby/output_buffer.rb', line 23 def output_type @output_type end |
Instance Method Details
#<<(str) ⇒ Object
Accumulate the string @str@.
95 96 97 98 99 100 101 102 |
# File 'lib/org-ruby/output_buffer.rb', line 95 def << (str) if @buffer_mode && @buffer_mode != current_mode then raise "Accumulation buffer is mixing modes: @buffer_mode == #{@buffer_mode}, current_mode == #{current_mode}" else @buffer_mode = current_mode end @buffer << str end |
#current_mode ⇒ Object
50 51 52 |
# File 'lib/org-ruby/output_buffer.rb', line 50 def current_mode @mode_stack.last end |
#current_mode_list? ⇒ Boolean
54 55 56 |
# File 'lib/org-ruby/output_buffer.rb', line 54 def current_mode_list? (current_mode == :ordered_list) or (current_mode == :unordered_list) end |
#enter_table? ⇒ Boolean
Tests if we are entering a table mode.
83 84 85 86 |
# File 'lib/org-ruby/output_buffer.rb', line 83 def enter_table? ((@output_type == :table_row) || (@output_type == :table_separator)) && (current_mode != :table) end |
#exit_table? ⇒ Boolean
Tests if we are existing a table mode.
89 90 91 92 |
# File 'lib/org-ruby/output_buffer.rb', line 89 def exit_table? ((@output_type != :table_row) && (@output_type != :table_separator)) && (current_mode == :table) end |
#list_indent_level ⇒ Object
Gets the current list indent level.
105 106 107 |
# File 'lib/org-ruby/output_buffer.rb', line 105 def list_indent_level @list_indent_stack.length end |
#pop_mode(mode = nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/org-ruby/output_buffer.rb', line 63 def pop_mode(mode = nil) m = @mode_stack.pop @logger.warn "Modes don't match. Expected to pop #{mode}, but popped #{m}" if mode && mode != m m end |
#prepare(line) ⇒ Object
Prepares the output buffer to receive content from a line. As a side effect, this may flush the current accumulated text.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/org-ruby/output_buffer.rb', line 71 def prepare(line) @logger.debug "Looking at #{line.paragraph_type}: #{line.to_s}" if not should_accumulate_output?(line) then flush! maintain_list_indent_stack(line) @output_type = line.paragraph_type end push_mode(:table) if enter_table? pop_mode(:table) if exit_table? end |
#preserve_whitespace? ⇒ Boolean
Test if we’re in an output mode in which whitespace is significant.
110 111 112 |
# File 'lib/org-ruby/output_buffer.rb', line 110 def preserve_whitespace? return current_mode == :code end |
#push_mode(mode) ⇒ Object
58 59 60 61 |
# File 'lib/org-ruby/output_buffer.rb', line 58 def push_mode(mode) raise "Not a recognized mode: #{mode}" unless Modes.include?(mode) @mode_stack.push(mode) end |