class Rundoc::Parser
Constants
- CODEBLOCK_REGEX
- COMMAND_REGEX
- DEFAULT_KEYWORD
- GITHUB_BLOCK
- INDENT_BLOCK
Attributes
contents[R]
keyword[R]
stack[R]
Public Class Methods
new(contents, keyword: DEFAULT_KEYWORD, document_path: nil)
click to toggle source
# File lib/rundoc/parser.rb, line 13 def initialize(contents, keyword: DEFAULT_KEYWORD, document_path: nil) @document_path = document_path @contents = contents @original = contents.dup @keyword = keyword @stack = [] partition end
Public Instance Methods
partition()
click to toggle source
split into [before_code, code, after_code], process code, and re-run until tail is empty
# File lib/rundoc/parser.rb, line 40 def partition until contents.empty? head, code, tail = contents.partition(CODEBLOCK_REGEX) @stack << head unless head.empty? unless code.empty? match = code.match(CODEBLOCK_REGEX) @stack << CodeSection.new(match, keyword: keyword, document_path: @document_path) end @contents = tail end end
to_md()
click to toggle source
# File lib/rundoc/parser.rb, line 22 def to_md result = [] @stack.each do |s| if s.respond_to?(:render) result << s.render else result << s end end return result.join("") rescue Exception => e File.open("README.md", "w") do |f| f.write(result.join("")) end raise e end