Pipette
new_data <- pipette(data, template)
Summary
build(data, options \\ []) | Build text file from |
render(data, options) | Render a template file with |
Functions
Build text file from data
and write.
Returns :ok
, or {:error, reason}
if an error occurs.
Data
:template
- Path to template file.:destination
- Write built string todestination
.
Options
:pre
- Function to hook a data before rendering.:post
- Function to hook a string before writing file.
Examples
iex> File.read!("test/files/hello.txt")
"hello, <%= @msg %>\n"
iex> Pipette.build(%{template: "test/files/hello.txt", destination: "test/files/world.txt", msg: "world"})
:ok
iex> File.read!("test/files/world.txt")
"hello, world"
Render a template file with data
.
Returns {data, rendered_string}
, or {:error, reason}
if an error occurs.
Data
Same as build/2
.
Options
Same as build/2
.
Examples
iex> File.read!("test/files/hello.txt")
"hello, <%= @msg %>\n"
iex> Pipette.render(%{template: "test/files/hello.txt", msg: "world"}, [])
{%{msg: "world", template: "test/files/hello.txt"}, "hello, world"}