View Source Orbit.View (Orbit v0.2.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

Add these imports to the view module:

import Orbit.Gemtext, only: [sigil_G: 2]
import Orbit.View

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

Functions

Define view functions from external files.

Renders a view within another view.

Link to this section Functions

Link to this macro

embed_templates(path)

View Source (macro)

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).

Link to this macro

render(view, assigns, block)

View Source (macro)

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 %>