Brick v0.1.0 Brick.Component behaviour View Source
Define a brick component.
Example
defmodule Component do
# Allows any type supported by phoenix's format encoders
use Brick.Component, type: :html
end
Link to this section Summary
Callbacks
Static config for the component. This is only needed for the extended idea
behind Brick
to have a component library
Show dependencies of the components (manged by Brick.component/3
)
Entry point to rendering the component
Return the source for the component
Convert a variant name to the actual name with the component type appended
A list of all variants the component defines
Link to this section Types
source() View Source
variant()
View Source
variant() :: atom()
variant() :: atom()
variant_name()
View Source
variant_name() :: String.t()
variant_name() :: String.t()
Link to this section Functions
get_config(module, variant) View Source
put_dependency(module, dependancy, variant) View Source
Link to this section Callbacks
config(variant) View Source (optional)
Static config for the component. This is only needed for the extended idea
behind Brick
to have a component library.
Example
defmodule Component.Author do
use Brick.Component, type: :html
use Phoenix.HTML
def render("default.html", %{name: name}) do
content_tag :span, name, itemprop: "author"
end
def config(:default) do
%{
name: "My Component",
description: "My fancy component is a component",
context: %{
name: "Example Author"
}
}
end
end
dependencies() View Source
Show dependencies of the components (manged by Brick.component/3
).
render(term, term) View Source
Entry point to rendering the component.
render_source(arg0)
View Source
render_source(variant() | variant_name()) :: source()
render_source(variant() | variant_name()) :: source()
Return the source for the component.
variant(variant)
View Source
variant(variant()) :: variant_name()
variant(variant()) :: variant_name()
Convert a variant name to the actual name with the component type appended.
variants()
View Source
variants() :: [variant()]
variants() :: [variant()]
A list of all variants the component defines.
Example
defmodule Component.Author do
use Brick.Component, type: :html
use Phoenix.HTML
def render("default.html", %{name: name}) do
content_tag :span, name, itemprop: "author"
end
def render("cite.html", %{name: name}) do
content_tag :cite, name, itemprop: "author"
end
end
Component.Author.variants()
# [:default, :cite]