x_component v0.1.0 X.Component View Source
Extends given module with the X component functions:
Example
defmodule ExampleComponent do
use X.Component,
assigns: %{
:message => String.t()
},
template: ~X"\""
<div>
{{ message }}
{{= yield }}
</div>
"\""
end
:assigns- list of component assigned variables. Types can be defined with Elixir typespecs:use X.Component, assigns: %{ :book => any(), :message => String.t(), :items => [{atom(), String.t(), boolean()}], optional(:active) => nil | boolean() }:template- component X template.
Component functions:
render/1,render/2- renders component asiodata. Render function can accept nestediodataelements:ExampleComponent.render(%{message: "Example"}) do [ ~X"\"" <form action="/test"> <input name="title"> </form> "\"", Button.render(%{test: "Submit"}) ] endrender_to_string/1,render_to_string/2- renders component tobitstring.assigns/0- returns a list of assigns with tuples where the first element is for the assignatomname and the second element is for required (true) and optional (false) assigns.ExampleComponent.assigns() # [message: true]template/0- returns X template string.ExampleComponent.template() # "<div>\n {{ message }}\n {{= yield }}\n</div>\n"