gohaml

package module
v0.0.0-...-41f18a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2015 License: MIT Imports: 11 Imported by: 2

README

!https://travis-ci.org/realistschuckle/gohaml.png?branch=master!:https://travis-ci.org/realistschuckle/gohaml

h1. What is it?

You can find out more about HAML at "haml.info":http://haml.info/
You can find out more about GO at "golang.org":http://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."

h1. Is it done?

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"}@)
* 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.

h1. How can I install this?

To install the library for use in your project, you can use goinstall.

pre. go get "github.com/realistschuckle/gohaml"

h1. How can I install this from source?

In a "Go workspace":http://golang.org/doc/code.html#tmp_2, 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```

h1. How can I use it?

How about something like this? Save it, compile it, link it, and run it!

bc.. 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!"
}

Documentation

Overview

The gohaml package contains a HAML parser similar to the one found at http://www.haml-lang.com.

You can find the specifics about this implementation at http://github.com/realistschuckle/gohaml.

Index

Constants

View Source
const ATOM = 57347
View Source
const FOR = 57348
View Source
const IDENT = 57346
View Source
const RANGE = 57349

Variables

View Source
var Output inode

Functions

func NewHamlHandler

func NewHamlHandler(base string) (hndl http.Handler, err error)

create an http.Handler that loads haml files from locations relative to base dir, taking into account that they won't end in *haml in the http request. Translates URLs such that:

/bla.html -> ${base}/bla.haml /bla/bla/dingdong.html -> ${base}/bla/bla/dingdong.haml /bla/bla/ -> ${base}/bla/bla/index.haml

Types

type Engine

type Engine struct {
	Autoclose       bool
	Indentation     string
	IncludeCallback func(string, map[string]interface{}) string
	// contains filtered or unexported fields
}

Engine provides the template interpretation functionality to convert a HAML template into its corresponding tag-based representation.

Available options are:

engine.Options["autoclose"] = true|false, default true

The Options field contains the values to modify the way that the engine produces the markup.

The Indentation field contains the string used by the engine to perform indentation.

The IncludeCallback field contains the callback invoked by the gohaml engine to process other files included through the %include extension.

func NewEngine

func NewEngine(input string) (engine *Engine, err error)

NewEngine returns a new Engine with the given input.

func (*Engine) Render

func (self *Engine) Render(scope map[string]interface{}) (output string)

Render interprets the HAML supplied to the NewEngine method.

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func (*Lexer) Error

func (l *Lexer) Error(e string)

func (*Lexer) Lex

func (l *Lexer) Lex(v *yySymType) (output int)

type Loader

type Loader interface {
	Load(id interface{}) (entry *Engine, err error)
}

func NewFileSystemLoader

func NewFileSystemLoader(dir string) (loader Loader, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL