Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyrossh/gromer
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
https://github.com/pyrossh/gromer
Last synced: 3 months ago
JSON representation
gromer is a framework and cli to build multipage web apps in golang using htmx and alpinejs.
- Host: GitHub
- URL: https://github.com/pyrossh/gromer
- Owner: pyrossh
- Created: 2020-11-13T13:50:36.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-03T18:41:38.000Z (over 1 year ago)
- Last Synced: 2024-06-20T16:33:12.602Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 9.08 MB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# gromer
[![Version](https://badge.fury.io/gh/pyros2097%2Fgromer.svg)](https://github.com/pyros2097/gromer)
**gromer** is a framework and cli to build multipage web apps in golang using [htmx](https://htmx.org/) and [alpinejs](https://alpinejs.dev/).
It uses a declarative syntax using inline jsx like templates for components and pages.
It also generates http handlers for your routes which follow a particular folder structure. Similar to other frameworks like nextjs, sveltekit.
You can install this extension [vscode-go-inline-html](https://marketplace.visualstudio.com/items?itemName=pyros2097.vscode-go-inline-html) to get
syntax highlighting for these templates.# Requirements
```sh
go >= v1.18
```# Install
```sh
go get -u -v github.com/pyros2097/gromer/cmd/gromer
```# Using
You need to follow this directory structure similar to nextjs for the api route handlers to be generated and run the gromer command.
[Example](https://github.com/pyros2097/gromer/tree/master/_example)
**These are some components**
`routes/todo.go`
```go
func Todo(c Context, todo *todos.Todo) *Node {
return c.Render(`
{todo.Text}
`)
}
```
**These are normal page routes**
`routes/get.go`
```go
type GetParams struct {
Page int `json:"page"`
Filter string `json:"filter"`
}
func GET(c Context, params GetParams) (*Node, int, error) {
c.Meta("title", "Gromer Todos")
c.Meta("description", "Gromer Todos")
c.Meta("author", "gromer")
c.Meta("keywords", "gromer")
return c.Render(`
`), 200, nil
}
```
And then run the gromer cli command annd it will generate the route handlers in a main.go file,
`main.go`
```go
// Code generated by gromer. DO NOT EDIT.
package main
import (
"github.com/gorilla/mux"
"github.com/pyros2097/gromer"
"github.com/pyros2097/gromer/assets"
"github.com/pyros2097/gromer/gsx"
"github.com/rs/zerolog/log"
"gocloud.dev/server"
"github.com/pyros2097/gromer/_example/assets"
"github.com/pyros2097/gromer/_example/components"
"github.com/pyros2097/gromer/_example/containers"
"github.com/pyros2097/gromer/_example/routes/404"
"github.com/pyros2097/gromer/_example/routes"
"github.com/pyros2097/gromer/_example/routes/about"
)
func init() {
gsx.RegisterComponent(components.Todo, "todo")
gsx.RegisterComponent(components.Checkbox, "value")
gsx.RegisterComponent(containers.TodoCount, "filter")
gsx.RegisterComponent(containers.TodoList, "page", "filter")
}
func main() {
baseRouter := mux.NewRouter()
baseRouter.Use(gromer.LogMiddleware)
baseRouter.NotFoundHandler = gromer.StatusHandler(not_found_404.GET)
staticRouter := baseRouter.NewRoute().Subrouter()
staticRouter.Use(gromer.CacheMiddleware)
gromer.StaticRoute(staticRouter, "/gromer/", gromer_assets.FS)
gromer.StaticRoute(staticRouter, "/assets/", assets.FS)
gromer.StylesRoute(staticRouter, "/styles.css")
pageRouter := baseRouter.NewRoute().Subrouter()
gromer.Handle(pageRouter, "GET", "/", routes.GET)
gromer.Handle(pageRouter, "POST", "/", routes.POST)
gromer.Handle(pageRouter, "GET", "/about", about.GET)
log.Info().Msg("http server listening on http://localhost:3000")
srv := server.New(baseRouter, nil)
if err := srv.ListenAndServe(":3000"); err != nil {
log.Fatal().Stack().Err(err).Msg("failed to listen")
}
}
```
## TODO:
Add inline css formatting
Add inline html formatting