require 'quarry/markup/step' require 'quarry/markup/header' require 'quarry/markup/comment' require 'quarry/markup/macro' require 'quarry/markup/before' require 'quarry/markup/after' require 'quarry/markup/table' module Quarry # = Specification Markup # class Markup attr :file attr :steps # def initialize(file) @file = file @steps = [] parse end # def parse lineno = 0 text = '' File.open(file, 'r') do |f| f.readlines.each_with_index do |line, lineno| case line when /^\s*$/ parse_section(text, lineno) text = '' else text << line end end end end # def parse_section(text, lineno) return if text.strip == '' case text when /\A[-=].*?$/, /[-=]\s*\Z/ #text << line steps << Header.new(self, text, lineno) when /^\s+/ case last = steps.last when Step, Macro last.code << "\n\n#{text.rstrip}" when Comment if last.text =~ /\A([A-Z]{1,9})[:]/ #if macro = Macro.types.find{ |m| m.match?(last.text) } type = Markup.const_get($1.capitalize) step = type.new(self, text, lineno, :comment=>last.text, :before=>@before, :after=>@after) case step when Before @before = step when After @after = step end steps << step else steps << Step.new(self, text, lineno, :before=>@before, :after=>@after) end else raise "never here" steps << Step.new(self, text, lineno, :before=>@before, :after=>@after) end else steps << Comment.new(self, text, lineno) end end # def description File.basename(file) end # def to_script script = [] Dir.chdir(File.dirname(file)) do steps.each do |step| script << step.to_script end end script.join("\n\n") end end #class Markup end#module Quarry