Class: JsonChecker::HTMLOutput
- Inherits:
-
Object
- Object
- JsonChecker::HTMLOutput
- Defined in:
- lib/json_checker/html_output.rb
Class Method Summary collapse
- .add_comparation_item(title, json) ⇒ Object
- .add_item(item) ⇒ Object
- .add_validation_item(title, values) ⇒ Object
- .generate_output(output_path) ⇒ Object
Instance Method Summary collapse
Class Method Details
.add_comparation_item(title, json) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/json_checker/html_output.rb', line 24 def self.add_comparation_item(title, json) if title.nil? || json.nil? return end item = "<h2>#{title}</h2>" + "<div class=\"diff\">" + json + "</div>" HTMLOutput.add_item(item) end |
.add_item(item) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/json_checker/html_output.rb', line 45 def self.add_item(item) if @reportItems.nil? @reportItems = Array.new() end @reportItems << item end |
.add_validation_item(title, values) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/json_checker/html_output.rb', line 6 def self.add_validation_item(title, values) if title.nil? || values.nil? || !values.is_a?(Array) return end item = "<h2>#{title}</h2>" item << "<div class=\"validation\" style=\"overflow-x:auto;\"> <table><tr><th>Status</th><th>Key</th><th>Expected</th><th>Value</th></tr>" values.each do |value| item << value end item << "</table></div>" HTMLOutput.add_item(item) end |
.generate_output(output_path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/json_checker/html_output.rb', line 34 def self.generate_output(output_path) htmlOutput = HTMLOutput.new() output = "<html>" + htmlOutput.add_style() + "<body>" @reportItems.each do |item| output << item end output << "</body></html>" htmlOutput.save_to_file(output, output_path) end |
Instance Method Details
#add_style ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/json_checker/html_output.rb', line 52 def add_style() return " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> <style> .addition { background: #eaffea; } .remotion { background: #ffecec; } .diff { outline: 1px solid #eff0d6; margin: 5px; padding-top: 5px; padding-bottom: 5px; } .validation { margin: 5px; } body { font-family: monospace; } table { border-collapse: collapse; width: 100%; } td { border: 1px solid #eff0d6; } th { background-color: #4CAF50; color: white; border: 1px solid #4CAF50; } th, td { padding: 5px; text-align: left; } tr:hover { background-color: #f5f5f5 } p { margin-top: 0em; margin-bottom: 0em; white-space: pre; padding : 3; color: #3e3333 } </style>" end |
#save_to_file(report, output_path) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/json_checker/html_output.rb', line 70 def save_to_file(report, output_path) path = "output.html" unless output_path.nil? path = output_path end if report.nil? puts "[ERROR] Invalid report" else FileUtils.mkdir_p(File.dirname(path)) File.write(path, report) end end |