Last active
October 31, 2019 15:25
-
-
Save sdomino/3d8d43dd5005cbb98737c364de2d6357 to your computer and use it in GitHub Desktop.
pdfer/lib/pdfer.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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