the-go-html-builder.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package advanced_functions
  2. import (
  3. "github.com/qor5/docs/docsrc/examples/e00_basics"
  4. "github.com/qor5/docs/docsrc/generated"
  5. "github.com/qor5/docs/docsrc/utils"
  6. . "github.com/theplant/docgo"
  7. "github.com/theplant/docgo/ch"
  8. )
  9. var TheGoHTMLBuilder = Doc(
  10. Markdown(`
  11. Like at the beginning we said, That we don't use interpreted template language (eg go html/template)
  12. to generate html page. We think they are:
  13. - error prone without static type enforcing
  14. - hard to refactor
  15. - difficult to abstract out to component
  16. - yet another tedious syntax to learn
  17. - not flexible to use helper functions
  18. We like to use standard Go code. the library [htmlgo](https://github.com/theplant/htmlgo) is just for that.
  19. Although Go can't do flexible builder syntax like [Kotlin](https://kotlinlang.org/docs/reference/type-safe-builders.html) does,
  20. But it can also do quite well.
  21. Consider the following code:
  22. `),
  23. ch.Code(generated.TypeSafeBuilderSample).Language("go"),
  24. Markdown(`
  25. It's basically assembled what Kotlin can do, Also is legitimate Go code.
  26. `),
  27. utils.Demo("The Go HTML Builder", e00_basics.TypeSafeBuilderSamplePath, "e00_basics/type-safe-builder-sample.go"),
  28. ).Title("The Go HTML builder").
  29. Slug("advanced-functions/the-go-html-builder")