Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Support lambda variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Ito committed Jul 14, 2013
1 parent c6ec1f8 commit 91a1d86
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions lib/mustache/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,42 @@ defmodule Mustache.Compiler do
end

defp handle_variable(buffer, var) do
quote do: unquote(buffer) <> Mustache.Compiler.escape_html(Mustache.Compiler.to_binary(unquote(var)))
quote do
var = unquote(var)

if is_function(var, 0), do: var = var.()

unquote(buffer) <> Mustache.Compiler.escape_html(Mustache.Compiler.to_binary(var))
end
end

defp handle_unescaped_variable(buffer, var) do
quote do: unquote(buffer) <> Mustache.Compiler.to_binary(unquote(var))
quote do
var = unquote(var)

if is_function(var, 0), do: var = var.()

unquote(buffer) <> Mustache.Compiler.to_binary(var)
end
end

def handle_dotted_name(buffer, var, atoms) do
quote do
buffer = unquote(buffer)
adding = Mustache.Compiler.recur_access(unquote(var), unquote(atoms)) |> Mustache.Compiler.to_binary
buffer <> adding
var = adding = Mustache.Compiler.recur_access(unquote(var), unquote(atoms))

if is_function(var, 0), do: var = var.()

unquote(buffer) <> Mustache.Compiler.escape_html(Mustache.Compiler.to_binary(var))
end
end

def handle_unescaped_dotted_name(buffer, var, atoms) do
quote do
buffer = unquote(buffer)
adding = Mustache.Compiler.recur_access(unquote(var), unquote(atoms))
|> Mustache.Compiler.to_binary
|> Mustache.Compiler.escape_html
buffer <> adding
var = Mustache.Compiler.recur_access(unquote(var), unquote(atoms))

if is_function(var, 0), do: var = var.()

unquote(buffer) <> Mustache.Compiler.to_binary(var)
end
end

Expand Down

0 comments on commit 91a1d86

Please sign in to comment.