Skip to content

Solid 1.0.0

Latest
Compare
Choose a tag to compare
@edgurgel edgurgel released this 16 Jun 09:17
· 2 commits to main since this release

What's changed

Parsing has been rewritten and there are a few breaking changes.

Check this PR for a bit more information.

Enhancements

  • Error messages are now more detailed;
  • Parsing can now fail with a list of errors instead of stopping on the first error;
  • liquid and the inline comment tag are now supported;

Bug fixes

Too many to list here.

Breaking changes

  • Parsing engine has been rewritten from scratch. Any custom tags will need to re-implemented using the Solid.Parser & Solid.Lexer functions. See existing tags as example;
  • Solid.parse/2 returns more meaningful errors and it tries to parse the whole file even when some errors are found. Example:
"""
{{ - }}

{% unknown %}

{% if true %}
{% endunless %}
{% echo 'yo' %}
"""
|> Solid.parse!()

** (Solid.TemplateError) Unexpected character '-'
1: {{ - }}
      ^
Unexpected tag 'unknown'
3: {% unknown %}
   ^
Expected one of 'elsif', 'else', 'endif' tags. Got: Unexpected tag 'endunless'
6: {% endunless %}
   ^
Unexpected tag 'endunless'
6: {% endunless %}
   ^
    (solid 1.0.0-rc.0) lib/solid.ex:77: Solid.parse!/2
    iex:2: (file)
  • Solid.render/3 now always return {:ok, result, errors} unless strict_variables or strict_filters are enabled and a filter or a variable was not found during rendering. See examples below:
"""
{{ 1 | base64_url_safe_decode }}
"""
|> Solid.parse!()
|> Solid.render(%{})

{:ok,
 ["Liquid error (line 1): invalid base64 provided to base64_url_safe_decode",
  "\n"],
 [
   %Solid.ArgumentError{
     message: "invalid base64 provided to base64_url_safe_decode",
     loc: %Solid.Parser.Loc{line: 1, column: 8}
   }
 ]}
"{{ missing_var }} 123"
|> Solid.parse!()
|> Solid.render(%{})

{:ok, ["", " 123"], []}
"{{ missing_var }}"
|> Solid.parse!()
|> Solid.render(%{}, strict_variables: true)

{:error,
 [
   %Solid.UndefinedVariableError{
     variable: ["missing_var"],
     loc: %Solid.Parser.Loc{line: 1, column: 4}
   }
 ], [""]}
"{{ 1 | my_sum }}"
|> Solid.parse!()
|> Solid.render(%{})

{:ok, ["1"], []}
"{{ 1 | my_sum }}"
|> Solid.parse!()
|> Solid.render(%{}, strict_filters: true)

{:error,
 [
   %Solid.UndefinedFilterError{
     filter: "my_sum",
     loc: %Solid.Parser.Loc{line: 1, column: 8}
   }
 ], ["1"]}
  • Solid.FileSystem.read_template_file/2 now must return a tuple with the file content or an error tuple.