charge

Types

Types of assets within a pipeline

pub opaque type Asset

Represents an HTML file that will be comitted to disk when assets are written

pub type HTMLFile {
  HTMLFile(
    source: option.Option(fs.Path),
    path: fs.SitePath,
    html: element.ElementTree,
  )
}

Constructors

Represents the current collection of data in the pipeline

pub opaque type Loaded(page, aggregate)

Represents a composable pipeline with state and aggregate data that is passed between stages

pub opaque type Pipeline(state, aggregate)

Represents the list of assets rendered in a pipeline so far

pub type Rendered =
  List(Asset)
pub type Renderer(state, aggregate) =
  fn(List(state), aggregate) -> promise.Promise(
    Result(List(Asset), error.ChargeError),
  )

Values

pub fn asset_to_readable_string(asset: Asset) -> String

Converts an asset to a string - useful for snapshot testing.

pub fn assets_to_readable_string(assets: List(Asset)) -> String

Converts an asset to a string - useful for snapshot testing. Assets are ordered by path and can be used for snapshot testing

pub fn derived_html_file(
  source: fs.Path,
  path: fs.SitePath,
  rendered: element.ElementTree,
) -> Asset

Create an HTML File asset that is marked as derived - i.e. it is based on another source file on disk such as a markdown file on disk

pub fn find_asset(
  assets: List(Asset),
  path: fs.SitePath,
) -> Result(Asset, Nil)

Find an asset given a SitePath

pub fn generated_html_file(
  path: fs.SitePath,
  rendered: element.ElementTree,
) -> Asset

Create an HTML File asset that is marked as generated - i.e. it is not based on another file on disk

pub fn if_html(
  asset: Asset,
  or_else: a,
  f: fn(HTMLFile) -> a,
) -> a

Guard to be used for running transformations on HTML assets

pub fn loaded(
  pages pages: List(page),
  aggregate aggregate: aggregate,
) -> Loaded(page, aggregate)

Create the loaded data to be returned from a pipeline

pub fn new(
  out out_dir: fs.Path,
  load load: fn() -> Result(
    Loaded(state, aggregate),
    error.ChargeError,
  ),
  render render: fn(List(state), aggregate) -> Result(
    List(Asset),
    error.ChargeError,
  ),
) -> Pipeline(state, aggregate)

Createa a new pipeline from scratch

pub fn run(
  pipeline: Pipeline(page, aggregate),
) -> promise.Promise(Result(List(Asset), error.ChargeError))

Cleans the output directory and runs the pipeline

pub fn text_file(path: fs.SitePath, content: String) -> Asset

Create a TextFile asset that will be written to disk

pub fn with(
  from: Pipeline(page, aggregate),
  render: fn(aggregate) -> Result(List(Asset), error.ChargeError),
) -> Pipeline(page, aggregate)

The raw unit for composing sync rendering pipelines

pub fn with_asset(
  from: Pipeline(page, aggregate),
  render: fn(aggregate) -> Result(Asset, error.ChargeError),
) -> Pipeline(page, aggregate)

Derive an asset from the pipeline aggregate

pub fn with_assets(
  from: Pipeline(page, aggregate),
  render: fn(aggregate) -> Result(List(Asset), error.ChargeError),
) -> Pipeline(page, aggregate)

Derive some assets from the pipeline aggregate

pub fn with_async(
  from: Pipeline(page, aggregate),
  render: fn(aggregate) -> promise.Promise(
    Result(List(Asset), error.ChargeError),
  ),
) -> Pipeline(page, aggregate)

The raw unit for composing async rendering pipelines

pub fn with_async_component(
  from: Pipeline(state, aggregate),
  comp: #(
    String,
    fn(component.RenderData, element.ElementTree) -> promise.Promise(
      Result(element.ElementTree, error.ChargeError),
    ),
  ),
) -> Pipeline(state, aggregate)

Add a server-side component to the pipeline Components can be defined using component.new.

Sync components can be defined using with_component or with_components

pub fn with_component(
  from: Pipeline(page, aggregate),
  component: #(
    String,
    fn(component.RenderData, element.ElementTree) -> Result(
      element.ElementTree,
      error.ChargeError,
    ),
  ),
) -> Pipeline(page, aggregate)

Add a server-side component to the pipeline Components can be defined using component.new.

Async components can be defined using with_async_component

pub fn with_components(
  from: Pipeline(page, aggregate),
  comps: List(
    #(
      String,
      fn(component.RenderData, element.ElementTree) -> Result(
        element.ElementTree,
        error.ChargeError,
      ),
    ),
  ),
) -> Pipeline(page, aggregate)

Add server-side components to the pipeline Components can be defined using component.new.

Async components can be defined using with_async_component

pub fn with_derived_assets(
  from: Pipeline(page, aggregate),
  extract: fn(Asset) -> Result(List(Asset), error.ChargeError),
) -> Pipeline(page, aggregate)

Add assets that are derived from an existing asset, e.g. providing an alternate of each page

pub fn with_static_dir(
  pipeline: Pipeline(page, aggregate),
  dir: fs.Path,
) -> Pipeline(page, aggregate)

Add a static directory to be copied as part of the pipeline

pub fn with_summary(
  from: Pipeline(state, aggregate),
  summarize: fn(List(Asset), aggregate) -> Result(
    List(Asset),
    error.ChargeError,
  ),
) -> Pipeline(state, aggregate)

Add some generic tasks into the pipeline given all the assets rendered till this point as well as the relevant aggregate e.g. running creating an accessibility report on all generated html pages, creating an RSS Feed, etc.

This receives all previously processed assets so it should likely only be used once all other assets are fully processed

Search Document