Class: Orgmode::OutputBuffer
- Inherits:
-
Object
- Object
- Orgmode::OutputBuffer
show all
- 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.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Creates a new OutputBuffer object that is bound to an output object. The output will get flushed to =output=.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/org-ruby/output_buffer.rb', line 19
def initialize(output)
@buffer = ""
@headline_number_stack = []
@output = output
@output_type = :start
@list_indent_stack = []
@mode_stack = []
@code_block_indent = nil
@logger = Logger.new(STDERR)
if ENV['DEBUG'] or $DEBUG
@logger.level = Logger::DEBUG
else
@logger.level = Logger::WARN
end
@re_help = RegexpHelper.new
end
|
Instance Attribute Details
#output ⇒ Object
This is the overall output buffer
12
13
14
|
# File 'lib/org-ruby/output_buffer.rb', line 12
def output
@output
end
|
#output_type ⇒ Object
This is the current type of output being accumulated.
15
16
17
|
# File 'lib/org-ruby/output_buffer.rb', line 15
def output_type
@output_type
end
|
Instance Method Details
#current_mode ⇒ Object
45
46
47
|
# File 'lib/org-ruby/output_buffer.rb', line 45
def current_mode
@mode_stack.last
end
|
#do_custom_markup ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/org-ruby/output_buffer.rb', line 138
def do_custom_markup
if File.exists? @options[:markup_file]
load_custom_markup
if @custom_blocktags.empty?
no_valid_markup_found
else
set_custom_markup
end
else
no_custom_markup_file_exists
end
end
|
#get_next_headline_number(level) ⇒ Object
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.
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/org-ruby/output_buffer.rb', line 115
def get_next_headline_number(level)
raise "Headline level not valid: #{level}" if level <= 0
while level > @headline_number_stack.length do
@headline_number_stack.push 0
end
while level < @headline_number_stack.length do
@headline_number_stack.pop
end
raise "Oops, shouldn't happen" unless level == @headline_number_stack.length
@headline_number_stack[@headline_number_stack.length - 1] += 1
@headline_number_stack.join(".")
end
|
#insert(line) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/org-ruby/output_buffer.rb', line 60
def insert(line)
@logger.debug "Looking at #{line.paragraph_type}|#{line.assigned_paragraph_type}(#{current_mode}) : #{line.to_s}"
@block_lang = line.block_lang if line.begin_block?
unless should_accumulate_output?(line)
flush!
maintain_mode_stack(line)
end
case
when line.assigned_paragraph_type == :comment
when line.title?
@buffer << line.output_text
when line.raw_text?
@buffer << "\n" << line.output_text if line.raw_text_tag == @buffer_tag
when preserve_whitespace?
@buffer << "\n" << line.output_text unless line.block_type
when line.assigned_paragraph_type == :code
when (line.kind_of? Headline)
add_line_attributes line
@buffer << "\n" << line.output_text.strip
when ([:definition_term, :list_item, :table_row, :table_header,
:horizontal_rule].include? line.paragraph_type)
@buffer << "\n" << line.output_text.strip
when line.paragraph_type == :paragraph
@buffer << "\n"
buffer_indentation
@buffer << line.output_text.strip
end
if mode_is_code? current_mode and not line.block_type
if line.paragraph_type != :blank
if @code_block_indent
@code_block_indent = [@code_block_indent, line.indent].min
else
@code_block_indent = line.indent
end
end
end
@output_type = line.assigned_paragraph_type || line.paragraph_type
end
|
#list_indent_level ⇒ Object
Gets the current list indent level.
129
130
131
|
# File 'lib/org-ruby/output_buffer.rb', line 129
def list_indent_level
@list_indent_stack.length
end
|
#load_custom_markup ⇒ Object
151
152
153
154
155
|
# File 'lib/org-ruby/output_buffer.rb', line 151
def load_custom_markup
require 'yaml'
self.class.to_s == 'Orgmode::MarkdownOutputBuffer' ? filter = '^MarkdownMap$' : filter = '^HtmlBlockTag$|^Tags$'
@custom_blocktags = YAML.load_file(@options[:markup_file]).select {|k| k.to_s.match(filter) }
end
|
#no_custom_markup_file_exists ⇒ Object
169
170
171
172
|
# File 'lib/org-ruby/output_buffer.rb', line 169
def no_custom_markup_file_exists
@logger.debug "Setting Custom Markup failed. No such file exists: #{@options[:markup_file]}."
@logger.debug "Continuing export with default tags."
end
|
#no_valid_markup_found ⇒ Object
163
164
165
166
167
|
# File 'lib/org-ruby/output_buffer.rb', line 163
def no_valid_markup_found
self.class.to_s == 'Orgmode::MarkdownOutputBuffer' ? tags = 'MarkdownMap' : tags = 'HtmlBlockTag or Tags'
@logger.debug "Setting Custom Markup failed. No #{tags} key where found in: #{@options[:markup_file]}."
@logger.debug "Continuing export with default markup."
end
|
#pop_mode(mode = nil) ⇒ Object
54
55
56
57
58
|
# File 'lib/org-ruby/output_buffer.rb', line 54
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
|
#preserve_whitespace? ⇒ Boolean
Test if we’re in an output mode in which whitespace is significant.
134
135
136
|
# File 'lib/org-ruby/output_buffer.rb', line 134
def preserve_whitespace?
[:example, :inline_example, :raw_text, :src].include? current_mode
end
|
#push_mode(mode, indent) ⇒ Object
49
50
51
52
|
# File 'lib/org-ruby/output_buffer.rb', line 49
def push_mode(mode, indent)
@mode_stack.push(mode)
@list_indent_stack.push(indent)
end
|
#set_custom_markup ⇒ Object
157
158
159
160
161
|
# File 'lib/org-ruby/output_buffer.rb', line 157
def set_custom_markup
@custom_blocktags.keys.each do |k|
@custom_blocktags[k].each {|key,v| self.class.const_get(k.to_s)[key] = v if self.class.const_get(k.to_s).key? key}
end
end
|