Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abdheshnayak/gohtmlx
GoHTMLX - A lightweight tool for defining and rendering reusable HTML components in Go. Perfect for server-side rendering with a focus on simplicity and efficiency.
https://github.com/abdheshnayak/gohtmlx
Last synced: 21 days ago
JSON representation
GoHTMLX - A lightweight tool for defining and rendering reusable HTML components in Go. Perfect for server-side rendering with a focus on simplicity and efficiency.
- Host: GitHub
- URL: https://github.com/abdheshnayak/gohtmlx
- Owner: abdheshnayak
- Created: 2025-01-04T12:55:17.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-01-05T17:37:02.000Z (about 1 month ago)
- Last Synced: 2025-01-05T18:27:44.251Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GoHTMLX (HTML Components with Go)
## Overview
gohtmlx enables developers to define and render reusable HTML components using Go. This tool is designed for scenarios where basic HTML rendering is needed or for writing purely server-side components. It simplifies creating dynamic HTML by allowing developers to define components in HTML and use them in Go code. Unlike React or JSX, gohtmlx focuses on server-side rendering and is not intended for building client-side interactive applications.
## Try it now
```bash
git clone https://github.com/abdheshnayak/gohtmlx.git
cd gohtmlx
go mod tidy
go run . --src=example/src --dist=example/dist
cd example
go run .
```### or use `task` to run it
```bash
git clone https://github.com/abdheshnayak/gohtmlx.git
cd gohtmlx
go mod tidy
cd example
task dev
```## Goals
gohtmlx allows developers to write reusable HTML components, which are then transpiled into Go code. The generated Go code can be utilized to render dynamic and reusable server-side components efficiently. The focus is on providing a simple way to create server-rendered HTML with a declarative and reusable approach.
## Example Usage
Developers can define reusable components in HTML and use them in their Go applications. Below is an example of defining components and rendering them:
### Defining Components
```html
name: string
Hello {props.Name}!
---
projectName: string
Welcome to {props.ProjectName}!
---
name: string
projectName: string
```
### Using Components in Go
```go
package mainimport (
gc "github.com/abdheshnayak/gohtmlx/example/dist/gohtmlxc"
)func main() {
gc.GreetNWelcome(gc.GreetNWelcomeProps{
Name: "Developers",
ProjectName: "GoHtmlx",
}).Render(os.Stdout)
}
```### Rendered HTML
When executed, the rendered HTML will look as follows:
```html
Hello Developers!
Welcome to gohtmlx!
```## Usage
### Installation
To install gohtmlx, you can use the following command:
```bash
go install github.com/abdheshnayak/gohtmlx@latest
```### Transpilation
To use gohtmlx, you can run the following command:
```bash
gohtmlx --src=path/to/src --dist=path/to/dist
```This command will transpile HTML components from the `src` directory and generate Go code in the `dist` directory.
### Options
- `--src`: Specifies the directory containing the source files to be transpiled.
- `--dist`: Specifies the directory where the transpiled Go code will be generated.## How It Works
1. **Transpilation:** gohtmlx takes HTML components defined with placeholders and transpiles them into valid Go code.
3. **Dynamic Rendering:** The resulting Go code produces dynamic HTML structures, leveraging Go's capabilities for server-side rendering and component-based architecture.## Benefits
- **Declarative Syntax:** Write HTML-like structures in a readable and reusable manner.
- **Component Reusability:** Define and reuse server-side components efficiently.
- **Seamless Integration:** Combines Go’s performance and HTML's clarity.
- **Dynamic HTML:** Simplifies the creation of dynamic server-side web content.## Future Enhancements
- **Improved Error Handling:** Provide detailed errors during transpilation.
- **Enhanced Debugging:** Add tools to visualize the transpilation process.
- **Broader Compatibility:** Extend support for additional libraries and frameworks.---
gohtmlx bridges the gap between Go and reusable HTML components, providing developers with an intuitive way to build modern, server-rendered web applications using Go. The examples and usage reflect its ability to simplify server-side HTML generation for projects requiring basic and efficient rendering.