Skip to content

Instantly share code, notes, and snippets.

@julien-leclercq
Created August 14, 2017 14:03
Show Gist options
  • Save julien-leclercq/5fbe854f7c87f072b7bb799b283acbb7 to your computer and use it in GitHub Desktop.
Save julien-leclercq/5fbe854f7c87f072b7bb799b283acbb7 to your computer and use it in GitHub Desktop.
mjml_path = "samples/try_it_live.html.mjml"
file_read = fn ->
mjml_path
|> Path.basename # generate_html_path -> generate_mjml_path
|> Path.rootname # generate_mjml_path
|> fn file_name -> "tmp/#{UUID.uuid1}-#{file_name}" end.() # generate_mjml_path
|> Path.absname # generate_html_path
|> fn path -> # generate_html_path -> convert_into_html
File.mkdir("tmp") # convert_into_html
System.cmd("mjml", [mjml_path, "-o", path]) # convert_into_html
path # convert_into_html
end.()
|> fn path -> {File.read!(path), path} end.()
|> fn {bytes, path} -> File.rm!(path) && bytes end.()
|> EEx.compile_string(engine: Phoenix.HTML.Engine, line: 0, trim: true)
end
stdout_read = fn ->
{html, 0} = System.cmd("mjml", [mjml_path, "-s"])
html
|> EEx.compile_string(engine: Phoenix.HTML.Engine, line: 0, trim: true)
end
if file_read.() != stdout_read.() do
IO.puts "Both implementations differ"
System.halt(1)
end
%{
"file_read" => file_read,
"stdout_read" => stdout_read
}
|> Benchee.run time: 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment