2017-06-25 11:23:20 -04:00
# Go Liquid Template Parser
2017-06-28 09:45:20 -04:00
[![GoDoc ](https://godoc.org/github.com/osteele/liquid?status.svg )](http://godoc.org/github.com/osteele/liquid)
2017-06-25 11:23:20 -04:00
2017-06-28 09:45:20 -04:00
`goliquid` is a pure Go implementation of [Shopify Liquid templates ](https://shopify.github.io/liquid ), for use in [gojekyll ](https://github.com/osteele/gojekyll ).
2017-06-25 11:23:20 -04:00
## Status
2017-06-26 10:16:25 -04:00
[![Build Status ](https://travis-ci.org/osteele/liquid.svg?branch=master )](https://travis-ci.org/osteele/liquid)
[![Go Report Card ](https://goreportcard.com/badge/github.com/osteele/liquid )](https://goreportcard.com/report/github.com/osteele/liquid)
2017-06-25 11:23:20 -04:00
- [ ] Basics
2017-06-26 15:36:05 -04:00
- [x] Literals
- [ ] String Escapes
2017-06-25 22:59:33 -04:00
- [x] Variables
2017-06-28 09:45:20 -04:00
- [ ] Operators (partial)
2017-06-26 15:36:05 -04:00
- [x] Arrays
2017-06-25 11:23:20 -04:00
- [ ] Whitespace Control
- [ ] Tags
2017-06-27 13:47:14 -04:00
- [x] Comment
2017-06-25 11:23:20 -04:00
- [ ] Control Flow
2017-06-27 20:23:09 -04:00
- [x] `if` /`else` /`elsif`
- [x] `unless`
2017-06-28 16:43:18 -04:00
- [ ] `case`
- [x] `when`
- [ ] `else`
2017-06-25 11:23:20 -04:00
- [ ] Iteration
2017-06-28 16:18:32 -04:00
- [x] modifiers (`limit` , `reversed` , `offset` )
- [ ] `range`
2017-06-29 12:20:16 -04:00
- [x] `break` , `continue`
2017-06-28 20:49:38 -04:00
- [x] loop variables
2017-06-27 20:23:09 -04:00
- [ ] `tablerow`
- [ ] `cycle`
2017-06-27 17:40:15 -04:00
- [x] Raw
2017-06-28 16:43:18 -04:00
- [x] Variables
2017-06-26 15:36:05 -04:00
- [x] Assign
2017-06-28 13:47:49 -04:00
- [x] Capture
2017-06-28 16:43:18 -04:00
- [ ] Filters
- [ ] `sort_natural` , `uniq` , `escape` , `truncatewords` , `url_decode` , `url_encode`
- [x] everything else
2017-06-25 11:23:20 -04:00
## Install
`go get -u github.com/osteele/goliquid`
2017-06-25 12:36:28 -04:00
## Contribute
### Setup
2017-06-25 11:23:20 -04:00
```bash
2017-06-27 13:25:07 -04:00
make setup
2017-06-25 11:23:20 -04:00
```
2017-06-25 12:36:28 -04:00
Install Ragel. On macOS: `brew install ragel` .
### Workflow
2017-06-25 11:23:20 -04:00
```bash
2017-06-26 15:36:05 -04:00
go generate ./...
go test ./...
2017-06-25 11:23:20 -04:00
```
2017-06-25 12:36:28 -04:00
Test just the scanner:
```bash
2017-06-26 15:36:05 -04:00
cd expressions
ragel -Z scanner.rl & & go test
2017-06-25 16:21:31 -04:00
```
2017-06-29 13:08:25 -04:00
Preview the documentation:
```bash
godoc -http=:6060&
open http://localhost:6060/pkg/github.com/osteele/liquid/
```
2017-06-27 18:06:26 -04:00
## References
< https: / / shopify . github . io / liquid >
< https: / / help . shopify . com / themes / liquid >
< https: / / github . com / Shopify / liquid / wiki / Liquid-for-Designers >
2017-06-25 16:21:31 -04:00
## Attribution
2017-06-29 11:15:13 -04:00
| Package | Author | Description |
| --- | --- | --- |
| [gopkg.in/yaml.v2 ](https://github.com/go-yaml ) | Canonical | YAML support |
| [Ragel ](http://www.colm.net/open-source/ragel/ ) | Adrian Thurston | scanning expressions |
2017-06-27 18:06:26 -04:00
2017-06-25 16:21:31 -04:00
Michael Hamrah's [Lexing with Ragel and Parsing with Yacc using Go ](https://medium.com/@mhamrah/lexing-with-ragel-and-parsing-with-yacc-using-go-81e50475f88f ) was essential to understanding `go yacc` .
2017-06-26 08:23:50 -04:00
2017-06-28 16:43:18 -04:00
The [original Liquid engine ](https://shopify.github.io/liquid ), of course, for the design and documentation of the Liquid template language. Many of the tag and filter test cases are taken directly from the Liquid documentation.
2017-06-27 18:06:26 -04:00
(That said, this is a clean-room implementation to make sure it just implements the documented design.)
2017-06-28 09:45:20 -04:00
## Other Implementations
Go:
* < https: // godoc . org / github . com / karlseguin / liquid > is a partial implementation.
* < https: // godoc . org / github . com / acstech / liquid > is a more active fork of Karl Seguin's implementation.
* < https: // godoc . org / github . com / hownowstephen / go-liquid > is a more recent entry.
< https: / / github . com / Shopify / liquid / wiki / Ports-of-Liquid-to-other-environments > lists ports to other languages.
2017-06-26 08:23:50 -04:00
## License
MIT License