Compare commits
12 Commits
8a9e06448b
...
d1db62ef58
Author | SHA1 | Date |
---|---|---|
FloatingGhost | d1db62ef58 | |
FloatingGhost | 33642c15d3 | |
FloatingGhost | 1b1585657f | |
dependabot[bot] | cfb2a325b9 | |
Mitchell Hanberg | da568bf84e | |
Mitchell Hanberg | d81458562f | |
Mitchell Hanberg | 1ae81b1d90 | |
github-actions[bot] | a991e71851 | |
Mitchell Hanberg | 0c166da988 | |
Mitchell Hanberg | dc57221bc9 | |
FloatingGhost | 066a699ade | |
FloatingGhost | 66735c51ba |
|
@ -22,6 +22,9 @@ jobs:
|
|||
with:
|
||||
release-type: elixir
|
||||
package-name: temple
|
||||
bump-minor-pre-major: true
|
||||
extra-files: |
|
||||
README.md
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
elixir 1.14.0-otp-25
|
||||
erlang 25.0-rc2
|
||||
elixir 1.15.4-otp-26
|
||||
erlang 26.0.2
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -2,6 +2,22 @@
|
|||
|
||||
## Main
|
||||
|
||||
## [0.12.0](https://github.com/mhanberg/temple/compare/v0.11.0...v0.12.0) (2023-06-13)
|
||||
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* configure runtime attributes function ([#202](https://github.com/mhanberg/temple/issues/202))
|
||||
|
||||
### Features
|
||||
|
||||
* configure runtime attributes function ([#202](https://github.com/mhanberg/temple/issues/202)) ([dc57221](https://github.com/mhanberg/temple/commit/dc57221bc99e165530134559097b27b1dfe95dbe))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **docs:** typos ([7a50587](https://github.com/mhanberg/temple/commit/7a505875af6a1cee1536e516528f5be914df1f3f))
|
||||
|
||||
## v0.11.0
|
||||
|
||||
### Breaking Changes
|
||||
|
|
|
@ -14,13 +14,16 @@ Temple is an Elixir DSL for writing HTML and SVG.
|
|||
|
||||
Add `temple` to your list of dependencies in `mix.exs`:
|
||||
|
||||
<!-- x-release-please-start-version -->
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:temple, "~> 0.11.0"}
|
||||
{:temple, "~> 0.12"}
|
||||
]
|
||||
end
|
||||
```
|
||||
<!-- x-release-please-end -->
|
||||
|
||||
## Goals
|
||||
|
||||
Currently Temple has the following things on which it won't compromise.
|
||||
|
|
|
@ -42,13 +42,16 @@ Temple works out of the box without any configuration, but here are a couple of
|
|||
|
||||
### Engine
|
||||
|
||||
By default, Temple uses the built in `EEx.SmartEngine`. If you want to use a different engine, this is as easy as setting the `:engine` configuration option.
|
||||
By default, Temple uses the built in `Phoenix.HTML.Engine`. If you want to use a different engine, this is as easy as setting the `:engine` configuration option.
|
||||
|
||||
You can also configure the function that is used for runtime attributes. By default, Temple uses `Phoenix.HTML.attributes_escape/1`.
|
||||
|
||||
```elixir
|
||||
# config/config.exs
|
||||
|
||||
config :temple,
|
||||
engine: Phoenix.HTML.Engine
|
||||
engine: EEx.SmartEngine,
|
||||
attributes: {Temple, :attributes}
|
||||
```
|
||||
|
||||
### Aliases
|
||||
|
|
|
@ -96,16 +96,40 @@ defmodule Temple do
|
|||
require Temple.Renderer
|
||||
|
||||
Temple.Renderer.compile(unquote(block))
|
||||
|> then(fn
|
||||
{:safe, template} ->
|
||||
template
|
||||
|
||||
template ->
|
||||
template
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@doc false
|
||||
defdelegate engine, to: Temple.Renderer
|
||||
|
||||
@doc """
|
||||
Compiles runtime attributes.
|
||||
|
||||
To use this function, you set it in application config.
|
||||
|
||||
By default, Temple uses `{Phoenix.HTML, :attributes_escape}`. This is useful if you want to use `EEx.SmartEngine`.
|
||||
|
||||
```elixir
|
||||
config :temple,
|
||||
engine: EEx.SmartEngine,
|
||||
attributes: {Temple, :attributes}
|
||||
```
|
||||
|
||||
> #### Note {: .info}
|
||||
>
|
||||
> This function does not do any HTML escaping
|
||||
|
||||
> #### Note {: .info}
|
||||
>
|
||||
> This function is used by the compiler and shouldn't need to be used directly.
|
||||
"""
|
||||
def attributes(attributes) do
|
||||
for {key, value} <- attributes, into: "" do
|
||||
case value do
|
||||
true -> ~s| #{key}|
|
||||
false -> ""
|
||||
value -> ~s| #{key}="#{value}"|
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,11 +42,7 @@ defmodule Temple.Ast.NonvoidElementsAliases do
|
|||
)
|
||||
end
|
||||
|
||||
defp whitespace(meta) do
|
||||
if Keyword.has_key?(meta, :end) do
|
||||
:loose
|
||||
else
|
||||
:tight
|
||||
end
|
||||
defp whitespace(_meta) do
|
||||
:tight
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
defmodule Temple.Ast.Utils do
|
||||
@moduledoc false
|
||||
|
||||
@attributes Application.compile_env(
|
||||
:temple,
|
||||
:attributes,
|
||||
{Phoenix.HTML, :attributes_escape}
|
||||
)
|
||||
|
||||
def snake_to_kebab(stringable),
|
||||
do: stringable |> to_string() |> String.replace_trailing("_", "") |> String.replace("_", "-")
|
||||
|
||||
|
@ -34,7 +40,7 @@ defmodule Temple.Ast.Utils do
|
|||
[
|
||||
{:expr,
|
||||
quote do
|
||||
Phoenix.HTML.attributes_escape(unquote(List.first(attrs)))
|
||||
unquote(__MODULE__).__attributes__(unquote(List.first(attrs)))
|
||||
end}
|
||||
]
|
||||
end
|
||||
|
@ -57,7 +63,7 @@ defmodule Temple.Ast.Utils do
|
|||
def build_attr("rest!", {_, _, _} = value) do
|
||||
expr =
|
||||
quote do
|
||||
Phoenix.HTML.attributes_escape(unquote(value))
|
||||
unquote(__MODULE__).__attributes__(unquote(value))
|
||||
end
|
||||
|
||||
[{:expr, expr}]
|
||||
|
@ -66,7 +72,7 @@ defmodule Temple.Ast.Utils do
|
|||
def build_attr(name, {_, _, _} = value) do
|
||||
expr =
|
||||
quote do
|
||||
Phoenix.HTML.attributes_escape([{unquote(name), unquote(value)}])
|
||||
unquote(__MODULE__).__attributes__([{unquote(name), unquote(value)}])
|
||||
end
|
||||
|
||||
[{:expr, expr}]
|
||||
|
@ -154,4 +160,10 @@ defmodule Temple.Ast.Utils do
|
|||
|
||||
ast
|
||||
end
|
||||
|
||||
def __attributes__(attributes) do
|
||||
{mod, func} = @attributes
|
||||
|
||||
apply(mod, func, [attributes])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@ defmodule Temple.Component do
|
|||
import Temple
|
||||
@doc false
|
||||
def component(func, assigns, _) do
|
||||
{:safe, apply(func, [assigns])}
|
||||
apply(func, [assigns])
|
||||
end
|
||||
|
||||
defmacro inner_block(_name, do: do_block) do
|
||||
|
|
|
@ -157,8 +157,8 @@ defmodule Temple.Renderer do
|
|||
def render(buffer, state, %NonvoidElementsAliases{} = ast) do
|
||||
current_indent = Utils.indent(state.indentation)
|
||||
|
||||
inside_new_lines = if ast.meta.whitespace == :tight, do: "", else: "\n"
|
||||
new_indent = if ast.meta.whitespace == :tight, do: nil, else: state.indentation + 1
|
||||
inside_new_lines = ""
|
||||
new_indent = nil
|
||||
|
||||
buffer =
|
||||
state.engine.handle_text(
|
||||
|
@ -207,7 +207,7 @@ defmodule Temple.Renderer do
|
|||
state.engine.handle_text(
|
||||
buffer,
|
||||
[],
|
||||
"#{inside_new_lines}#{Utils.indent(if(ast.meta.whitespace == :loose, do: state.indentation, else: nil))}</#{ast.name}>#{new_line(state)}\n"
|
||||
"#{inside_new_lines}#{Utils.indent(if(ast.meta.whitespace == :loose, do: state.indentation, else: nil))}</#{ast.name}>#{new_line(state)}"
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -233,7 +233,7 @@ defmodule Temple.Renderer do
|
|||
end
|
||||
end
|
||||
|
||||
state.engine.handle_text(buffer, [], ">\n")
|
||||
state.engine.handle_text(buffer, [], ">")
|
||||
end
|
||||
|
||||
def render(buffer, state, %AnonymousFunctions{} = ast) do
|
||||
|
@ -245,7 +245,7 @@ defmodule Temple.Renderer do
|
|||
render(new_buffer, state, child)
|
||||
end
|
||||
|
||||
new_buffer = state.engine.handle_text(new_buffer, [], "\n")
|
||||
new_buffer = state.engine.handle_text(new_buffer, [], "")
|
||||
|
||||
inner_quoted = state.engine.handle_end(new_buffer)
|
||||
|
||||
|
@ -355,7 +355,7 @@ defmodule Temple.Renderer do
|
|||
buffer = state.engine.handle_expr(buffer, "=", elixir_ast)
|
||||
|
||||
if not state.terminal_node do
|
||||
state.engine.handle_text(buffer, [], "\n")
|
||||
state.engine.handle_text(buffer, [], "")
|
||||
else
|
||||
buffer
|
||||
end
|
||||
|
@ -366,6 +366,6 @@ defmodule Temple.Renderer do
|
|||
defp children(%ElementList{children: children}), do: children
|
||||
defp children(list) when is_list(list), do: list
|
||||
|
||||
def new_line(%{terminal_node: false}), do: "\n"
|
||||
def new_line(%{terminal_node: false}), do: ""
|
||||
def new_line(%{terminal_node: true}), do: ""
|
||||
end
|
||||
|
|
6
mix.exs
6
mix.exs
|
@ -6,7 +6,7 @@ defmodule Temple.MixProject do
|
|||
app: :temple,
|
||||
name: "Temple",
|
||||
description: "An HTML DSL for Elixir",
|
||||
version: "0.11.0",
|
||||
version: "0.12.0",
|
||||
package: package(),
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
elixir: "~> 1.13",
|
||||
|
@ -66,7 +66,7 @@ defmodule Temple.MixProject do
|
|||
maintainers: ["Mitchell Hanberg"],
|
||||
licenses: ["MIT"],
|
||||
links: %{github: "https://github.com/mhanberg/temple"},
|
||||
files: ~w(lib priv CHANGELOG.md LICENSE mix.exs README.md .formatter.exs)
|
||||
files: ~w(lib CHANGELOG.md LICENSE mix.exs README.md .formatter.exs)
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -75,7 +75,7 @@ defmodule Temple.MixProject do
|
|||
{:floki, ">= 0.0.0"},
|
||||
{:phoenix_html, "~> 3.2"},
|
||||
{:typed_struct, "~> 0.3"},
|
||||
{:ex_doc, "~> 0.29.0", only: :dev, runtime: false}
|
||||
{:ex_doc, "~> 0.30.0", only: :dev, runtime: false}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
10
mix.lock
10
mix.lock
|
@ -1,12 +1,12 @@
|
|||
%{
|
||||
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.29.1", "b1c652fa5f92ee9cf15c75271168027f92039b3877094290a75abcaac82a9f77", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "b7745fa6374a36daf484e2a2012274950e084815b936b1319aeebcf7809574f6"},
|
||||
"earmark_parser": {:hex, :earmark_parser, "1.4.33", "3c3fd9673bb5dcc9edc28dd90f50c87ce506d1f71b70e3de69aa8154bc695d44", [:mix], [], "hexpm", "2d526833729b59b9fdb85785078697c72ac5e5066350663e5be6a1182da61b8f"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.30.0", "ed94bf5183f559d2f825e4f866cc0eab277bbb17da76aff40f8e0f149656943e", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "6743fe46704fe27e2f2558faa61f00e5356528768807badb2092d38476d6dac2"},
|
||||
"floki": {:hex, :floki, "0.34.0", "002d0cc194b48794d74711731db004fafeb328fe676976f160685262d43706a8", [:mix], [], "hexpm", "9c3a9f43f40dde00332a589bd9d389b90c1f518aef500364d00636acc5ebc99c"},
|
||||
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
|
||||
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
|
||||
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
|
||||
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
|
||||
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
|
||||
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
|
||||
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
|
||||
"typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"},
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
defmodule Temple.Support.Helpers do
|
||||
defmacro assert_html(expected, actual) do
|
||||
quote do
|
||||
assert unquote(expected) == Phoenix.HTML.safe_to_string(unquote(actual)), """
|
||||
--- Expected ---
|
||||
#{unquote(expected)}----------------
|
||||
import ExUnit.Assertions
|
||||
|
||||
--- Actual ---
|
||||
#{Phoenix.HTML.safe_to_string(unquote(actual))}--------------
|
||||
"""
|
||||
defmacro assert_html(expected, actual) do
|
||||
quote location: :keep do
|
||||
unquote(__MODULE__).__assert_html__(unquote_splicing([expected, actual]))
|
||||
end
|
||||
end
|
||||
|
||||
def __assert_html__(expected, actual) do
|
||||
actual = actual |> Phoenix.HTML.Engine.encode_to_iodata!() |> IO.iodata_to_binary()
|
||||
|
||||
assert expected == actual,
|
||||
"""
|
||||
--- Expected ---
|
||||
#{expected}----------------
|
||||
|
||||
--- Actual ---
|
||||
#{actual}--------------
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@ defmodule Temple.Ast.TempleNamespaceNonvoidTest do
|
|||
attrs: [class: "foo", id: {:var, [], _}],
|
||||
children: %ElementList{
|
||||
children: [%Text{text: "foo"}],
|
||||
whitespace: :loose
|
||||
whitespace: :tight
|
||||
}
|
||||
} = ast
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ defmodule Temple.Ast.UtilsTest do
|
|||
|
||||
assert Macro.to_string(
|
||||
quote do
|
||||
Phoenix.HTML.attributes_escape([{"class", unquote(class_ast)}])
|
||||
Temple.Ast.Utils.__attributes__([{"class", unquote(class_ast)}])
|
||||
end
|
||||
) == Macro.to_string(actual)
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ defmodule Temple.Ast.UtilsTest do
|
|||
|
||||
assert Macro.to_string(
|
||||
quote do
|
||||
Phoenix.HTML.attributes_escape(unquote(rest_ast))
|
||||
Temple.Ast.Utils.__attributes__(unquote(rest_ast))
|
||||
end
|
||||
) == Macro.to_string(rest_actual)
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule Temple.RendererTest do
|
|||
"hello world"
|
||||
end
|
||||
|
||||
assert_html "hello world\n", result
|
||||
assert_html "hello world", result
|
||||
end
|
||||
|
||||
test "produces renders a div" do
|
||||
|
@ -30,14 +30,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div class="hello world">
|
||||
hello world
|
||||
<span id="name">bob</span>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div class="hello world">hello world<span id="name">bob</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -54,15 +47,8 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div class="hello world">
|
||||
hello world
|
||||
<input type="button" value="Submit">
|
||||
<input type="button" value="Submit">
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div class="hello world">hello world<input type="button" value="Submit"><input type="button" value="Submit"></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -78,13 +64,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div class="hello world">
|
||||
<span id="name">bob</span>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div class="hello world"><span id="name">bob</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -100,12 +80,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div class="green">
|
||||
hello world
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div class="green">hello world</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -121,12 +96,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div class="green">
|
||||
hello world
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div class="green">hello world</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -142,12 +112,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
hello world
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div>hello world</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -165,15 +130,8 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<span class="name">alice</span>
|
||||
<span class="name">bob</span>
|
||||
<span class="name">carol</span>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div><span class="name">alice</span><span class="name">bob</span><span class="name">carol</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -194,13 +152,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<span>#{val}</span>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~s|<div><span>#{val}</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -227,13 +179,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<span>#{val}</span>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~s|<div><span>#{val}</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -243,13 +189,7 @@ defmodule Temple.RendererTest do
|
|||
assigns = %{name: "alice"}
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<span id="correct answer">alice is the best</span>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div><span id="correct answer">alice is the best</span></div>|
|
||||
|
||||
result =
|
||||
Renderer.compile do
|
||||
|
@ -283,18 +223,8 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<span class="name">alice</span>
|
||||
|
||||
<span class="name">bob</span>
|
||||
|
||||
<span class="name">carol</span>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div><span class="name">alice</span><span class="name">bob</span><span class="name">carol</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -320,18 +250,8 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<span class="name">alice</span>
|
||||
|
||||
<span class="name">bob</span>
|
||||
|
||||
<span class="name">carol</span>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div><span class="name">alice</span><span class="name">bob</span><span class="name">carol</span></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -345,16 +265,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<div>
|
||||
I am a basic component
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div><div>I am a basic component</div></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -372,18 +283,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div>
|
||||
<div>
|
||||
I am above the slot
|
||||
<span>i'm a slot</span>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div><div>I am above the slot<span>i'm a slot</span></div></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -407,26 +307,8 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# heex
|
||||
expected = """
|
||||
<div>
|
||||
<div>
|
||||
motchy boi is above the slot
|
||||
<span>i'm a slot</span>
|
||||
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<span>i'm a slot attribute</span>
|
||||
<p>
|
||||
motchy boi's in the footer!
|
||||
</p>
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div><div>motchy boi is above the slot<span>i'm a slot</span></div><footer><span>i'm a slot attribute</span><p>motchy boi's in the footer!</p></footer></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -442,12 +324,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<div class="text-red">
|
||||
hello world
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div class="text-red">hello world</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -459,9 +336,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<input type="text" disabled placeholder="Enter some text...">
|
||||
"""
|
||||
expected = ~S|<input type="text" disabled placeholder="Enter some text...">|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -473,9 +348,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<input type="text" placeholder="Enter some text...">
|
||||
"""
|
||||
expected = ~S|<input type="text" placeholder="Enter some text...">|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -490,9 +363,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# html
|
||||
expected = """
|
||||
<input type="text" checked placeholder="Enter some text...">
|
||||
"""
|
||||
expected = ~S|<input type="text" checked placeholder="Enter some text...">|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -522,30 +393,8 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# heex
|
||||
expected = """
|
||||
<div>
|
||||
<div>
|
||||
motchy boi is above the slot
|
||||
<span>i'm a slot</span>
|
||||
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<span></span>
|
||||
<p>
|
||||
motchy boi's in the footer!
|
||||
</p>
|
||||
<span></span>
|
||||
<p>
|
||||
motchy boi is the second footer!
|
||||
</p>
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div><div>motchy boi is above the slot<span>i'm a slot</span></div><footer><span></span><p>motchy boi's in the footer!</p><span></span><p>motchy boi is the second footer!</p></footer></div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -566,12 +415,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# heex
|
||||
expected = """
|
||||
<div id="foo" class="font-bold" disabled>
|
||||
hi
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div id="foo" class="font-bold" disabled>hi</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -589,12 +433,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# heex
|
||||
expected = """
|
||||
<div>
|
||||
I am a basic foo with font-bold
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div>I am a basic foo with font-bold</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
@ -619,13 +458,7 @@ defmodule Temple.RendererTest do
|
|||
end
|
||||
|
||||
# heex
|
||||
expected = """
|
||||
<div>
|
||||
id is passed-into-slot and class is font-bold
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected = ~S|<div>id is passed-into-slot and class is font-bold</div>|
|
||||
|
||||
assert_html expected, result
|
||||
end
|
||||
|
|
|
@ -14,20 +14,19 @@ defmodule TempleTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|> :erlang.iolist_to_binary()
|
||||
|> Phoenix.HTML.safe_to_string()
|
||||
|
||||
# heex
|
||||
expected = """
|
||||
<div class="hello" id="hi" name="mitch">
|
||||
<div class="hi" foo="bar">
|
||||
mitch
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
"""
|
||||
expected =
|
||||
~S|<div class="hello" id="hi" name="mitch"><div class="hi" foo="bar">mitch</div></div>|
|
||||
|
||||
assert expected == result
|
||||
end
|
||||
end
|
||||
|
||||
describe "attributes/1" do
|
||||
test "compiles runtime attributes" do
|
||||
assert ~s| disabled class="foo"| == attributes(disabled: true, checked: false, class: "foo")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue