View Source Orbit.Gemtext (Orbit v0.3.0)
Render Gemtext content.
A template is any 1-arity function that accepts an assigns map and returns a string of rendered Gemtext.
A view is a module containing template functions.
Templates can be defined directly as functions, or embedded from .gmi.eex files into view module via embed_templates/1.
EEx templates can be precompiled with sigil_G/2, as long as an assigns variable is in-scope.
Usage
Add the imports to the view module:
import Orbit.GemtextExamples
Importing templates from a directory
defmodule MyAppCapsule.PostGmi do
import Orbit.Gemtext
embed_templates "post_gmi/*"
endWriting templates directly
defmodule MyAppCapsule.PostGmi do
import Orbit.Gemtext
def list(assigns) do
~G"""
<%= for item <- @items do %>
* <%= item %>
<% end %>
"""
end
end
Summary
Functions
Precompile template functions from external files.
Renders a template.
Sigil for defining Gemtext content.
Functions
Precompile template functions from external files.
Every file found in the wildcard path is compiled as EEx and injected as a template 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 template.
The assigns and block arguments are optional.
If a block is passed, its contents set to @inner_content assign of the template.
Examples
<%= render &my_template/1 %>
<%= render &my_template/1, title: @title %>
<%= render &my_template/1 do %>
inner content here
<% end %>
Sigil for defining Gemtext content.
The assigns map must be in-scope.
A single trailing newline character \n will be trimmed, if it exists.
Example
def hello(assigns) do
~G"""
Why hello there, <%= @name %>!
"""
end