All Projects → TechMagister → liquid.cr

TechMagister / liquid.cr

Licence: MIT license
Kind of liquid template engine for Crystal [WIP]

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to liquid.cr

dry
Dry is a new template engine and language, and is a superset of Shopify's Liquid, with first-class support for advanced inheritance features, and more. From the creators of Enquirer, Assemble, Remarkable, and Micromatch.
Stars: ✭ 66 (+3.13%)
Mutual labels:  template-engine, liquid
Liquidjs
A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
Stars: ✭ 638 (+896.88%)
Mutual labels:  template-engine, liquid
liquidpy
A port of liquid template engine for python
Stars: ✭ 49 (-23.44%)
Mutual labels:  template-engine, liquid
Solid
Liquid template engine in Elixir
Stars: ✭ 68 (+6.25%)
Mutual labels:  template-engine, liquid
korte
Kotlin cORoutines Template Engine for Multiplatform Kotlin
Stars: ✭ 69 (+7.81%)
Mutual labels:  template-engine, liquid
liquid
A Python engine for the Liquid template language.
Stars: ✭ 40 (-37.5%)
Mutual labels:  template-engine, liquid
CodegenCS
C# Toolkit for Code Generation (T4 alternative!)
Stars: ✭ 119 (+85.94%)
Mutual labels:  template-engine
Supply
🛍 Supply is a free e-commerce Jekyll theme with Gumroad integration.
Stars: ✭ 24 (-62.5%)
Mutual labels:  liquid
Kvantum
An intellectual (HTTP/HTTPS) web server with support for server side templating (Crush, Apache Velocity and JTwig)
Stars: ✭ 17 (-73.44%)
Mutual labels:  template-engine
lua-template
The simplest Lua template engine
Stars: ✭ 33 (-48.44%)
Mutual labels:  template-engine
ultron-ele
The world’s fastest LMS engine based on Gatsby -- Deliver knowledge with fun!
Stars: ✭ 27 (-57.81%)
Mutual labels:  template-engine
express-edge
🔤  Use Edge templating engine with Express
Stars: ✭ 45 (-29.69%)
Mutual labels:  template-engine
agency-jekyll-theme
Jekyll version of the newest Agency Bootstrap theme, plus new features: Google Analytics, Markdown support, custom pages, and more!
Stars: ✭ 222 (+246.88%)
Mutual labels:  liquid
tale-pug
Tale Pug is the popular JavaScript Template Engine Pug, formerly Jade, for PHP!
Stars: ✭ 32 (-50%)
Mutual labels:  template-engine
mechanic-tasks
Public task repository for Mechanic (https://mechanic.dev)
Stars: ✭ 42 (-34.37%)
Mutual labels:  liquid
htmldoom
An intuitive, high performance HTML rendering framework
Stars: ✭ 36 (-43.75%)
Mutual labels:  template-engine
velvet
A sweet velvety templating package
Stars: ✭ 72 (+12.5%)
Mutual labels:  template-engine
biketag-website
A website for biketag.org
Stars: ✭ 34 (-46.87%)
Mutual labels:  liquid
jekyll-rss-feeds
Templates for rendering RSS feeds for your Jekyll blog
Stars: ✭ 639 (+898.44%)
Mutual labels:  liquid
micro-template.js
A template engine on JavaScript which like embed js
Stars: ✭ 49 (-23.44%)
Mutual labels:  template-engine

liquid - Liquid template engine for Crystal

Build Status Version License

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

Helper Methods

  • size (for Array and String)
  • present / blank (added)
  • first / last

Development

TODO:

  • Basic For loops
  • if/elsif/else/endif
  • unless/endunless
  • 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 val in myhash %}, access as val[0] and val[1])
  • Add support for Hash into for loop ({% for key, val in myhash %}) (new)
  • Add support for Float
  • Add iteration over Arrays
  • Improve data interface
  • Add Filter support
  • Add capture block
  • Add increment block
  • Add decrement block
  • Add support for Array in expressions
  • Add support for Hash in expressions
  • Add "secret" empty Array ([]) for use in comparisons (equivalent to #blank helper method)
  • Add contains operator
  • Add cycle keyword
  • Add starts_with keyword (new)
  • Add ends_with keyword (new)
  • Add continue keyword
  • Add break keyword
  • Add case/when
  • Add syntax checking
  • Improve expression parsing
  • Add optional strict mode on Context (see below)
  • Add Everything that's missing [https://shopify.github.io/liquid/]

Context Strict Mode

NOTE: Will eventually use this to implement a strict_variables rendering flag (planning to implement strict_filters as well).

Enable at initialization:

ctx = Liquid::Context.new(strict: true)

Or on an existing Context:

ctx.strict = true

Raises KeyError on missing keys and IndexError on array out of bounds errors instead of silently emitting nil.

Append ? to emit nil in strict mode (very simplistic, just checks for ? at the end of the identifier)

ctx = Liquid::Context.new(strict: true)
ctx["obj"] = { something: "something" }
{{ missing }}          -> KeyError
{{ missing? }}         -> nil
{{ obj.missing }}      -> KeyError
{{ obj.missing? }}     -> nil
{{ missing.missing? }} -> nil

Note on order of operations in complex expressions

Currently, comparison operators are evaluated before and/or. Other than that, evaluations are evaluated from left to right. Parentheses are not supported.

Eventually, this will be fixed to evaluate expressions in a way that mirrors Crystal itself, but for now, it would be best to simply avoid writing complex expressions.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].