Nabo v0.2.1 Nabo.Repo behaviour View Source
Precompiles and provides interface to interact with your posts.
defmodule MyRepo do
use Nabo.Repo, root: "priv/posts"
end
posts = MyRepo.all
{:ok, post} = MyRepo.get("foo")
post = MyRepo.get!("foo")
Compiler
By default Nabo uses Nabo.Compilers.Markdown compiler.
To customize compiler or compiler options, use :compiler option.
defmodule MyRepo do
use Nabo.Repo,
root: "priv/posts",
compiler: {
Nabo.Compilers.Markdown,
markdown: %Earmark.Options{smartypants: false}
}
end
See Nabo.Compiler more more information of how to build your own compiler.
Link to this section Summary
Callbacks
Fetches all available posts in the repo
Fetches all availables post names in the repo
Exclude draft posts
Filter only posts published before a specified datetime
Finds a post by the given slug
Similar to get/1 but raises error when no post was found
Order posts by date
Link to this section Callbacks
Link to this callback
exclude_draft(posts)
View Source
exclude_draft(posts :: [Nabo.Post.t]) :: [Nabo.Post.t]
Exclude draft posts.
Example
posts = MyRepo.all() |> MyRepo.exclude_draft()
Link to this callback
filter_published(posts, datetime)
View Source
filter_published(posts :: [Nabo.Post.t], datetime :: DateTime.t) :: [Nabo.Post.t]
Filter only posts published before a specified datetime.
Example
posts = MyRepo.all() |> MyRepo.filter_published()
Link to this callback
get(name)
View Source
get(name :: String.t) :: {:ok, Nabo.Post.t} | {:error, any}
Finds a post by the given slug.
Example
{:ok, post} = MyRepo.get("my-slug")
Link to this callback
order_by_date(posts)
View Source
order_by_date(posts :: [Nabo.Post.t]) :: [Nabo.Post.t]
Order posts by date.
Example
posts = MyRepo.all() |> MyRepo.order_by_date()