This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/lib/temple/engine.ex

45 lines
1.1 KiB
Elixir

defmodule Temple.Engine do
@behaviour Phoenix.Template.Engine
@moduledoc """
The Temple HTML engine makes it possible to use Temple with Phoenix controllers.
To get started, you will configure Phoenix to use this module for `.exs` files.
```elixir
# config.exs
config :phoenix, :template_engines,
# this will work for files named like `index.html.exs`
exs: Temple.Engine
# config/dev.exs
config :your_app, YourAppWeb.Endpoint,
live_reload: [
patterns: [
~r"lib/myapp_web/(live|views)/.*(ex|exs|lexs)$",
~r"lib/myapp_web/templates/.*(eex|exs|lexs)$"
]
]
# my_app/
# lib/
# my_app/
# my_app_web/
# templates/
# posts/
# show.html.exs
```
Now you can get started by writing `exs` files in the templates directory and they will be compiled as you would expect.
"""
def compile(path, _name) do
require Temple
template = path |> File.read!() |> Code.string_to_quoted!(file: path)
Temple.temple(template)
|> EEx.compile_string(engine: Phoenix.HTML.Engine, file: path, line: 1)
end
end