View Source Orbit.View (Orbit v0.1.0)
Render Gemtext content.
A "view" is any 1-arity function that accepts a map of assigns and returns a string of rendered Gemtext.
The ~G
sigil is used to precompile EEx templates as strings when an assigns
variable or argument is
in scope.
Views can be defined as functions, or embedded from .gmi.eex
files into view module via embed_templates/1
.
usage
Usage
use Orbit.View
injects the following in the module:
import Orbit.Gemtext, only: [sigil_G: 2]
import Orbit.View
require EEx
example
Example
defmodule MyApp.MyView do
use Orbit.View
embed_templates "my_view/*"
def list(assigns) do
~G"""
<%= for item <- @items do %>
* <%= item %>
<% end %>
"""
end
end
Link to this section Summary
Link to this section Functions
Define view functions from external files.
Every file found in the wildcard path
is compiled as EEx and injected as a view function into the view
module, using the file basename as the function name. For example, index.gmi.eex
will be defined as
def index(assigns)
.
Renders a view within another view.
The assigns
and block
arguments are optional.
If a block is passed, its contents are renderd and set to @inner_content
assign of the view.
examples
Examples
<%= render &my_view/1 %>
<%= render &my_view/1, title: @title %>
<%= render &my_component/1 do %>
inner content
<% end %>