From 5cbaba11d8800eaddac8cd94b7df0c66ac1b942a Mon Sep 17 00:00:00 2001 From: early Date: Mon, 12 Aug 2024 18:09:02 -0600 Subject: [PATCH] Remove examples, add README, update go --- README.md => README.txt | 19 ++--- app.go | 10 --- cmd/run-today-examples/ex01-pages/example.go | 12 --- cmd/run-today-examples/ex01-pages/page.html | 84 ------------------- cmd/run-today-examples/ex02-parts/example.go | 35 -------- cmd/run-today-examples/ex02-parts/page.html | 64 -------------- .../ex02-parts/random-generator.html | 5 -- cmd/run-today-examples/index.html | 20 ----- cmd/run-today-examples/main.go | 22 ----- cmd/run-today-examples/parts/parts.go | 29 ------- .../parts/source-preview.html | 4 - cmd/run-today-examples/public/style.css | 36 -------- go.mod | 2 +- 13 files changed, 6 insertions(+), 336 deletions(-) rename README.md => README.txt (67%) delete mode 100644 app.go delete mode 100644 cmd/run-today-examples/ex01-pages/example.go delete mode 100644 cmd/run-today-examples/ex01-pages/page.html delete mode 100644 cmd/run-today-examples/ex02-parts/example.go delete mode 100644 cmd/run-today-examples/ex02-parts/page.html delete mode 100644 cmd/run-today-examples/ex02-parts/random-generator.html delete mode 100644 cmd/run-today-examples/index.html delete mode 100644 cmd/run-today-examples/main.go delete mode 100644 cmd/run-today-examples/parts/parts.go delete mode 100644 cmd/run-today-examples/parts/source-preview.html delete mode 100644 cmd/run-today-examples/public/style.css diff --git a/README.md b/README.txt similarity index 67% rename from README.md rename to README.txt index 98c82e2..ec52e38 100644 --- a/README.md +++ b/README.txt @@ -1,27 +1,18 @@ -# Today Web Engine +===== Today Engine ============================================================= The Today engine builds on Go's templating with reusable parts in the style of the Web Components standard. It aims to be usable for anything from static HTML websites to complex applications with a mix of server and client-side behavior. -## Install +===== Install ================================================================== -```sh go get git.earlybird.gay/today-engine@latest -``` -## Usage +===== Usage ==================================================================== -Currently, the `examples` folder contains a site going through concepts by -example. You can walk through these examples yourself by installing them as -an executable: +I'm working on a by-example application to help with this. -```sh -go install git.earlybird.gay/today-engine/cmd/run-today-examples@latest -run-today-examples -``` - -## License +===== License ================================================================== > This section is not legally binding, please read the license text for > specifics! diff --git a/app.go b/app.go deleted file mode 100644 index f16ebc9..0000000 --- a/app.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2024 early (LGPL) -package engine - -import ( - "net/http" -) - -type App struct { - http.ServeMux -} diff --git a/cmd/run-today-examples/ex01-pages/example.go b/cmd/run-today-examples/ex01-pages/example.go deleted file mode 100644 index ee1056f..0000000 --- a/cmd/run-today-examples/ex01-pages/example.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2024 early (LGPL) -package ex01 - -import ( - "git.earlybird.gay/today-engine/page" -) - -// Make a page like this, with page.New(name, file). Name doesn't matter much -// for pages. File is a path to a file relative to *this Go file*, NOT the -// working directory. -// A Page is an http.Handler! -var Page = page.New("ex01", "page.html") diff --git a/cmd/run-today-examples/ex01-pages/page.html b/cmd/run-today-examples/ex01-pages/page.html deleted file mode 100644 index b5ba9b6..0000000 --- a/cmd/run-today-examples/ex01-pages/page.html +++ /dev/null @@ -1,84 +0,0 @@ - - - - Example 1 - - - - -
-

Static HTML

-

Today supports regular HTML, without any modification. All of the - features you'll see in these examples add on to the "normal experience". - For each example, you'll see the rendered result in the browser, plus - source files to show how that example is constructed. -

- - - -

Sources for this example

- - -

page.html

-
ᐸ!DOCTYPE htmlᐳ
-ᐸhtmlᐳ
-ᐸheadᐳ
-  ᐸtitleᐳExample 1ᐸ/titleᐳ
-  ᐸlink rel="stylesheet" href="/style.css"ᐳ
-ᐸ/headᐳ
-
-ᐸbodyᐳ
-  ᐸmainᐳ
-    ᐸh1ᐳStatic HTMLᐸ/h1ᐳ
-    ᐸpᐳToday supports regular HTML, without any modification. All of the
-      features you'll see in these examples add on to the "normal experience".
-      For each example, you'll see the rendered result in the browser, plus
-      source files to show how that example is constructed.
-    ᐸ/pᐳ
-
-    ᐸh2ᐳSources for this exampleᐸ/h2ᐳ
-    ᐸ!-- source-preview does not belong to the HTML specification, but elements
-      with - in the name are allowed! We're going to do something with this in
-      a second. --ᐳ
-    ᐸsource-previewᐳ
-      ᐸh3ᐳpage.htmlᐸ/h3ᐳ
-      ᐸpreᐳᐸcodeᐳ...ᐸ/codeᐳᐸ/preᐳ
-    ᐸ/source-previewᐳ
-    ᐸsource-previewᐳ
-      ᐸh3ᐳexample.goᐸ/h3ᐳ
-      ᐸpreᐳᐸcodeᐳ...ᐸ/codeᐳᐸ/preᐳ
-    ᐸ/source-previewᐳ
-    ᐸnavᐳ
-      ᐸa href="/ex02"ᐳPartsᐸ/aᐳ
-      ᐸa href="/"ᐳBack to Overviewᐸ/aᐳ
-    ᐸ/navᐳ
-  ᐸ/mainᐳ
-ᐸ/bodyᐳ
-
-ᐸ/htmlᐳ
-
- -

example.go

-
// Copyright (C) 2024 early (LGPL)
-package ex01
-
-import (
-  "git.earlybird.gay/today-engine/page"
-)
-
-// Make a page like this, with page.New(name, file). Name doesn't matter much
-// for pages. File is a path to a file relative to *this Go file*, NOT the
-// working directory.
-// A Page is an http.Handler!
-var Page = page.New("ex01", "page.html")
-      
-
-
- - - \ No newline at end of file diff --git a/cmd/run-today-examples/ex02-parts/example.go b/cmd/run-today-examples/ex02-parts/example.go deleted file mode 100644 index cfb3fea..0000000 --- a/cmd/run-today-examples/ex02-parts/example.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2024 early (LGPL) -package ex02 - -import ( - "math/rand/v2" - - "git.earlybird.gay/today-engine/cmd/run-today-examples/parts" - "git.earlybird.gay/today-engine/include" - "git.earlybird.gay/today-engine/page" - "git.earlybird.gay/today-engine/part" - "git.earlybird.gay/today-engine/render" -) - -// Like pages, you make parts with part.New. The name is more important for -// parts, since the name is the name of the element in HTML. -var RandomGenerator = part.New("random-generator", "random-generator.html", - part.OnLoad(func(data render.Data) error { - // Generate a random number on load. - data.Set("number", rand.Int()%100) - return nil - }), -) - -var Page = page.New("ex01", "page.html", - // When you want to use a part, you need to say so in page.Includes. - page.Includes(RandomGenerator, parts.SourcePreview), - page.OnLoad(func(data render.Data) error { - // This is all for SourcePreview, don't worry about it just yet. - sources := make(render.Data) - sources.Set("page", include.File("page.html")) - sources.Set("go", include.File("example.go")) - data.Set("sources", sources) - return nil - }), -) diff --git a/cmd/run-today-examples/ex02-parts/page.html b/cmd/run-today-examples/ex02-parts/page.html deleted file mode 100644 index 8b6dd31..0000000 --- a/cmd/run-today-examples/ex02-parts/page.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - Example 1 - - - - -
-

Parts

-

- In the previous example, you saw a source-preview element, - which is not part of the HTML specification. However, custom elements with - a - in the name are allowed by the specification, because they are used - for the Web Components feature of the web platform. Today Engine borrows - this for use with server-side "parts". Examples will focus on these for - now, but we'll get into Web Components and how they're different later. -

-

- Parts allow you to define custom elements that are rendered server-side, - before any content is sent to the user agent. Each part can execute some - behavior in Go, and decide how it is rendered based on the result. Here - is a part that generates a random number every time the page is reloaded. -

- - - -

This isn't super useful.

- -

- Fortunately, these are solvable problems. In the next few examples, we'll - evaluate how to make replacable markup in parts using slots and pass data - using attributes. -

- - - - -

Sources for this example

- -

page.html

-
- -

example.go

-
-
- - - \ No newline at end of file diff --git a/cmd/run-today-examples/ex02-parts/random-generator.html b/cmd/run-today-examples/ex02-parts/random-generator.html deleted file mode 100644 index 6bff857..0000000 --- a/cmd/run-today-examples/ex02-parts/random-generator.html +++ /dev/null @@ -1,5 +0,0 @@ - \ No newline at end of file diff --git a/cmd/run-today-examples/index.html b/cmd/run-today-examples/index.html deleted file mode 100644 index ab51f28..0000000 --- a/cmd/run-today-examples/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - -
- Today Engine Examples -
- -

Today Engine Examples

-

This is a set of examples for usage of the Today Web Engine!

-

Links

-
    -
  1. Pages
  2. -
  3. Parts
  4. -
  5. Slots
  6. -
  7. Go Templates
  8. -
  9. N/A
  10. -
  11. Passing Data to Parts
  12. -
  13. Web Components
  14. -
- - \ No newline at end of file diff --git a/cmd/run-today-examples/main.go b/cmd/run-today-examples/main.go deleted file mode 100644 index 70d78b0..0000000 --- a/cmd/run-today-examples/main.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2024 early (LGPL) -package main - -import ( - "net/http" - - "git.earlybird.gay/today-engine/cmd/run-today-examples/ex01-pages" - "git.earlybird.gay/today-engine/cmd/run-today-examples/ex02-parts" - "git.earlybird.gay/today-engine/page" -) - -var index = page.New("index", "index.html") - -func main() { - mux := new(http.ServeMux) - mux.Handle("GET /{$}", index) - mux.Handle("GET /ex01", ex01.Page) - mux.Handle("GET /ex02", ex02.Page) - mux.Handle("GET /", http.FileServer(http.Dir("cmd/run-today-examples/public"))) - - http.ListenAndServe("0.0.0.0:3000", mux) -} diff --git a/cmd/run-today-examples/parts/parts.go b/cmd/run-today-examples/parts/parts.go deleted file mode 100644 index 8ec00d7..0000000 --- a/cmd/run-today-examples/parts/parts.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2024 early (LGPL) -package parts - -import ( - "errors" - "io" - "strings" - - "git.earlybird.gay/today-engine/include" - "git.earlybird.gay/today-engine/part" - "git.earlybird.gay/today-engine/render" -) - -var SourcePreview = part.New("source-preview", "source-preview.html", - part.OnLoad(func(data render.Data) error { - opener, ok := data.Get("source").(include.Opener) - if !ok || opener == nil { - return errors.New("source-preview requires include.Opener source") - } - file, err := opener.Open() - if err != nil { - return err - } - buf := new(strings.Builder) - io.Copy(buf, file) - data.Set("source_raw", buf.String()) - return nil - }), -) diff --git a/cmd/run-today-examples/parts/source-preview.html b/cmd/run-today-examples/parts/source-preview.html deleted file mode 100644 index ec9c1b0..0000000 --- a/cmd/run-today-examples/parts/source-preview.html +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/cmd/run-today-examples/public/style.css b/cmd/run-today-examples/public/style.css deleted file mode 100644 index 557cbab..0000000 --- a/cmd/run-today-examples/public/style.css +++ /dev/null @@ -1,36 +0,0 @@ -/* The Great Reset */ -* { - padding: 0; - margin: 0; -} - -/* Containers */ - -main, section, nav { - display: flex; - flex-direction: column; - gap: .5rem; -} - -main { - margin: 2rem 20%; -} - -/* Typography */ - -/* Styling for parts and app-specific stuff */ - -source-preview { - width: fit-content; - border: 1px solid black; - border-radius: 5px; - overflow: hidden; -} - -source-preview > * { - padding: 1rem; -} - -source-preview pre { - background-color: lightgray; -} diff --git a/go.mod b/go.mod index 94e6cec..27bc819 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module git.earlybird.gay/today-engine -go 1.22.0 +go 1.22.4 require golang.org/x/net v0.27.0 -- 2.39.5