diff --git a/18-expenses-chart/.envrc b/18-expenses-chart/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/18-expenses-chart/.envrc @@ -0,0 +1 @@ +use flake diff --git a/18-expenses-chart/.gitignore b/18-expenses-chart/.gitignore new file mode 100644 index 0000000..a397892 --- /dev/null +++ b/18-expenses-chart/.gitignore @@ -0,0 +1,5 @@ +/.direnv/ +/.go/ +*~ +*_templ.go +static/output.css diff --git a/18-expenses-chart/Makefile b/18-expenses-chart/Makefile new file mode 100644 index 0000000..cc8de80 --- /dev/null +++ b/18-expenses-chart/Makefile @@ -0,0 +1,28 @@ +# List of all .templ files +TEMPL_FILES := $(shell find templates -type f -name '*.templ') + +# Name of the generated file(s) from templ +GENERATED_FILES := $(TEMPL_FILES:.templ=_templ.go) + +# Generate Go files from .templ files only if they have changed +$(GENERATED_FILES): $(TEMPL_FILES) + templ generate + +TAILWIND_CONFIG := tailwind.config.js +INPUT_CSS := input.css +OUTPUT_CSS := static/output.css + +# generate tailwindcss output +$(OUTPUT_CSS): $(TEMPL_FILES) $(TAILWIND_CONFIG) $(INPUT_CSS) + tailwindcss -i $(INPUT_CSS) -o $(OUTPUT_CSS) + +# Run the server, with dependencies on templ and tailwind generation +run: $(GENERATED_FILES) $(OUTPUT_CSS) + go run . + +# this uses wgo to re-execute 'make run' +# which will toggle templ generate, when needed +# and then do `go run .` to rebuild all else +.PHONY: run/live +run/live: + wgo -verbose -file=.go -file=.templ make run diff --git a/18-expenses-chart/flake.lock b/18-expenses-chart/flake.lock new file mode 100644 index 0000000..d8ba0cb --- /dev/null +++ b/18-expenses-chart/flake.lock @@ -0,0 +1,211 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "templ", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1694102001, + "narHash": "sha256-vky6VPK1n1od6vXbqzOXnekrQpTL4hbPAwUhT5J9c9E=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "9e21c80adf67ebcb077d75bd5e7d724d21eeafd6", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "templ", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1705314449, + "narHash": "sha256-yfQQ67dLejP0FLK76LKHbkzcQqNIrux6MFe32MMFGNQ=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "30e3c3a9ec4ac8453282ca7f67fca9e1da12c3e6", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710097495, + "narHash": "sha256-B7Ea7q7hU7SE8wOPJ9oXEBjvB89yl2csaLjf5v/7jr8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d40e866b1f98698d454dad8f592fe7616ff705a4", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1701282334, + "narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "templ": "templ" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "templ": { + "inputs": { + "gitignore": "gitignore", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs_2", + "xc": "xc" + }, + "locked": { + "lastModified": 1709917943, + "narHash": "sha256-zDQxUFSmG/VX+xtK+nZ3ObRMVcMjjx+EUAxHLNcHHF8=", + "owner": "a-h", + "repo": "templ", + "rev": "df2a32403bb4a8e4745ac10ddc8b3e77386d8045", + "type": "github" + }, + "original": { + "owner": "a-h", + "repo": "templ", + "type": "github" + } + }, + "xc": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "templ", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703164129, + "narHash": "sha256-kCcCqqwvjN07H8FPG4tXsRVRcMqT8dUNt9pwW1kKAe8=", + "owner": "joerdav", + "repo": "xc", + "rev": "0655cccfcf036556aeaddfb8f45dc7e8dd1b3680", + "type": "github" + }, + "original": { + "owner": "joerdav", + "repo": "xc", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/18-expenses-chart/flake.nix b/18-expenses-chart/flake.nix new file mode 100644 index 0000000..b998fb7 --- /dev/null +++ b/18-expenses-chart/flake.nix @@ -0,0 +1,32 @@ +rec { + description = "templ-practice"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + templ.url = "github:a-h/templ"; + }; + + outputs = { self, nixpkgs, flake-utils, templ }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + templPkg = templ.packages.${system}.templ; + in { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.go + pkgs.wgo + pkgs.semgrep + pkgs.gopls + pkgs.gnumake + templPkg + pkgs.tailwindcss + ]; + shellHook = '' + export GOPATH=$PWD/.go + export PATH=$GOPATH/bin:$PATH + ''; + }; + }); + # see https://serokell.io/blog/practical-nix-flakes +} diff --git a/18-expenses-chart/flake.nix~ b/18-expenses-chart/flake.nix~ new file mode 100644 index 0000000..e69de29 diff --git a/18-expenses-chart/go.mod b/18-expenses-chart/go.mod new file mode 100644 index 0000000..0a9bbb0 --- /dev/null +++ b/18-expenses-chart/go.mod @@ -0,0 +1,5 @@ +module sunshine.industries/temp-exercise + +go 1.21.7 + +require github.com/a-h/templ v0.2.598 diff --git a/18-expenses-chart/go.sum b/18-expenses-chart/go.sum new file mode 100644 index 0000000..0e72287 --- /dev/null +++ b/18-expenses-chart/go.sum @@ -0,0 +1,4 @@ +github.com/a-h/templ v0.2.598 h1:6jMIHv6wQZvdPxTuv87erW4RqN/FPU0wk7ZHN5wVuuo= +github.com/a-h/templ v0.2.598/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/18-expenses-chart/input.css b/18-expenses-chart/input.css new file mode 100644 index 0000000..b5c61c9 --- /dev/null +++ b/18-expenses-chart/input.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/18-expenses-chart/main.go b/18-expenses-chart/main.go new file mode 100644 index 0000000..602ddc4 --- /dev/null +++ b/18-expenses-chart/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "net/http" + + "sunshine.industries/temp-exercise/templates" + "github.com/a-h/templ" +) + +func main() { + component := templates.Hello("some name") + + http.Handle("/", templ.Handler(component)) + + staticFs := http.FileServer(http.Dir("./static")) + http.Handle("/static/", http.StripPrefix("/static/", staticFs)) + + fmt.Println("starting to serve on :3000") + http.ListenAndServe(":3000", nil) +} diff --git a/18-expenses-chart/tailwind.config.js b/18-expenses-chart/tailwind.config.js new file mode 100644 index 0000000..6eb134e --- /dev/null +++ b/18-expenses-chart/tailwind.config.js @@ -0,0 +1,9 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ["./**/*.templ"], + theme: { + extend: {}, + }, + plugins: [], +} + diff --git a/18-expenses-chart/templates/hello.templ b/18-expenses-chart/templates/hello.templ new file mode 100644 index 0000000..9338eaf --- /dev/null +++ b/18-expenses-chart/templates/hello.templ @@ -0,0 +1,16 @@ +package templates + +var myVar string = "some string, changed. and more" +var anotherVar string = "hoho, cool" + +templ Hello(name string) { + +
+This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.
+ + +}