class Guileless::Parser
Attributes
buffer[R]
char_count[R]
input[R]
stream[R]
tag_name[R]
tag_stack[R]
Public Class Methods
new(input)
click to toggle source
# File lib/guileless/parser.rb, line 14 def initialize(input) @input = input end
Public Instance Methods
add_tag_to_stack()
click to toggle source
# File lib/guileless/parser.rb, line 65 def add_tag_to_stack @tag_stack << tag_name end
close_tag()
click to toggle source
# File lib/guileless/parser.rb, line 69 def close_tag unwind_tag_stack(tag_name) end
filtered_input()
click to toggle source
# File lib/guileless/parser.rb, line 87 def filtered_input # Ignoring carriage return should be fine for now, # the output doesn't contain newlines. input.gsub(/\r/, '') end
finish_tag()
click to toggle source
# File lib/guileless/parser.rb, line 59 def finish_tag if block_level_tags.include?(tag_name) flush_buffer end end
flush_buffer()
click to toggle source
# File lib/guileless/parser.rb, line 49 def flush_buffer if wrap_in_paragraph? if buffer.buffered? && char_count > 0 buffer.wrap("<p>", "</p>") end end @char_count = 0 buffer.flush end
last_block_level_tag()
click to toggle source
# File lib/guileless/parser.rb, line 79 def last_block_level_tag tag_stack.reverse.select{|t| block_level_tags.include?(t) }.first end
parse!()
click to toggle source
# File lib/guileless/parser.rb, line 23 def parse! reset! read while !stream.empty? transition(:end) end
read()
click to toggle source
# File lib/guileless/parser.rb, line 29 def read char = stream.fetch value, next_state = Array(self.send("parse_#{state}".to_sym, char)) if value === nil buffer.add char elsif value buffer.add value end transition(next_state) if next_state end
reset!()
click to toggle source
# File lib/guileless/parser.rb, line 93 def reset! @char_count = 0 @buffer = Guileless::OutputBuffer.new @stream = Guileless::InputStream.new(filtered_input) @tag_stack = [] reset_tag_name @state = :text end
reset_tag_name()
click to toggle source
# File lib/guileless/parser.rb, line 83 def reset_tag_name @tag_name = "" end
to_html()
click to toggle source
# File lib/guileless/parser.rb, line 18 def to_html parse! buffer.to_s end
unwind_tag_stack(tag)
click to toggle source
# File lib/guileless/parser.rb, line 73 def unwind_tag_stack(tag) if tag_stack.include?(tag) last_tag = tag_stack.pop while last_tag != tag end end
wrap_in_paragraph?()
click to toggle source
# File lib/guileless/parser.rb, line 42 def wrap_in_paragraph? state == :text && char_count > 0 && buffer.buffered? && (!last_block_level_tag || paragraph_container_tags.include?(last_block_level_tag)) end