Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 71 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,15 @@ A typical development workflow with twerge:

- [func CodeGen\(g \*Generator, goPath string, cssPath string, htmlPath string, comps ...templ.Component\) error](<#CodeGen>)
- [func If\(ok bool, trueClass string, falseClass string\) string](<#If>)
- [func IsDev\(\) bool](<#IsDev>)
- [func It\(raw string\) string](<#It>)
- [func SetDefault\(g \*Generator\)](<#SetDefault>)
- [type CacheValue](<#CacheValue>)
- [type DebugHandler](<#DebugHandler>)
- [func NewDebugHandler\(\) \*DebugHandler](<#NewDebugHandler>)
- [func \(d \*DebugHandler\) Cache\(\) map\[string\]CacheValue](<#DebugHandler.Cache>)
- [func \(d \*DebugHandler\) It\(s string\) string](<#DebugHandler.It>)
- [func \(d \*DebugHandler\) SetCache\(newC map\[string\]CacheValue\)](<#DebugHandler.SetCache>)
- [type Generator](<#Generator>)
- [func Default\(\) \*Generator](<#Default>)
- [func New\(h Handler\) \*Generator](<#New>)
Expand All @@ -280,6 +286,15 @@ func If(ok bool, trueClass string, falseClass string) string

If returns a short unique CSS class name from the merged classes taking an additional boolean parameter.

<a name="IsDev"></a>
## func [IsDev](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L60>)

```go
func IsDev() bool
```

IsDev returns true if the default generator is using a debug handler.

<a name="It"></a>
## func [It](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L55>)

Expand Down Expand Up @@ -320,8 +335,59 @@ type CacheValue struct {
}
```

<a name="DebugHandler"></a>
## type [DebugHandler](<https://github.com/conneroisu/twerge/blob/main/debug.go#L10-L13>)

DebugHandler is a [Handler](<#Handler>) that can be used to debug tailwind classes.

It is not meant to be used in production.

It will return the same class name for the same input.

```go
type DebugHandler struct {
// contains filtered or unexported fields
}
```

<a name="NewDebugHandler"></a>
### func [NewDebugHandler](<https://github.com/conneroisu/twerge/blob/main/debug.go#L16>)

```go
func NewDebugHandler() *DebugHandler
```

NewDebugHandler creates a new DebugHandler.

<a name="DebugHandler.Cache"></a>
### func \(\*DebugHandler\) [Cache](<https://github.com/conneroisu/twerge/blob/main/debug.go#L28>)

```go
func (d *DebugHandler) Cache() map[string]CacheValue
```

Cache returns the cache of the [Generator](<#Generator>).

<a name="DebugHandler.It"></a>
### func \(\*DebugHandler\) [It](<https://github.com/conneroisu/twerge/blob/main/debug.go#L25>)

```go
func (d *DebugHandler) It(s string) string
```

It returns a short unique CSS class name from the merged classes.

<a name="DebugHandler.SetCache"></a>
### func \(\*DebugHandler\) [SetCache](<https://github.com/conneroisu/twerge/blob/main/debug.go#L35>)

```go
func (d *DebugHandler) SetCache(newC map[string]CacheValue)
```

SetCache sets the cache of the [Generator](<#Generator>).

<a name="Generator"></a>
## type [Generator](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L63>)
## type [Generator](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L73>)

Generator generates all the code needed to use Twerge statically.

Expand All @@ -341,7 +407,7 @@ func Default() *Generator
Default returns the default [Generator](<#Generator>).

<a name="New"></a>
### func [New](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L66>)
### func [New](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L76>)

```go
func New(h Handler) *Generator
Expand All @@ -350,7 +416,7 @@ func New(h Handler) *Generator
New creates a new Generator with the given non\-nil Handler.

<a name="Generator.Cache"></a>
### func \(Generator\) [Cache](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L79>)
### func \(Generator\) [Cache](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L89>)

```go
func (Generator) Cache() map[string]CacheValue
Expand All @@ -359,7 +425,7 @@ func (Generator) Cache() map[string]CacheValue
Cache returns the cache of the [Generator](<#Generator>).

<a name="Generator.It"></a>
### func \(\*Generator\) [It](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L97>)
### func \(\*Generator\) [It](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L107>)

```go
func (g *Generator) It(classes string) string
Expand All @@ -372,7 +438,7 @@ If the class name already exists, it will return the existing class name.
If the class name does not exist, it will generate a new class name and return it.

<a name="Handler"></a>
## type [Handler](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L72-L76>)
## type [Handler](<https://github.com/conneroisu/twerge/blob/main/twerge.go#L82-L86>)

Handler is the interface that needs to be implemented to customize the behavior of the [Generator](<#Generator>).

Expand Down
8 changes: 4 additions & 4 deletions doc/src/examples/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ simple/
├── classes/
│ ├── classes.go # Generated Go code with class mappings
│ └── classes.html # HTML output of class definitions
├── gen.go # Code generation script
├── build.go # Code generation script
├── go.mod # Go module file
├── input.css # TailwindCSS input file
├── main.go # Web server
Expand All @@ -27,9 +27,9 @@ simple/

### Code Generation

The `gen.go` file handles Twerge code generation and TailwindCSS processing:
The `build.go` file handles Twerge code generation and TailwindCSS processing:

```go title="gen.go"
```go title="build.go"
//go:build ignore
// +build ignore

Expand Down Expand Up @@ -149,7 +149,7 @@ templ generate ./views

3. Run the code generation:
```sh
go run gen.go
go run build.go
```

4. Run the server:
Expand Down
6 changes: 3 additions & 3 deletions doc/src/examples/complex-webapp.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dashboard/
├── classes/
│ ├── classes.go # Generated Go code with class mappings
│ └── classes.html # HTML output of class definitions
├── gen.go # Code generation script
├── build.go # Code generation script
├── go.mod # Go module file
├── input.css # TailwindCSS input file
├── main.go # Web server implementation
Expand All @@ -37,7 +37,7 @@ dashboard/

The dashboard example uses multiple components, all processed by Twerge:

```go title="gen.go"
```go title="build.go"
//go:build ignore
// +build ignore

Expand Down Expand Up @@ -532,7 +532,7 @@ templ generate ./views

3. Run the code generation:
```sh
go run gen.go
go run build.go
```

4. Run the server:
Expand Down
24 changes: 12 additions & 12 deletions doc/src/examples/tailwind-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A typical Twerge-Tailwind integration includes these steps:

Here's a simple build script that handles code generation and Tailwind processing:

```go title="gen.go"
```go title="build.go"
//go:build ignore
// +build ignore

Expand Down Expand Up @@ -212,7 +212,7 @@ func runBuild() {

For production builds, you'll want to minify your CSS and use Tailwind's purge feature to remove unused styles:

```go title="gen_prod.go"
```go title="build_prod.go"
//go:build ignore
// +build ignore

Expand Down Expand Up @@ -292,10 +292,10 @@ func runTailwind(prod bool) {
Usage:
```sh
# Development build
go run gen_prod.go
go run build_prod.go

# Production build (minified)
go run gen_prod.go -prod
go run build_prod.go -prod
```

## Makefile Integration
Expand All @@ -307,19 +307,19 @@ You can create a Makefile to simplify common build tasks:

dev:
templ generate ./views
go run gen.go
go run build.go

watch:
go run watch.go

build:
templ generate ./views
go run gen.go
go run build.go
go build -o app ./main.go

prod:
templ generate ./views
go run gen_prod.go -prod
go run build_prod.go -prod
go build -o app -ldflags="-s -w" ./main.go

clean:
Expand Down Expand Up @@ -361,7 +361,7 @@ jobs:
run: templ generate ./views

- name: Build production CSS
run: go run gen_prod.go -prod
run: go run build_prod.go -prod

- name: Build application
run: go build -o app -ldflags="-s -w" ./main.go
Expand Down Expand Up @@ -405,7 +405,7 @@ COPY . .
RUN templ generate ./views

# Build with Twerge
RUN go run gen_prod.go -prod
RUN go run build_prod.go -prod

# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o app -ldflags="-s -w" ./main.go
Expand All @@ -430,7 +430,7 @@ CMD ["./app"]

You can extend your build script to generate multiple theme variants:

```go title="gen_themes.go"
```go title="build_themes.go"
//go:build ignore
// +build ignore

Expand Down Expand Up @@ -528,10 +528,10 @@ func runTailwind(input, output string) {
Usage:
```sh
# Build default theme
go run gen_themes.go
go run build_themes.go

# Build dark theme
go run gen_themes.go -theme dark
go run build_themes.go -theme dark
```

This example demonstrates how to integrate Twerge into your Tailwind CSS build process for both development and production environments.
2 changes: 1 addition & 1 deletion doc/src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
- name: Generate templ code
run: templ generate ./views
- name: Run Twerge code generation
run: go run ./gen.go
run: go run ./build.go
- name: Build application
run: go build -o app
```
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ templ generate ./views

3. Run the code generation:
```sh
go run gen.go
go run build.go
```

4. Run the server:
Expand All @@ -47,6 +47,6 @@ go run main.go
## Notes

- Each example follows the same structure with `views/`, `classes/`, and `_static/` directories
- The `gen.go` file handles twerge code generation and TailwindCSS processing
- The `build.go` file handles twerge code generation and TailwindCSS processing
- `classes/classes.go` contains the generated class mappings
- `input.css` and `tailwind.config.js` manage TailwindCSS configuration
2 changes: 1 addition & 1 deletion examples/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ templ generate

2. Run the code generation:
```sh
go run gen.go
go run build.go
```

3. Run the server:
Expand Down
2 changes: 1 addition & 1 deletion examples/dashboard/gen.go → examples/dashboard/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ func runTailwind() {
if err := cmd.Run(); err != nil {
panic(err)
}
}
}
File renamed without changes.
Loading