Skip to content

syamilAbdillah/jj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JJ - A Go HTML Builder

Write HTML without leaving your lovely Go files.

Install

go get github.com/syamilAbdillah/jj

v0.2.0 is break everything, so good luck with that

don't install this shit. just copy and paste it to your codebase.

shamelessly stole htmgolang code and changed it to my heart's content.

features

  • Pure Go
  • embrace LOB principle
  • No dependencies
  • No reflection
  • No Money
  • No Girl friend (WTF ... ?)

Usage

package main

import (
	"net/http"

	"github.com/syamilAbdillah/jj"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		jj.Render(w, func(j *jj.J) {
			j.Raw("<!DOCTYPE html>")
			j.Html(nil, func() {
				j.Head(nil, func() {
					j.Title(nil, func() {
						j.Text("Hello World")
					})
				})
				j.Body(jj.NewAttr().Class("container"), func() {
					j.H1(nil, func() {
						j.Text("Hello World")
					})

					j.Br(nil)
				})
			})
		})
	})

	http.ListenAndServe(":8080", nil)
}

Conditional

func Conditional(j *jj.J, isLoggedIn bool) {
	atr := jj.NewAttr()
	if isLoggedIn {
		atr.Href("/profile")
	} else {
		atr.Href("/login")
	}

	j.A(atr, func() {
		if isLoggedIn {
			j.Text("Profile")
		} else {
			j.Text("Login")
		}
	})
}

Loop

func Loop(j *jj.J, users []string) {
	j.Ul(nil, func() {
		for _, user := range users {
			j.Li(nil, func() {
				j.Text(user)
			})
		}
	})
}

TODO

  • codegen tool from HTML to JJ syntax
  • more tests
  • more examples
  • documentation site

why the name is JJ?

because my index finger is on j key

License

MIT

About

A Go HTML Builder

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages