Skip to content

Commit

Permalink
Make parse function be able to handle nil and convert it to empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Arentsen committed May 29, 2017
1 parent 28caa3a commit e2d3939
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/liquid/template.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(<<markup::binary>>, presets \\ %{}) do
@spec parse(String.t, map) :: Liquid.Template
def parse(value, presets \\ %{})
def parse(<<markup::binary>>, 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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions test/liquid/template_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e2d3939

Please sign in to comment.