Pipette

new_data <- pipette(data, template)

Source

Summary

build(data, options \\ [])

Build text file from data and write. Returns :ok, or {:error, reason} if an error occurs

render(data, options)

Render a template file with data. Returns {data, rendered_string}, or {:error, reason} if an error occurs

Functions

build(data, options \\ [])

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 to destination.

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"
Source
render(data, options)

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"}
Source