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

Link to this type

source() View Source
source() ::
  {:inline, String.t()}
  | {:template, String.t()}
  | {:combo, inline :: String.t(), template :: String.t()}

Link to this type

variant() View Source
variant() :: atom()

Link to this type

variant_name() View Source
variant_name() :: String.t()

Link to this section Functions

Link to this function

get_config(module, variant) View Source

Link to this function

put_dependency(module, dependancy, variant) View Source

Link to this section Callbacks

Link to this callback

config(variant) View Source (optional)
config(variant()) :: term()

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
Link to this callback

dependencies() View Source
dependencies() :: [{module(), variant()}]

Show dependencies of the components (manged by Brick.component/3).

Link to this callback

render(term, term) View Source
render(term(), term()) :: term()

Entry point to rendering the component.

Link to this callback

render_source(arg0) View Source
render_source(variant() | variant_name()) :: source()

Return the source for the component.

Convert a variant name to the actual name with the component type appended.

Link to this callback

variants() View Source
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]