From e2d3939bafe181939a60def121eaa962bd515d07 Mon Sep 17 00:00:00 2001 From: Peter Arentsen Date: Mon, 29 May 2017 12:27:33 +0200 Subject: [PATCH] Make parse function be able to handle nil and convert it to empty string --- lib/liquid/template.ex | 10 ++++++++-- mix.exs | 2 +- test/liquid/template_test.exs | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/liquid/template.ex b/lib/liquid/template.ex index cc0cb218..4ae297ba 100644 --- a/lib/liquid/template.ex +++ b/lib/liquid/template.ex @@ -37,9 +37,15 @@ defmodule Liquid.Template do @doc """ Function to parse markup with given presets (if any) """ - @spec render(String.t, map) :: Liquid.Template - def parse(<>, presets \\ %{}) do + @spec parse(String.t, map) :: Liquid.Template + def parse(value, presets \\ %{}) + def parse(<>, presets) do Liquid.Parse.parse(markup, %Template{presets: presets}) end + @spec parse(nil, map) :: Liquid.Template + def parse(nil, presets) do + Liquid.Parse.parse("", %Template{presets: presets}) + end + end diff --git a/mix.exs b/mix.exs index 52337a7a..33ed09d9 100644 --- a/mix.exs +++ b/mix.exs @@ -3,7 +3,7 @@ defmodule Liquid.Mixfile do def project do [ app: :liquid, - version: "0.6.0", + version: "0.6.1", elixir: "~> 1.3", deps: deps(), name: "Liquid", diff --git a/test/liquid/template_test.exs b/test/liquid/template_test.exs index 0122e3b7..32fbec11 100644 --- a/test/liquid/template_test.exs +++ b/test/liquid/template_test.exs @@ -30,6 +30,11 @@ defmodule Liquid.TemplateTest do assert [" ", "{% comment %}", " ", "{% endcomment %}", " "] == Parse.tokenize(" {% comment %} {% endcomment %} ") end + test :should_be_able_to_handle_nil_in_parse do + t = Template.parse(nil) + assert { :ok, "", _context} = Template.render(t) + end + test :returns_assigns_from_assign_tags do t = Template.parse("{% assign foo = 'from returned assigns' %}{{ foo }}") { :ok, rendered, context } = Template.render(t)