Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Add support for Temple #152

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions lib/still/preprocessor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ defmodule Still.Preprocessor do
Save,
AddLayout,
AddContent,
Image
Image,
Temple
}

@default_preprocessors %{
".slim" => [AddContent, EEx, Frontmatter, Slime, OutputPath, AddLayout, Save],
".slime" => [AddContent, EEx, Frontmatter, Slime, OutputPath, AddLayout, Save],
".eex" => [AddContent, EEx, Frontmatter, OutputPath, AddLayout, Save],
".exs" => [AddContent, Frontmatter, Temple, EEx, OutputPath, AddLayout, Save],
".css" => [AddContent, EEx, CSSMinify, OutputPath, URLFingerprinting, AddLayout, Save],
".js" => [AddContent, EEx, JS, OutputPath, URLFingerprinting, AddLayout, Save],
".md" => [AddContent, EEx, Frontmatter, Markdown, OutputPath, AddLayout, Save],
Expand Down Expand Up @@ -141,11 +143,33 @@ defmodule Still.Preprocessor do
end)
end

@callback render(SourceFile.t()) :: SourceFile.t()
@type render_result ::
{:cont, SourceFile.t()}
| {:halt, SourceFile.t()}
| SourceFile.t()

@callback render(SourceFile.t()) :: render_result()

@callback after_render(SourceFile.t()) :: SourceFile.t()

@optional_callbacks render: 1, after_render: 1

@doc """
Identity function to silence pattern matching warnings from
Dialyzer.

Each preprocessor implements the `run/1` and `render/1` functions, so Dialyzer
knows whether all the branches in `case` statement are essential. They never
are, and most processors only return one type. So there's always going to a
warning there that's not helpful. Using this identity function that's only
defined once, we force Dialyzer to accept that those branches in `case` are
necessary.
"""
@spec handle_return(result :: render_result()) :: render_result()
def handle_return(value) do
value
end

defmacro __using__(_opts) do
quote do
@behaviour Still.Preprocessor
Expand All @@ -162,6 +186,7 @@ defmodule Still.Preprocessor do
def run(source_file, next_preprocessors) do
source_file
|> render()
|> Still.Preprocessor.handle_return()
|> case do
{:cont, source_file} ->
source_file
Expand Down Expand Up @@ -200,19 +225,18 @@ defmodule Still.Preprocessor do

Returns the resulting #{Still.SourceFile}.
"""
@spec after_render(SourceFile.t()) :: SourceFile.t()
@impl true
def after_render(source_file), do: source_file

@doc """
Runs the current preprocessor and invokes the next one.

Returns the resulting #{Still.SourceFile}.
"""
@spec render(SourceFile.t()) ::
{:cont, SourceFile.t()} | {:halt, SourceFile.t()} | SourceFile.t()
@impl true
def render(source_file), do: source_file

defoverridable render: 1, after_render: 1
defoverridable(Still.Preprocessor)
end
end
end
11 changes: 11 additions & 0 deletions lib/still/preprocessor/temple.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Still.Preprocessor.Temple do
alias Still.{Preprocessor, SourceFile}

use Preprocessor

@impl true
def render(%{content: content} = file) do
{content, _} = Code.eval_string(content, [], __ENV__)
%SourceFile{file | content: content, extension: ".html"}
end
end
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ defmodule Still.MixProject do
{:plug, "~> 1.10"},
{:plug_cowboy, "~> 2.3"},
{:slime, "~> 1.2"},
{:temple, "~> 0.6.0-rc.0"},
{:timex, "~> 3.5"},
{:yaml_elixir, "~> 2.4"}
]
Expand Down
3 changes: 2 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
"credo": {:hex, :credo, "1.5.5", "e8f422026f553bc3bebb81c8e8bf1932f498ca03339856c7fec63d3faac8424b", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd8623ab7091956a855dc9f3062486add9c52d310dfd62748779c4315d8247de"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"},
Expand Down Expand Up @@ -40,6 +40,7 @@
"slime": {:hex, :slime, "1.2.1", "71e036056051f0a6fae136af34eaa1322e8e11cdd2da3a56196fd31bca34dd49", [:mix], [{:neotoma, "~> 1.7", [hex: :neotoma, repo: "hexpm", optional: false]}], "hexpm", "298568e64291fed4eb690be094f6c46400daa03b594bab34fcaa0167e139c263"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
"temple": {:hex, :temple, "0.6.0-rc.0", "2febf687a87901629e9ad994200a55e0d23b700413e7cb0afc26716ad485b52f", [:mix], [{:phoenix, ">= 0.0.0", [hex: :phoenix, repo: "hexpm", optional: true]}], "hexpm", "408988b116a5f7f53ae822aa844e7f6dae28a21e4038e21b5fcddc51493e5c0d"},
"timex": {:hex, :timex, "3.6.2", "845cdeb6119e2fef10751c0b247b6c59d86d78554c83f78db612e3290f819bc2", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "26030b46199d02a590be61c2394b37ea25a3664c02fafbeca0b24c972025d47a"},
"tzdata": {:hex, :tzdata, "1.0.5", "69f1ee029a49afa04ad77801febaf69385f3d3e3d1e4b56b9469025677b89a28", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "55519aa2a99e5d2095c1e61cc74c9be69688f8ab75c27da724eb8279ff402a5a"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
Expand Down
31 changes: 31 additions & 0 deletions priv/site/_includes/main.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use Temple

temple do
div class: "main" do
div class: "content" do
h1 class: "fancy-title" do
div class: "visually-hidden" do
"Still"
end
end

div class: "logo-container" do
responsive_image("_includes/logo.png", class: "logo", aria_hidden: true)
end

p class: "lead" do
"A composable elixir static site builder"
end

div class: "info" do
link(@env, "Docs", to: "https://hexdocs.pm/still", class: "cta")
|> to_string()
link(@env, "GitHub", to: "https://github.com/still-ex/still", class: "cta")
|> to_string()
end
end
include(@env, "_includes/marquee.exs")
div class: "overlay"
responsive_image("_includes/main.jpg", class: "cover", aria_hidden: true)
end
end
22 changes: 0 additions & 22 deletions priv/site/_includes/main.slime

This file was deleted.

17 changes: 17 additions & 0 deletions priv/site/_includes/marquee.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
text: "Tonight on display: still (featuring elixir)"
---

use Temple

temple do
div class: "marquee" do
div class: "content" do
for _ <- 1..5 do
span do
@text
end
end
end
end
end
2 changes: 1 addition & 1 deletion priv/site/index.slime
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: _layout.slime
---

= include(@env, "_includes/main.slime")
= include(@env, "_includes/main.exs")
= include(@env, "_includes/manifesto.slime")
= include(@env, "_includes/getting_started.slime")
= include(@env, "_includes/community.slime")
Expand Down