class Bizside::Redmine::HtmlToTextile
Constants
- NEWLINE
Public Class Methods
convert(text)
click to toggle source
Wrapper for SAX parser
# File lib/bizside/redmine/html_to_textile.rb, line 151 def self.convert(text) # Note, start-of-line is white space trimmed and we use HTML parsing to wrap up a fake HTML root node text.gsub!(/<title.*title>/, '') text.gsub!(/<style.*style>/m, '') text.gsub!(/class="rla-report-table" cellspacing="0"/, '') text.gsub!(/class="alt"/, '') mark_up = text.gsub(/\n\ +/, NEWLINE).gsub(/\>\s*\n/, '> ') converter = Converter.new Nokogiri::HTML::SAX::Parser.new(converter).parse(mark_up) converter.converted.strip end
tweak_wiki_style(textile_format)
click to toggle source
# File lib/bizside/redmine/html_to_textile.rb, line 163 def self.tweak_wiki_style(textile_format) content = textile_format.gsub(/\n\n\s\|\n/, "\n") content.gsub!(/^h2\. Routing Errors$/, "h2. Routing Errors \n") content.gsub!(/^h2\. Parse warnings$/, "\n h2. Parse warnings \n") content.gsub!(/^h2\. Thanks for using request-log-analyzer$/, "--- \n\n h2. Thanks for using request-log-analyzer") content.gsub!(/\n\s\|_\./, "\n{background: #CAE8EA}. |_.") # Get threshold to draw color only Mean & StdDev threshold = ENV['THRESHOLD'] || 400 colorized_content = '' content.each_line do |line| splited = line.split('|') if splited[4].present? mean = splited[4].strip if mean.match(/^\d+ms$/) if mean.to_i > threshold.to_i splited[4] = mean.strip.gsub(/^\d+ms$/, "%{color:red} #{mean}%") end elsif mean.match(/^\d+\.\d+s$/) if mean.to_f * 1000 > threshold.to_i splited[4] = mean.strip.gsub(/^\d+\.\d+s$/, "%{color:red} #{mean}%") end end end if splited[5].present? std_dev = splited[5].strip if std_dev.match(/^\d+ms$/) if std_dev.to_i > threshold.to_i splited[5] = std_dev.gsub(/^\d+ms$/, "%{color:red} #{std_dev}%") end elsif std_dev.match(/^\d+\.\d+s$/) if std_dev.to_f * 1000 > threshold.to_i splited[5] = std_dev.strip.gsub(/^\d+\.\d+s$/, "%{color:red} #{std_dev}%") end end end colorized_content << splited.join("|") end colorized_content end