github.com/dare892/liquid.cr

Kind of liquid template engine for Crystal [WIP]

0 stars
0 dependents
License: MIT

Nothing has been indexed for 0.2.4 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  liquid:
    github: dare892/liquid.cr
    version: ~> 0.2.4

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.2.4. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

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