2017-06-25 17:23:20 +02:00
# Go Liquid Template Parser
2017-06-28 15:45:20 +02:00
[![GoDoc ](https://godoc.org/github.com/osteele/liquid?status.svg )](http://godoc.org/github.com/osteele/liquid)
2017-06-25 17:23:20 +02:00
2017-06-28 15:45:20 +02: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 17:23:20 +02:00
## Status
2017-06-26 16:16:25 +02: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 17:23:20 +02:00
- [ ] Basics
2017-06-26 21:36:05 +02:00
- [x] Literals
- [ ] String Escapes
2017-06-26 04:59:33 +02:00
- [x] Variables
2017-06-28 15:45:20 +02:00
- [ ] Operators (partial)
2017-06-26 21:36:05 +02:00
- [x] Arrays
2017-06-25 17:23:20 +02:00
- [ ] Whitespace Control
- [ ] Tags
2017-06-27 19:47:14 +02:00
- [x] Comment
2017-06-25 17:23:20 +02:00
- [ ] Control Flow
2017-06-28 02:23:09 +02:00
- [x] `if` /`else`/`elsif`
- [x] `unless`
2017-06-28 22:43:18 +02:00
- [ ] `case`
- [x] `when`
- [ ] `else`
2017-06-25 17:23:20 +02:00
- [ ] Iteration
2017-06-28 22:18:32 +02:00
- [x] modifiers (`limit`, `reversed` , `offset` )
- [ ] `range`
2017-06-29 18:20:16 +02:00
- [x] `break` , `continue`
2017-06-29 02:49:38 +02:00
- [x] loop variables
2017-06-28 02:23:09 +02:00
- [ ] `tablerow`
- [ ] `cycle`
2017-06-27 23:40:15 +02:00
- [x] Raw
2017-06-28 22:43:18 +02:00
- [x] Variables
2017-06-26 21:36:05 +02:00
- [x] Assign
2017-06-28 19:47:49 +02:00
- [x] Capture
2017-06-28 22:43:18 +02:00
- [ ] Filters
- [ ] `sort_natural` , `uniq` , `escape` , `truncatewords` , `url_decode` , `url_encode`
- [x] everything else
2017-06-25 17:23:20 +02:00
## Install
`go get -u github.com/osteele/goliquid`
2017-06-25 18:36:28 +02:00
## Contribute
### Setup
2017-06-25 17:23:20 +02:00
```bash
2017-06-27 19:25:07 +02:00
make setup
2017-06-25 17:23:20 +02:00
```
2017-06-25 18:36:28 +02:00
Install Ragel. On macOS: `brew install ragel` .
### Workflow
2017-06-25 17:23:20 +02:00
```bash
2017-06-26 21:36:05 +02:00
go generate ./...
go test ./...
2017-06-25 17:23:20 +02:00
```
2017-06-25 18:36:28 +02:00
Test just the scanner:
```bash
2017-06-26 21:36:05 +02:00
cd expressions
ragel -Z scanner.rl & & go test
2017-06-25 22:21:31 +02:00
```
2017-06-28 00:06:26 +02: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 22:21:31 +02:00
## Attribution
2017-06-29 17:15:13 +02:00
| Package | Author | Description |
| --- | --- | --- |
| [github.com/leekchan/timeutil ](https://github.com/leekchan/timeutil ) | Kyoung-chan Lee | formatting dates |
| [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-28 00:06:26 +02:00
2017-06-25 22:21:31 +02: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 14:23:50 +02:00
2017-06-28 22:43:18 +02: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-28 00:06:26 +02:00
(That said, this is a clean-room implementation to make sure it just implements the documented design.)
2017-06-28 15:45:20 +02: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 14:23:50 +02:00
## License
MIT License