View Source Rewrite.Filetype behaviour (rewrite v1.0.1)

The behaviour for filetypes.

An implementation of the filetype behaviour extends a source. For an example, see Rewrite.Source.Ex.

Summary

Callbacks

Returns the default path for the filetype.

Returns a list of file type extensions for which the module is responsible.

Fetches the value for a specific key for the given source.

Fetches the value for a specific key in a source for the given version.

Returns a Rewrite.Source with a filetype from the given string.

Returns a Rewrite.Source with a filetype form the given, string and options.

This function is called when the content or path of the source is updated.

This function is called when the source is updated by a key that is handled by the current filetype.

Returns a Rewrite.Source with a filetype from a file.

Returns a Rewrite.Source with a filetype from a file.

This function is called after an undo of the source.

Types

@type extension() :: String.t()
@type key() :: atom()
@type opts() :: keyword()
@type t() :: map()
@type updater() :: (term() -> term())
@type updates() :: keyword()
@type value() :: term()

Callbacks

@callback default_path() :: Path.t()

Returns the default path for the filetype.

@callback extensions() :: [extension()] | :any

Returns a list of file type extensions for which the module is responsible.

@callback fetch(source :: Rewrite.Source.t(), key()) :: value()

Fetches the value for a specific key for the given source.

If source contains the given key then its value is returned in the shape of {:ok, value}. If source doesn't contain key, :error is returned.

Link to this callback

fetch(source, key, version)

View Source
@callback fetch(source :: Rewrite.Source.t(), key(), version :: Rewrite.Source.version()) ::
  value()

Fetches the value for a specific key in a source for the given version.

If source contains the given key then its value is returned in the shape of {:ok, value}. If source doesn't contain key, :error is returned.

@callback from_string(string :: Rewrite.Source.content()) :: Rewrite.Source.t()

Returns a Rewrite.Source with a filetype from the given string.

Link to this callback

from_string(string, opts)

View Source
@callback from_string(string :: Rewrite.Source.content(), opts()) :: Rewrite.Source.t()

Returns a Rewrite.Source with a filetype form the given, string and options.

Link to this callback

handle_update(source, key, opts)

View Source
@callback handle_update(source :: Rewrite.Source.t(), key(), opts()) :: t()

This function is called when the content or path of the source is updated.

Returns a %Source{} with an updated filetype.

Link to this callback

handle_update(source, key, arg3, opts)

View Source
@callback handle_update(source :: Rewrite.Source.t(), key(), value() | updater(), opts()) ::
  updates()

This function is called when the source is updated by a key that is handled by the current filetype.

Returns a keyword with the keys :content and :filetype to update the source.

@callback read!(path :: Path.t()) :: Rewrite.Source.t()

Returns a Rewrite.Source with a filetype from a file.

@callback read!(path :: Path.t(), opts()) :: Rewrite.Source.t()

Returns a Rewrite.Source with a filetype from a file.

@callback undo(source :: Rewrite.Source.t()) :: Rewrite.Source.t()

This function is called after an undo of the source.