From 28d5c1c212a06d599160f96cbe0e6c88840ab367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Tue, 9 Jul 2024 10:04:00 +0200 Subject: init --- .gitignore | 2 + contrib/Makefile | 5 ++ contrib/invoice-01.md | 28 +++++++ contrib/metadata.yml | 13 ++++ contrib/template.html | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 12 +++ go.sum | 15 ++++ main.go | 31 ++++++++ 8 files changed, 310 insertions(+) create mode 100644 .gitignore create mode 100644 contrib/Makefile create mode 100644 contrib/invoice-01.md create mode 100644 contrib/metadata.yml create mode 100644 contrib/template.html create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c6bdfa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +contrib/invoice*.html +contrib/invoice*.pdf diff --git a/contrib/Makefile b/contrib/Makefile new file mode 100644 index 0000000..e04d380 --- /dev/null +++ b/contrib/Makefile @@ -0,0 +1,5 @@ +invoice-01.pdf: invoice-01.md + pandoc -s -t html --template template.html --metadata-file metadata.yml $^ | tee invoice-01.html | weasyprint - $@ + +clean: + - rm invoice-01.pdf invoice-01.html diff --git a/contrib/invoice-01.md b/contrib/invoice-01.md new file mode 100644 index 0000000..74705ae --- /dev/null +++ b/contrib/invoice-01.md @@ -0,0 +1,28 @@ +--- +number: "0001" +date: 2024-07-08 +due_date: 2024-08-01 + +notes: ":3" + +currency: EUR + +client: + name: Example + address: Ex Ample, Elpam Xe + email: hello@example.org + +services: + - name: Programming + comment: Lorem ipsum + rate: 1 + qty: 1 + sum: 1 + + - name: System administration + rate: 2.5 + qty: 10 + sum: 25 + +total: 26 +--- diff --git a/contrib/metadata.yml b/contrib/metadata.yml new file mode 100644 index 0000000..61a633c --- /dev/null +++ b/contrib/metadata.yml @@ -0,0 +1,13 @@ +--- + +author: + name: John Smith + address: 123 Sesame St, Cloud, Earth + email: john@smi.th + website: https://smi.th + phone: "+101010101" + +bank: + name: ABC + iban: 2323232323 + swift: LLLLLLXXX diff --git a/contrib/template.html b/contrib/template.html new file mode 100644 index 0000000..458af62 --- /dev/null +++ b/contrib/template.html @@ -0,0 +1,204 @@ + + + + + + + + + +
+ + +
+ + + + +

Invoice

#${ number }
issued at: ${ date }
due at: ${ due_date }
+
+
+ +
+
+

Invoice for

+
    +
  • ${ client.name }
  • +
  • ${ client.address }
  • +
  • ${ client.email }
  • +
+
+ ${ if(notes) } +
+

${ notes }

+
+ ${ endif } +
+ +
+
+ + + + + + + + + + + ${ for(services) } + + + + + + + ${ endfor } + + + + + + + +
DescriptionRateQuantityAmount
+ ${ it.name } + ${ if(it.comment) } +

${ it.comment }

+ ${ endif } +
${ it.rate }${ it.qty }${ it.sum }
Total in ${ currency }${ total }
+
+
+ + + + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..56e6ada --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module main.go + +go 1.22.5 + +require ( + github.com/fatih/color v1.17.0 // indirect + github.com/goccy/go-yaml v1.11.3 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d0915ad --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I= +github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= +golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= diff --git a/main.go b/main.go new file mode 100644 index 0000000..ce58679 --- /dev/null +++ b/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "os" + "fmt" + "html/template" + "github.com/goccy/go-yaml" +) + +func check(e error) { + if e != nil { + fmt.Println(e) + panic(e) + } +} + +func main() { + template_file, err := os.ReadFile(os.Args[1]) + check(err) + + data_file, err := os.ReadFile(os.Args[2]) + check(err) + + template_obj, err := template.New("template").Parse(string(template_file)) + check(err) + + data_raw, err := yaml.Marshal(string(data_file)) + check(err) + + template_obj.Execute(os.Stdout, data_raw) +} -- cgit v1.2.3