liquid

Kind of liquid template engine template-engine liquid
0.3.2 released

liquid

Build Status

Liquid template engine for Crystal.

Liquid templating language : http://shopify.github.io/liquid/

Installation

Add this to your application's shard.yml:

dependencies:
  liquid:
    github: TechMagister/liquid.cr

Usage

require "liquid"

txt = "
    {% if kenny.sick %}
      Kenny is sick.
    {% elsif kenny.dead %}
      You killed Kenny!  You ***!!!
    {% else %}
      Kenny looks okay --- so far
    {% endif %}
    "
ctx = Liquid::Context.new
ctx.set "kenny", { "sick" => false, "dead" => true}

tpl = Liquid::Template.parse txt  # tpl can be cached and reused

result = tpl.render ctx

# result = "
#      You killed Kenny!  You ***!!!
#
#    "

Tags can be escaped:

\{% assign myvar = 15 %}

# or

{% raw %}
{% assign myvar = 15 %}
{% endraw %}

will both render {% assign myvar = 15 %}.

Blocks

Cache block (only supports caching using Redis): https://github.com/TechMagister/liquid-cache.cr

Filters

  • [x] abs
  • [x] append
  • [x] camelcase | camelize
  • [x] capitalize
  • [x] ceil
  • [x] compact
  • [x] date
  • [x] default
  • [x] divided_by
  • [x] downcase
  • [x] escape
  • [x] escape_once
  • [x] first
  • [x] floor
  • [x] join
  • [x] last
  • [x] lstrip
  • [x] map
  • [x] minus
  • [x] modulo
  • [x] newline_to_br
  • [x] pluralize
  • [x] plus
  • [x] prepend
  • [x] remove
  • [x] remove_first
  • [x] replace
  • [x] replace_first
  • [x] reverse
  • [x] round
  • [x] rstrip
  • [x] size
  • [x] slice
  • [ ] sort
  • [ ] sort_natural
  • [x] split
  • [x] strip
  • [x] strip_html
  • [x] strip_newlines
  • [ ] times
  • [ ] truncate
  • [ ] truncatewords
  • [x] underscore
  • [ ] uniq
  • [x] upcase | uppercase

Development

TODO:

  • [x] Basic For loops
  • [x] Basic If Elsif Else
  • [x] Raw and comment blocks ({% raw %} and {% comment %})
  • [x] Add variable assignment ({% assign var = "Hello World" %})
  • [x] Add support for multiple operator (no operator precedence support (for now))
  • [x] Add support for Array into for loop
  • [x] Add support for Hash into for loop ({% for key, val in myhash %})
  • [x] Add support for Float
  • [x] Add iteration over Arrays
  • [x] Improve data interface
  • [x] Add Filter support
  • [x] Add capture block
  • [x] Add increment block
  • [x] Add decrement block
  • [ ] Add "contains" keyword
  • [ ] Add support for Array into expressions
  • [ ] Add case/when
  • [ ] Add syntax checking
  • [ ] Improve expression parsing
  • [ ] Add Everything that's missing [https://shopify.github.io/liquid/]

Contributing

  1. Fork it ( https://github.com/TechMagister/liquid.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

liquid:
  github: TechMagister/liquid.cr
  version: ~> 0.3.2
License MIT
Crystal 0.31.1

Authors

Dependencies 1

  • inflector ~> 0.1.8
    {'github' => 'phoffer/inflector.cr', 'version' => '~> 0.1.8'}

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently