Skip to content

Commit

Permalink
replace module name to be included until author accepts my PR
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Feb 14, 2020
1 parent 5238456 commit 9bf39b9
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 203 deletions.
198 changes: 5 additions & 193 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,196 +1,8 @@
# Jade.go - template engine for Go (golang)
Package jade (github.com/Joker/jade) is a simple and fast template engine implementing Jade/Pug template.
Jade precompiles templates to Go code or generates html/template.
Now Jade-lang renamed to [Pug template engine](https://pugjs.org/api/getting-started.html).
# Jade(Pug) Parser

[![GoDoc](https://godoc.org/github.com/Joker/jade?status.svg)](https://godoc.org/github.com/Joker/jade) [![Go Report Card](https://goreportcard.com/badge/github.com/Joker/jade)](https://goreportcard.com/report/github.com/Joker/jade)
Read more about its syntax at: https://github.com/iris-contrib/jade.

## Jade/Pug syntax
example:
Fixes:

```jade
:go:func Index(pageTitle string, youAreUsingJade bool)
mixin for(golang)
#cmd Precompile jade templates to #{golang} code.
doctype html
html(lang="en")
head
title= pageTitle
script(type='text/javascript').
if(question){
answer(40 + 2)
}
body
h1 Jade - template engine
+for('Go')
#container.col
if youAreUsingJade
p You are amazing
else
p Get on it!
p.
Jade/Pug is a terse and simple
templating language with
a #[strong focus] on performance
and powerful features.
```

becomes

```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Jade.go</title>
<script type="text/javascript">
if(question){
answer(40 + 2)
}
</script>
</head>
<body>
<h1>Jade - template engine
<div id="cmd">Precompile jade templates to Go code.</div>
</h1>
<div id="container" class="col">
<p>You are amazing</p>
<p>
Jade/Pug is a terse and simple
templating language with
a <strong>focus</strong> on performance
and powerful features.
</p>
</div>
</body>
</html>
```


See [more](https://github.com/Joker/jade/tree/master/testdata/v2) [examples](https://github.com/Joker/jade/tree/master/example).


## Example usage

```sh
jade -pkg=main -writer hello.jade
```
jade command precompiles hello.jade to hello.jade.go

`hello.jade`
```
:go:func(arg) word string
doctype 5
html
body
p Hello #{word}!
```

`hello.jade.go`
```go
// Code generated by "jade.go"; DO NOT EDIT.
package main

import "io"

const (
hello__0 = `<!DOCTYPE html><html><body><p>Hello `
hello__1 = `!</p></body></html>`
)
func tpl_hello(word string, wr io.Writer) {
buffer := &WriterAsBuffer{wr}
buffer.WriteString(hello__0)
WriteEscString(word, buffer)
buffer.WriteString(hello__1)
}
```

`main.go`
```go
package main
//go:generate jade -pkg=main -writer hello.jade

import "net/http"

func main() {
http.HandleFunc("/", func(wr http.ResponseWriter, req *http.Request) {
tpl_hello("jade", wr)
})
http.ListenAndServe(":8080", nil)
}
```

Output on localhost:8080 :
```html
<!DOCTYPE html><html><body><p>Hello jade!</p></body></html>
```


or generate html/template at runtime


```go
package main

import (
"fmt"
"github.com/Joker/hpp" // Prettify HTML
"github.com/Joker/jade"
)

func main() {
tpl, err := jade.Parse("name_of_tpl", "doctype 5\n html: body: p Hello #{.Word} !")
if err != nil {
fmt.Printf("Parse error: %v", err)
return
}

fmt.Printf( "Output:\n\n%s", hpp.PrPrint(tpl) )
}
```

Output:

```html
<!DOCTYPE html>
<html>
<body>
<p>Hello {{.Word}} !</p>
</body>
</html>
```


## Installation

```sh
$ go get github.com/Joker/jade/cmd/jade
```


## Custom filter :go
This filter is used as helper for command line tool
(to set imports, function name and parameters).
Filter may be located at any nesting level.
When jade used as library :go filter is not needed.

### Nested filter :func
```
:go:func
CustomNameForTemplateFunc(any []int, input string, args map[string]int)
:go:func(name)
OnlyCustomNameForTemplateFunc
:go:func(args)
(only string, input float32, args uint)
```

### Nested filter :import
```
:go:import
"github.com/Joker/jade"
github.com/Joker/hpp
```
- https://github.com/iris-contrib/jade/issues/33
- https://github.com/kataras/iris/issues/1450
2 changes: 1 addition & 1 deletion cmd/jade/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"text/template"

"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/jade/go_ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"testing"

"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)

var wdir string
Expand Down
2 changes: 1 addition & 1 deletion cmd/jade/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"regexp"
"strconv"

"github.com/Joker/jade"
"github.com/iris-contrib/jade"
"golang.org/x/tools/imports"
)

Expand Down
2 changes: 1 addition & 1 deletion example/v1.0/actions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"

"github.com/Joker/hpp"
"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)

type Person struct {
Expand Down
2 changes: 1 addition & 1 deletion example/v1.0/jade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/ioutil"

"github.com/Joker/hpp"
"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion example/v1.0/jade_extends/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/Joker/hpp"
"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion example/v1.0/jade_include/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/Joker/hpp"
"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Joker/jade
module github.com/iris-contrib/jade

require (
github.com/Joker/hpp v1.0.0
Expand Down
2 changes: 1 addition & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Trivial usage:
import (
"fmt"
"github.com/Joker/jade"
"github.com/iris-contrib/jade"
)
func main() {
Expand Down
2 changes: 1 addition & 1 deletion testdata/v2/filters.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
const myFunc = () => `This is ES2015 in a CD${'ATA'}`;

:go:import
"github.com/Joker/jade"
"github.com/iris-contrib/jade"
"github.com/Joker/hpp"
//-
\\\\\\\\\\ options.js <
Expand Down

0 comments on commit 9bf39b9

Please sign in to comment.