exhtml v0.4.0-beta.2 Exhtml

Exhtml serves HTML contents. It fetches content from backend storage and saves in its state. HTML contents are responded to user directly from state.

Examples:

iex> Exhtml.start []
...> #update
...> Exhtml.update_content(:foo)
"default_content_for_foo"
iex> # get
...> Exhtml.get_content(:foo)
"default_content_for_foo"

Link to this section Summary

Functions

Deletes the content from a host

Gets html content from a host

Gets html content from a host

Join an existing exhtml cluster

Sets html content to a host with a slug

Sets the content fetcher. A content fetcher is used when Exhtml.update_content/1 is called. You can pass a function or module as content fetcher

Start the repo engine. Before starting a repo, all actions will not be performed and {:error, :repo_not_started} will be returned

Fetchs and sets the content from the storage to a host’s table

Link to this section Types

Link to this type slug()
slug() :: binary() | atom()

Link to this section Functions

Link to this function delete_content(slug)
delete_content(slug()) :: :ok

Deletes the content from a host.

  • slug is the key of content.

Returns :ok.

Examples:

iex> Exhtml.start []
...> Exhtml.set_content :foo, :bar
...> Exhtml.get_content :foo
:bar
iex> Exhtml.delete_content :foo
:ok
iex> Exhtml.get_content :foo
nil
Link to this function get_content(slug)
get_content(slug()) :: any()

Gets html content from a host.

  • slug is the key of content to get.

Examples:

iex> Exhtml.start []
...> Exhtml.start_repo([])
...> Exhtml.set_content(:foo, :bar)
...> Exhtml.get_content(:foo)
:bar
Link to this function get_content_since(slug, time)
get_content_since(slug(), DateTime.t()) :: any()

Gets html content from a host.

  • slug is the key of content to get.
  • time is the modified time.

Returns:

{:not_modified} - If the content has not changed since the time; content - if the content has changed since the time.

Link to this function join_repo(node, opts)

Join an existing exhtml cluster.

  • node - the node to connect
  • opts - options to start this repo node, including:

    • data_dir - where to store db datas, ./exhtml_contents by default.
    • data_nodes - which nodes are used to copy datas, [node()] by default.
Link to this function set_content(slug, value)
set_content(slug(), any()) :: :ok

Sets html content to a host with a slug.

  • slug is the key of content.
  • value is the content.

Returns :ok.

Examples:

iex> Exhtml.start []
...> Exhtml.start_repo([])
...> Exhtml.set_content(:foo, :bar)
...> Exhtml.get_content(:foo)
:bar
Link to this function set_content_fetcher(f)
set_content_fetcher((slug() -> any()) | module()) :: :ok

Sets the content fetcher. A content fetcher is used when Exhtml.update_content/1 is called. You can pass a function or module as content fetcher.

Returns :ok.

Examples:

iex> Exhtml.start []
...> Exhtml.start_repo []
...> Exhtml.set_content_fetcher(fn slug -> "Hi, #{slug}!" end)
:ok
iex> Exhtml.update_content(:foo)
"Hi, foo!"
iex> Exhtml.get_content(:foo)
"Hi, foo!"
Link to this function start_repo(opts)

Start the repo engine. Before starting a repo, all actions will not be performed and {:error, :repo_not_started} will be returned.

Link to this function update_content(slug)
update_content(slug()) :: any()

Fetchs and sets the content from the storage to a host’s table.

  • slug is the key of content.

Returns anything returned by the fetcher.

Examples:

iex> Exhtml.start []
...> Exhtml.start_repo([])
...> Exhtml.set_content_fetcher fn slug -> "Hi, #{slug}!" end
...> Exhtml.update_content :wuliu
"Hi, wuliu!"