liquid.cr

forked from amberframework/liquid.cr
Kind of liquid template engine for Crystal [WIP]

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

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

Development

TODO:

  • Basic For loops
  • Basic If Elsif Else
  • Raw and comment blocks ({% raw %} and {% comment %})
  • Add variable assignment ({% assign var = "Hello World" %})
  • Add support for multiple operator (no operator precedence support (for now))
  • Add support for Array into for loop
  • Add support for Hash into for loop ({% for key, val in myhash %})
  • Add support for Float
  • Add iteration over Arrays
  • Improve data interface
  • Add Filter support
  • Add capture block
  • Add increment block
  • 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

Repository

liquid.cr

Owner
Statistic
  • 0
  • 0
  • 0
  • 4
  • 2
  • over 3 years ago
  • May 25, 2021
License

MIT License

Links
Synced at

Wed, 06 Nov 2024 21:36:13 GMT

Languages