Skip to content

Instantly share code, notes, and snippets.

View jfjensen's full-sized avatar

Jes Fink-Jensen jfjensen

View GitHub Profile
@jfjensen
jfjensen / d3js_radial_tree.html
Created February 20, 2021 16:05
D3.js Radial Tree Example
<!-- Code adapted from
https://observablehq.com/@d3/Fradial-tidy-tree
https://javadude.wordpress.com/2012/06/20/d3-js-from-tree-to-cluster-and-radial-projection/
https://stackoverflow.com/questions/59783070/d3-v5-radial-tree-cluster
-->
<!DOCTYPE html>
<html>
<head>
<title>D3.js Radial Tree Example</title>
@jfjensen
jfjensen / iBuilder.tmpl
Last active March 4, 2022 12:18
This is the iBuilder template
package main
type iBuilder interface {
{{range .Properties -}}
set{{if eq .TypeName `int`}}Num{{end}}{{title .Name}}()
{{end -}}
get{{title .ProductTarget}}() {{.ProductTarget}}
}
func getBuilder(builderType string) iBuilder {
@jfjensen
jfjensen / ConcreteTarget.tmpl
Created March 4, 2022 12:21
This is the template for creating the Concrete targets
package main
{{$target := index .ConcreteTargets 0}}
type {{$target}}Builder struct {
{{range .Properties -}}
{{.Name}} {{.TypeName}}
{{end -}}
}
func new{{title $target}}Builder() *{{$target}}Builder {
@jfjensen
jfjensen / codegen_builder.go
Created March 4, 2022 12:23
This is the main code for generating the builder design pattern from templates.
package main
import (
"bufio"
"bytes"
"fmt"
"github.com/Masterminds/sprig"
"go/format"
"html/template"
"log"
@jfjensen
jfjensen / ProductTarget.tmpl
Created March 4, 2022 14:59
This is the template for the Product Target.
package main
type {{.ProductTarget}} struct {
{{range .Properties -}}
{{.Name}} {{.TypeName}}
{{end -}}
}
@jfjensen
jfjensen / director.tmpl
Created March 4, 2022 15:00
This is the template for the Director.
package main
type director struct {
builder iBuilder
}
func newDirector(b iBuilder) *director {
return &director{
builder: b,
}
@jfjensen
jfjensen / sample_main.tmpl
Created March 4, 2022 15:02
This is the template for generating the sample main function.
package main
import "fmt"
func main() {
{{$pt:=.ProductTarget}}
{{$ct:=.ConcreteTargets}}
{{$ps:=.Properties}}
{{range $index, $item := $ct}}
{{$item}}Builder := getBuilder("{{$item}}")
@jfjensen
jfjensen / main.go
Last active February 23, 2024 10:27
The main Go program for generating HTML code
package main
import (
"bufio"
"bytes"
"html/template"
"os"
)
type product struct {
@jfjensen
jfjensen / page.tmpl
Created March 10, 2022 18:24
The "page" template
{{define "page"}}
{{template "header" -}}
{{template "content" . -}}
{{template "footer" -}}
{{end}}
@jfjensen
jfjensen / header.tmpl
Created March 10, 2022 18:25
The "header" template
{{define "header" -}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/script.js" defer></script>