Skip to content

Commit

Permalink
style: extract content of visual report to the constant
Browse files Browse the repository at this point in the history
to fix the "Block has too many lines. [39/25]" violation
  • Loading branch information
knarewski committed Sep 16, 2024
1 parent 100f33c commit fc40c7e
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions spec/visual_report_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
# frozen_string_literal: true

module VisualReportHelper
VISUAL_REPORT_TEMPLATE = <<-HTML
<!DOCTYPE html>
<html >
<head>
<title>Morandi report</title>
<meta charset="utf-8">
<style>
.img-block { display: inline-block; margin-right: 20px; }
th, td { text-align: left; vertical-align: top; }
</style>
</head>
<body>
<table width="100%" border="1">
<thead>
<tr>
<th width="20%">Description</th>
<th width="80%">Image</th>
</tr>
</thead>
<tbody>
<!-- insert results -->
</tbody>
</table>
<script>
window.onload = function () {
if (sessionStorage.scrollToBottom == "yes") {
window.scrollTo({top: document.body.offsetHeight - window.innerHeight + 50, behavior: 'smooth' })
}
setInterval(() => fetch(location.href).then(response => response.text()).then(body => {
if ([...body.matchAll(/[<]img /g)].length !== document.getElementsByTagName('img').length) {
sessionStorage.scrollToBottom = (window.innerHeight + window.scrollY) >= document.body.offsetHeight ? "yes" : "no";
window.location.reload();
}
}), 500);
}
</script>
</body>
</html>
HTML

class << self
attr_accessor :group
end
Expand All @@ -13,45 +53,7 @@ def visual_report_path

def create_visual_report
File.open(visual_report_path, 'w') do |fp|
fp << <<-HTML
<!DOCTYPE html>
<html >
<head>
<title>Morandi report</title>
<meta charset="utf-8">
<style>
.img-block { display: inline-block; margin-right: 20px; }
th, td { text-align: left; vertical-align: top; }
</style>
</head>
<body>
<table width="100%" border="1">
<thead>
<tr>
<th width="20%">Description</th>
<th width="80%">Image</th>
</tr>
</thead>
<tbody>
<!-- insert results -->
</tbody>
</table>
<script>
window.onload = function () {
if (sessionStorage.scrollToBottom == "yes") {
window.scrollTo({top: document.body.offsetHeight - window.innerHeight + 50, behavior: 'smooth' })
}
setInterval(() => fetch(location.href).then(response => response.text()).then(body => {
if ([...body.matchAll(/[<]img /g)].length !== document.getElementsByTagName('img').length) {
sessionStorage.scrollToBottom = (window.innerHeight + window.scrollY) >= document.body.offsetHeight ? "yes" : "no";
window.location.reload();
}
}), 500);
}
</script>
</body>
</html>
HTML
fp << VISUAL_REPORT_TEMPLATE
end
end

Expand Down

0 comments on commit fc40c7e

Please sign in to comment.