You can find out more about HAML at haml.info
You can find out more about GO at golang.org
I’ve tried to remain diligent about reproducing the output from the canonical Ruby-based parser, so if you feel familiar with the one, then you should feel familiar with the other.
This branch compiles with 6g/8g “go version go1.0.3.”
I think so. It has…
- Tags with
- empty content;
- attributes of the form
{:attr => "value"}
; - id moniker using “#” (
#divId
); and, - class moniker using “.” (
.divClass
).
- Tag nesting
- Scope lookup
- Arbitrary number of keys as specified by struct (
someKeyInScope.Subkey1.Subkey2
) - Valid as tag content (
%p= someKeyInScope
) - Valid as tag attribute value (
%p{:attr => someKeyInScope}
) - Valid as tag attribute name (
%p{someKeyInScope => "value"}
)
- Arbitrary number of keys as specified by struct (
- Engine-level autoclose option (
<br />
vs.<br>
) - Tag-specific close option (
%br/
becomes<br />
regardless of autoclose setting) - Whitespace removal with the
<
operator - Simple scripting
- Declaration and assignment of strings, floats, and ints (- varname := “value”)
- Range looping construct (- for i, v := range scopeVar)
- Error messages for badly-formed templates
If you would like another feature added, just log an issue and I’ll review it forthright.
To install the library for use in your project, you can use goinstall.
go get "github.com/realistschuckle/gohaml"
In a Go workspace, create a directory for gohaml
.
mkdir -p src/github.com/realistschuckle/gohaml
Clone the
gohaml
repository into that newly created directory.git clone git://github.com/realistschuckle/gohaml.git src/github.com/realistschuckle/gohaml
Now build and install it.
go install github.com/realistschuckle/gohaml
How about something like this? Save it, compile it, link it, and run it!
package main
import ( "github.com/realistschuckle/gohaml" "fmt" )
func main() { var scope = make(map[string]interface{}) scope["lang"] = "HAML" content := "I love <\n=lang<\n!" engine, _ := gohaml.NewEngine(content) output := engine.Render(scope) fmt.Println(output) // Prints "I love HAML!" }