Folio.Document (Folio v0.2.3)

Copy Markdown View Source

A complete document with content, styles, and file attachments.

Summary

Functions

Add content to the document.

Add one or more style rules to the document.

Attach a file to the document (images, bibliography, etc).

Create an empty document.

Types

t()

@type t() :: %Folio.Document{
  content: [Folio.Content.t()],
  files: %{required(String.t()) => binary()},
  styles: [Folio.Styles.rule()]
}

Functions

add_content(doc, nodes)

@spec add_content(t(), Folio.Content.t() | [Folio.Content.t()] | String.t()) :: t()

Add content to the document.

add_style(doc, rules)

@spec add_style(t(), Folio.Styles.rule() | [Folio.Styles.rule()]) :: t()

Add one or more style rules to the document.

attach_file(doc, path, data)

@spec attach_file(t(), String.t(), binary()) :: t()

Attach a file to the document (images, bibliography, etc).

Files are scoped to this document only — they don't leak across independent compile calls. Prefer this over Folio.register_file/2 for session isolation.

doc =
  Folio.Document.new()
  |> Folio.Document.attach_file("logo.png", File.read!("logo.png"))
  |> Folio.Document.add_content("![Logo](logo.png)")

new()

@spec new() :: t()

Create an empty document.