-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1ea18d9
commit d1cf8aa
Showing
5 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package internal | ||
|
||
import ( | ||
"embed" | ||
"html/template" | ||
"log" | ||
"os" | ||
|
||
"clingy/lib" | ||
) | ||
|
||
//go:embed templates | ||
var templates embed.FS | ||
|
||
// GenerateHTMLReport - generate a HTML report by reading from a file and writing to a specified destination | ||
func GenerateHTMLReport(logger *log.Logger, data *lib.ClingyTemplate, outFile string) error { | ||
logger.Println("Generating HTML report", data.Label, outFile) | ||
|
||
inputTemplateBytes, err := templates.ReadFile("templates/simple-report.template.html") | ||
if err != nil { | ||
logger.Println("Error in reading embed template", err) | ||
return err | ||
} | ||
|
||
inputTemplate, err := template.New("report").Parse(string(inputTemplateBytes)) | ||
if err != nil { | ||
logger.Println("Error in creating template from templatedir", err) | ||
return err | ||
} | ||
|
||
out, err := os.Create(outFile) | ||
if err != nil { | ||
logger.Println("Error in creating outfile", outFile, err) | ||
return err | ||
} | ||
defer func(out *os.File) { | ||
err = out.Close() | ||
if err != nil { | ||
logger.Println("Error in closing outFile", outFile, err) | ||
// unable to safely return in closure/defer func | ||
} | ||
}(out) | ||
|
||
if err = inputTemplate.ExecuteTemplate(out, "report", data); err != nil { | ||
logger.Println("Error in executing on template", err) | ||
return err | ||
} | ||
|
||
logger.Println("Completed generating HTML report", data.Label, outFile) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<html lang="en"> | ||
<head><title>Clingy Report - {{.Label}}</title></head> | ||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css"> | ||
<body> | ||
<hgroup> | ||
<h1> | ||
Clingy Report - {{.Label}} | ||
</h1> | ||
<h2> | ||
Steps: | ||
</h2> | ||
</hgroup> | ||
{{range $idx, $step := .Steps}} | ||
<div> | ||
<hgroup> | ||
<h3> | ||
#{{$idx}} {{$step.Label}} | ||
</h3> | ||
<h4> | ||
{{$step.Description}} | ||
</h4> | ||
</hgroup> | ||
<img alt="screenshot of {{$step.Label}}" src="{{$step.ImageOutput}}" /> | ||
</div> | ||
{{end}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters