Skip to content

Instantly share code, notes, and snippets.

@sdomino
Last active October 31, 2019 15:25
Show Gist options
  • Save sdomino/3d8d43dd5005cbb98737c364de2d6357 to your computer and use it in GitHub Desktop.
Save sdomino/3d8d43dd5005cbb98737c364de2d6357 to your computer and use it in GitHub Desktop.
pdfer/lib/pdfer.ex
defmodule Pdfer do
@moduledoc """
Documentation for Pdfer.
"""
#
def generate(pdf_path, template_path, mapping_path) do
mapping = Jason.decode!(read_file(mapping_path))
template = read_file(template_path)
template
|> :bbmustache.render(mapping, key_type: :binary)
|> PdfGenerator.generate_binary!()
|> (&File.write("#{pdf_path}.pdf", &1)).()
end
#
defp read_file(filepath) do
__DIR__
|> Path.join(filepath)
|> File.read!()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment