Exemplo n.º 1
0
// Parse given raw amber template string.
func (c *Compiler) Parse(input string) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = errors.New(r.(string))
		}
	}()

	parser, err := parser.StringParser(input)

	if err != nil {
		return
	}

	c.node = parser.Parse()
	return
}
Exemplo n.º 2
0
// ParseFile parses the amber template file in given path.
func (c *Compiler) ParseFile(filename string) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = errors.New(r.(string))
		}
	}()

	parser, err := parser.FileParser(filename)

	if err != nil {
		return
	}

	c.node = parser.Parse()
	c.filename = filename
	return
}
Exemplo n.º 3
0
// Parse given raw amber template bytes, and the filename that belongs with it
func (c *Compiler) ParseData(input []byte, filename string) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = errors.New(r.(string))
		}
	}()

	parser, err := parser.ByteParser(input)
	parser.SetFilename(filename)

	if err != nil {
		return
	}

	c.node = parser.Parse()
	return
}