Phlex.Kit (phlex v0.3.0)

Copy Markdown View Source

Registers nested Phlex components as callable helpers.

Elixir counterpart to Phlex Ruby Kit. Because Elixir has no const_added hook, kits register components explicitly with kit_component/1:

defmodule MyApp.Components do
  use Phlex.Kit

  defmodule SayHi do
    use Phlex.HTML
    defstruct [:name, times: 1]

    def view_template(assigns, state) do
      # ...
    end
  end

  kit_component SayHi
end

Import or use the kit from another component to get say_hi/1-3 helpers. Calling those helpers outside a render that starts with %Phlex.SGML.State{} raises, matching Ruby kit guard behavior.

Summary

Functions

Registers a component module under a helper name.

Functions

kit_component(module_alias, opts \\ [])

(macro)

Registers a component module under a helper name.

Options:

  • :as - atom helper name (default: underscored last module segment)