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_validation_item(title, values) ⇒ Object
- .generate_output ⇒ Object
Instance Method Summary collapse
Class Method Details
.add_comparation_item(title, json) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/json_checker/html_output.rb', line 27 def self.add_comparation_item(title, json) if title.nil? || json.nil? return end item = "<h2>#{title}</h2>" + "<div class=\"diff\">" + json + "</div>" if @reportItems.nil? @reportItems = Array.new() end @reportItems << item end |
.add_validation_item(title, values) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/json_checker/html_output.rb', line 4 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 = item + value end item << "</table></div>" if @reportItems.nil? @reportItems = Array.new() end @reportItems << item end |
.generate_output ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/json_checker/html_output.rb', line 40 def self.generate_output() htmlOutput = HTMLOutput.new() output = "<html>" + htmlOutput.add_style() + "<body>" @reportItems.each do |item| output << item end output << "</body></html>" htmlOutput.save_to_file(output) end |
Instance Method Details
#add_style ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/json_checker/html_output.rb', line 51 def add_style() return "<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) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/json_checker/html_output.rb', line 67 def save_to_file(report) if report.nil? puts "[ERROR] Invalid report" else File.write("output.html", report) end end |