View Source Rewrite.Filetype behaviour (rewrite v0.9.0)
The behaviour for filetypes.
An implementation of the filetype behaviour extends a source. For an example,
see Rewrite.Source.Ex
.
Summary
Callbacks
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
from the given string
and path
.
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
Callbacks
@callback extensions() :: [extension()] | :any
Returns a list of file type extensions for which the module is responsible.
@callback fetch(source :: Rewrite.Source.t(), key :: 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.
@callback fetch( source :: Rewrite.Source.t(), key :: 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
.
@callback from_string(string :: Rewrite.Source.content(), path :: Path.t() | nil) :: Rewrite.Source.t()
Returns a Rewrite.Source
with a filetype
from the given string
and path
.
@callback from_string( strong :: Rewrite.Source.content(), path :: Path.t() | nil, options :: opts() ) :: Rewrite.Source.t()
Returns a Rewrite.Source
with a filetype
form the given
, string
and options
.
@callback handle_update(source :: Rewrite.Source.t(), key :: key()) :: t()
This function is called when the content or path of the source
is updated.
Returns a %Source{}
with an updated filetype
.
@callback handle_update(source :: Rewrite.Source.t(), key :: key(), value :: value()) :: 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(), options :: 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
.