• Stars
    star
    416
  • Rank 104,068 (Top 3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An HTML DSL for Elixir and Phoenix

Temple

Actions Status Hex.pm

You are looking at the README for the main branch. The README for the latest stable release is located here.

Temple

Temple is an Elixir DSL for writing HTML and SVG.

Installation

Add temple to your list of dependencies in mix.exs:

def deps do
  [
    {:temple, "~> 0.12"}
  ]
end

Goals

Currently Temple has the following things on which it won't compromise.

  • Will only work with valid Elixir syntax.
  • Should work in all web environments such as Plug, Aino, Phoenix, and Phoenix LiveView.

Usage

Using Temple is as simple as using the DSL inside of an temple/1 block. The runtime result of the macro is your HTML.

See the guides for more details.

import Temple

temple do
  h2 do: "todos"

  ul class: "list" do
    for item <- @items do
      li class: "item" do
        div class: "checkbox" do
          div class: "bullet hidden"
        end

        div do: item
      end
    end
  end

  script do: """
  function toggleCheck({currentTarget}) {
    currentTarget.children[0].children[0].classList.toggle("hidden");
  }

  let items = document.querySelectorAll("li");

  Array.from(items).forEach(checkbox => checkbox.addEventListener("click", toggleCheck));
  """
end

Components

Temple components are simple to write and easy to use.

Unlike normal partials, Temple components have the concept of "slots", which are similar Vue. You can also refer to HEEx and Surface for examples of templates that have the "slot" concept.

Temple components are compatible with HEEx and Surface components and can be shared.

Please see the guides for more details.

defmodule MyAppWeb.Component do
  import Temple

  def card(assigns) do
    temple do
      section do
        div do
          slot @header
        end

        div do
          slot @inner_block
        end

        div do
          slot @footer
        end
      end
    end
  end
end

Using components is as simple as passing a reference to your component function to the c keyword.

import MyAppWeb.Component

c &card/1 do
  slot :header do
    @user.full_name
  end

  @user.bio

  slot :footer do
    a href: "https://twitter.com/#{@user.twitter}" do
      "@#{@user.twitter}"
    end
    a href: "https://github.com/#{@user.github}" do
      "@#{@user.github}"
    end
  end
end

Engine

By default, Temple will use the EEx.SmartEngine that is built into the Elixir standard library. If you are a web framework that uses it's own template engine (such as Aino and Phoenix/LiveView, you can configure Temple to it!

# config/config.exs

config :temple,
  engine: Aino.View.Engine # or Phoenix.HTML.Engine or Phoenix.LiveView.Engine

Formatter

To include Temple's formatter configuration, add :temple to your .formatter.exs.

[
  import_deps: [:temple],
  inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs,lexs}"],
]

Phoenix

When using Phoenix ~> 1.7, all you need to do is include :temple in your mix.exs.

If you plan on using the template structure that < 1.6 Phoenix applications use, you can use :temple_phoenix as described below.

To use with Phoenix, please use the temple_phoenix package! This bundles up some useful helpers as well as the Phoenix Template engine.

Related

More Repositories

1

elixir.nvim

Neovim plugin for Elixir
Lua
157
star
2

advent-of-code-elixir-starter

Template project for Advent of Code in Elixir.
Elixir
125
star
3

jekyll-tailwind-starter

Starter project for using Jekyll with Tailwind CSS
CSS
108
star
4

lazyasdf

Experimental TUI for asdf: a project to learn the art of the TUI.
Elixir
108
star
5

schematic

πŸ“ schematic
Elixir
82
star
6

output-panel.nvim

A panel to view the logs from your LSP servers.
Lua
61
star
7

jekyll-postcss

A plugin to use PostCSS plugins like Autoprefixer or Tailwind CSS with Jekyll.
Ruby
60
star
8

.dotfiles

My dotfiles
Lua
47
star
9

jekyll-purgecss

A Jekyll plugin for Purgecss.
Ruby
24
star
10

gen_lsp

A behaviour for creating language servers.
Elixir
21
star
11

early_return

early_return
Elixir
20
star
12

eex_compiler_visualizer

Elixir
16
star
13

everforest-textmate

Forest Night Color Scheme for editors using `tmTheme`
13
star
14

monkey

Monkey programming language interpreter implementations from the book "Writing an Interpreter in Go"
Elixir
11
star
15

contact

Instant Messaging application
Elixir
9
star
16

advent-of-code-clojure-starter

Template project for Advent of Code in Clojure.
Clojure
8
star
17

temple_phoenix

Integrates Temple and Phoenix
Elixir
7
star
18

install_fathom

Single command install of Fathom Analytics.
Shell
7
star
19

control-panel.nvim

experimental plugin, use with caution
Lua
5
star
20

advent-of-code

My Advent of Code solutions
Elixir
5
star
21

tableau

Experimental static site generator for Elixir
Elixir
5
star
22

silicon.lua

re-upload of 0oAstro/silicon.lua
Shell
5
star
23

everforest-alfred

5
star
24

blog

Jekyll source code for mitchellhanberg.com
HTML
4
star
25

pipsqueak

A modern and artisanal url shortener, with synergy.
Elixir
4
star
26

notebooks

4
star
27

workspace-folders.nvim

Lua
4
star
28

sandrabbit

sandrabbit
Elixir
3
star
29

zk.nvim

Exploratory plugin for sharing my zk+fzf configuration
Lua
3
star
30

monkey.nvim

Neovim plugin for the Monkey language
Lua
3
star
31

while

Elixir
3
star
32

loop

loop
Elixir
3
star
33

thicc_forest

My Neovim Colorscheme
Lua
3
star
34

blabber

Live-coding presentation tutorial project
Elixir
3
star
35

const

Constants for Elixir!
Elixir
2
star
36

nextls

Experimental language server for Elixir. Not for public usage.
Elixir
2
star
37

tree-sitter-elixir

Tree Sitter parser for Elixir
JavaScript
2
star
38

wallaby_httpoison_test

Elixir
2
star
39

alfred-localhost

Workflow to open localhost with any port easily
2
star
40

tableau_demo_heex

Demo showing a Tableau site using HEEx
Elixir
2
star
41

homebrew-zk

Ruby
2
star
42

tailwindcss-sketchpalette

A TailwindCSS .sketchpalette
2
star
43

hackery

Blog and website template for Tableau
Elixir
2
star
44

wallaby_plug_demo

Example application to demonstrate using Wallaby to test a standalone JS app
Elixir
1
star
45

temple_live_view

Elixir
1
star
46

issue-test

1
star
47

follow_through

Elixir
1
star
48

Buggy-s-TV-Guide

A program for CS408 at Purdue University
Java
1
star
49

surface_playground

Elixir
1
star
50

ziglings

Zig
1
star
51

duck

what the duck
Elixir
1
star
52

one-thing-workflow

A workflow to control One Thing
1
star
53

CatFeeder

Ruby
1
star
54

maigai

Experimental, Production Grade, Framework for Synergy
Elixir
1
star
55

lsp_codegen

Codegen for GenLSP
Elixir
1
star
56

inline_svg_test

Elixir
1
star
57

homebrew-tap

My personal homebrew tap
Ruby
1
star
58

enviro

HTML
1
star
59

ascii_dox

AsciiDoc implementation in Elixir
Elixir
1
star
60

neovim-macos-builder

Builds NeoVim artifacts for macOS
1
star
61

Lunch

An app to facilitate meal improvement through data collection and metric calculation
Ruby
1
star
62

blabber2

"Twitter" Clone built with Aino and Temple
Elixir
1
star
63

tree-sitter-monkey

Tree Sitter parser for Monkey
C
1
star
64

workflow-test

1
star
65

daily-ui

Daily UI challenges
1
star
66

YAFBC

a silly flappy bird clone
Java
1
star
67

wallaby_bug_demo

Elixir
1
star
68

diplo

Elixir
1
star
69

seven-langs

Scala
1
star
70

wallaby_stress_test

Elixir
1
star
71

cli

the motch cli
Shell
1
star
72

wallamox

Elixir
1
star
73

.github

1
star
74

temple_example

Elixir
1
star
75

foobar

Elixir
1
star
76

temple_heex_interop

Elixir
1
star
77

isBroken.js

πŸ”₯ Modern πŸš€ Fast 🎨 Artisanal
JavaScript
1
star
78

config_test

Elixir
1
star
79

reddit-deleter

A script to delete all of your Reddit posts and comments
Ruby
1
star
80

euler

Project Euler solutions
Ruby
1
star