require 'aipim-rails/parser' module Markdown def self.init(features) features.each_with_index do |feature, i| output = File.new("aipim/markdown/#{feature[:filename]}", "w") write_feature(feature, output) output.close end #read_content(filename) end def self.read_line(file) line = file.gets line = line.gsub("\n", "").split(' ').join(' ') unless line.nil? line end def self.write_feature(feature, output) feature[:scenarios].each_with_index do |scenario, i| output.puts "[#{i+1}. #{scenario[:name]}](#) " end output.puts '' output.puts "# #{feature[:feature_name]} #" end def self.read_content(features, output) file = File.new("features/"+filename, "r") output = File.new("aipim/markdown/"+filename+".md", "a") is_screenshot = false; scenario_counter = 1; screenshot_counter = 0 screenshots = %x[\ls aipim/screenshots/#{filename}].split("\n") output.puts "" line = read_line(file) while (line) if !ParserHelper.is_comando?(line) && !(line.gsub(" ", "") == "") output.puts " #{line} " line = read_line(file) elsif ParserHelper.is_marcacao?(line) && ParserHelper.is_screenshot?(line) is_screenshot = true line = read_line(file) elsif ParserHelper.is_funcionalidade?(line) output.puts "# #{ParserHelper.get_funcionalidade(line)} #" line = read_line(file) elsif ParserHelper.is_cenario?(line) output.puts "> ## #{scenario_counter}. #{ParserHelper.get_cenario(line)} ##" scenario_counter = scenario_counter+1 while ((line = read_line(file)) && !ParserHelper.is_comando?(line)) output.puts "> #{line} " if !(line.gsub(" ", "") == "") end if is_screenshot output.puts '> [![Alt text](../screenshots/'+filename+'/'+screenshots[screenshot_counter].to_s+')](../screenshots/'+filename+'/'+screenshots[screenshot_counter].to_s+') ' screenshot_counter = screenshot_counter+1 is_screenshot = false end output.puts '' elsif ParserHelper.is_contexto?(line) output.puts "## Contexto : #{ParserHelper.get_contexto(line)} ##" line = read_line(file) else line = read_line(file) end end file.close output.close end end