koluszki

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Koluszki

Koluszki is a Go package that transforms HTML code into Go code that renders provided HTML with amazing gomponents library.

Usage

Koluszki provides library, CLI and HTTP server to translate HTML into Go code.

CLI

You can use cmd/cli program to translate HTML code from standard input to a go code that is going to be streamed into standard output.

$ echo '<h1>Hello World!</h1>' | go run github.com/thinkofher/koluszki/cmd/cli@latest
HTML(
 Head(
 ),
 Body(
  H1(
   g.Text(`Hello World!`),
  ),
 ),
)

The cmd/cli package integrates well with other Unix tools.

luxemburg; curl -s 'https://github.com' | go run github.com/thinkofher/koluszki/cmd/cli@latest | head -n 20
HTML(
 Lang("en"),
 Data("color-mode", "light"),
 Data("light-theme", "light"),
 Data("dark-theme", "dark"),
 Data("a11y-animated-images", "system"),
 Data("a11y-link-underlines", "true"),
 Head(
  Meta(
   Charset("utf-8"),
  ),
  Link(
   Rel("dns-prefetch"),
   Href("https://github.githubassets.com"),
  ),
  Link(
   Rel("dns-prefetch"),
   Href("https://avatars.githubusercontent.com"),
  ),
HTTP Server

Just execute below command in the terminal and visit the prompted address in the browser. You'll see a web application that executes Koluszki's interface through a HTTP integration.

$ go run github.com/thinkofher/koluszki/cmd/server@latest --host localhost --port 8080
Listening at localhost:8080...

Extras

You can read about beautiful polish city Koluszki here.

Documentation

Overview

Package koluszki implements Renderer to render github.com/maragudk/gomponents Go code based on html.Node. It also provides CLI and HTTP server for your convenience.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, n *html.Node) error

Render renders given html.Node into provided writer. Use NewRenderer if you need more control over output.

func WithRenderSVG

func WithRenderSVG(r *Renderer)

WithRenderSVG tells Renderer to fully render SVG elements with gomponents package.

You can mix this option with WithHTMLPackageElements or WithHTMLPackageAttributes just fine.

By default, Renderer will use g.Raw function call to render SVGs.

Types

type Option

type Option func(*Renderer)

Option modifies Renderer. You cannot define your own options.

func WithGomponentsAlias

func WithGomponentsAlias(alias string) Option

WithGomponentsAlias tells Renderer to use alias for every function call from gomponents package in rendered code.

func WithHTMLPackageAttributes

func WithHTMLPackageAttributes(gomponentsAlias, htmlAlias string) Option

WithHTMLPackageElements tells Renderer to use gomponents/html package in order to render standard HTML attributes. It uses default gomponent package as fallback.

In order to have proper go code rendered, you have to provide gomponentsAlias, but you can leave htmlAlias empty.

Empty htmlAlias will render function calls imported into namespace with "." import operator.

func WithHTMLPackageElements

func WithHTMLPackageElements(gomponentsAlias, htmlAlias string) Option

WithHTMLPackageElements tells Renderer to use gomponents/html package in order to render standard HTML elements. It uses default gomponent package as fallback.

In order to have proper go code rendered, you have to provide gomponentsAlias, but you can leave htmlAlias empty.

Empty htmlAlias will render function calls imported into namespace with "." import operator.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer renders github.com/maragudk/gomponents go code.

Use NewRenderer to initialize Renderer. Using default value of Renderer can end up with panic.

func NewRenderer

func NewRenderer(opts ...Option) *Renderer

NewRenderer returns new Renderer. It is the only way to create new intance of Renderer.

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, n *html.Node) error

Render renders given html.Node into provided writer.

Directories

Path Synopsis
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL