exhtml v0.3.1 Exhtml.Storage
Storage provides a fetch
method used to fetch content from outside
source.
Examples:
iex> {:ok, pid} = Exhtml.Storage.start_link []
...> Exhtml.Storage.fetch(pid, :foo)
nil
iex> # fetcher can be replaced at runtime
...> Exhtml.Storage.set_fetcher(pid, fn slug -> "#{slug} is awesome" end)
...> Exhtml.Storage.fetch(pid, :foo)
"foo is awesome"
or you can start a process, passing fetcher:
iex> fetcher = fn slug -> "#{slug} on remote" end
...> {:ok, pid} = Exhtml.Storage.start_link fetcher: fetcher
...> Exhtml.Storage.fetch(pid, :foo)
"foo on remote"
Summary
Functions
Fetches the content of a slug
Dynamicly set content fetcher. A fetcher can be a function, or a module that can repsond to &fetch/1.
If you want to ‘unset’ fetcher, just pass nil
as fetcher
Types
Functions
Fetches the content of a slug.
pid
- the PID or name of the server processslug
- the key for the content
Returns nil
or the content stored.
Examples:
iex> {:ok, pid} = Exhtml.Storage.start_link [fetcher: fn slug -> "default_content_for_#{slug}" end]
...> Exhtml.Storage.fetch(pid, :foo)
"default_content_for_foo"
Dynamicly set content fetcher. A fetcher can be a function, or a module that can repsond to &fetch/1.
If you want to ‘unset’ fetcher, just pass nil
as fetcher.
pid
- the PID or name of the server processf
- function or module to fetch the content by a slug
Returns :ok
.
Examples:
use a function as fetcher:
iex> {:ok, pid} = Exhtml.Storage.start_link []
...> Exhtml.Storage.set_fetcher(pid, fn _slug -> :bar end)
:ok
or a module:
iex> defmodule A do
...> def fetch(slug), do: "Hello, #{slug}~"
...> end
...>
...> {:ok, pid} = Exhtml.Storage.start_link []
...> Exhtml.Storage.set_fetcher(pid, A)
:ok
iex> Exhtml.Storage.fetch(pid, :miao)
"Hello, miao~"