Rename a dir and shrink the test matrix

This commit is contained in:
Mitchell Hanberg 2021-04-09 00:01:18 -04:00
parent acf53760c3
commit b35b9b6d91
16 changed files with 118 additions and 120 deletions

View file

@ -11,8 +11,8 @@ jobs:
strategy:
matrix:
otp: [21.x, 22.x, 23.x]
elixir: [1.7.x, 1.8.x, 1.9.x, 1.10.x, 1.11.x]
otp: [21.x]
elixir: [1.8.x, 1.11.x]
steps:
- uses: actions/checkout@v2
@ -42,8 +42,8 @@ jobs:
strategy:
matrix:
otp: [21.x, 22.x, 23.x]
elixir: [1.8.x, 1.9.x, 1.10.x, 1.11.x]
otp: [21.x]
elixir: [1.8.x, 1.11.x]
services:
db:

View file

@ -1,2 +1,2 @@
elixir 1.10.2
elixir 1.7.4
erlang 23.2.6

View file

@ -132,119 +132,4 @@ defmodule Temple.Parser do
|> List.wrap()
end
end
defmodule Private do
@moduledoc false
def snake_to_kebab(stringable),
do:
stringable |> to_string() |> String.replace_trailing("_", "") |> String.replace("_", "-")
def kebab_to_snake(stringable),
do: stringable |> to_string() |> String.replace("-", "_")
def compile_attrs([]), do: ""
def compile_attrs([attrs]) when is_list(attrs) do
compile_attrs(attrs)
end
def compile_attrs(attrs) when is_list(attrs) do
if Keyword.keyword?(attrs) do
for {name, value} <- attrs, into: "" do
name = snake_to_kebab(name)
case value do
{_, _, _} = macro ->
" " <> name <> "=\"<%= " <> Macro.to_string(macro) <> " %>\""
value ->
" " <> name <> "=\"" <> to_string(value) <> "\""
end
end
else
"<%= Temple.Parser.Private.runtime_attrs(" <>
(attrs |> List.first() |> Macro.to_string()) <> ") %>"
end
end
def runtime_attrs(attrs) do
{:safe,
for {name, value} <- attrs, into: "" do
name = snake_to_kebab(name)
" " <> name <> "=\"" <> to_string(value) <> "\""
end}
end
def split_args(not_what_i_want) when is_nil(not_what_i_want) or is_atom(not_what_i_want),
do: {[], []}
def split_args(args) do
{do_and_else, args} =
args
|> Enum.split_with(fn arg ->
if Keyword.keyword?(arg) do
arg
|> Keyword.drop([:do, :else])
|> Enum.empty?()
else
false
end
end)
{List.flatten(do_and_else), args}
end
def split_on_fn([{:fn, _, _} = func | rest], {args_before, _, args_after}) do
split_on_fn(rest, {args_before, func, args_after})
end
def split_on_fn([arg | rest], {args_before, nil, args_after}) do
split_on_fn(rest, {[arg | args_before], nil, args_after})
end
def split_on_fn([arg | rest], {args_before, func, args_after}) do
split_on_fn(rest, {args_before, func, [arg | args_after]})
end
def split_on_fn([], {args_before, func, args_after}) do
{Enum.reverse(args_before), func, Enum.reverse(args_after)}
end
def pop_compact?([]), do: {false, []}
def pop_compact?([args]) when is_list(args), do: pop_compact?(args)
def pop_compact?(args) do
Keyword.pop(args, :compact, false)
end
def traverse(buffer, {:__block__, _meta, block}) do
traverse(buffer, block)
end
def traverse(buffer, [first | rest]) do
traverse(buffer, first)
traverse(buffer, rest)
end
def traverse(buffer, original_macro) do
Temple.Parser.parsers()
|> Enum.reduce_while(original_macro, fn parser, macro ->
with true <- parser.applicable?(macro),
:ok <- parser.run(macro, buffer) do
{:halt, macro}
else
{:component_applied, adjusted_macro} ->
traverse(buffer, adjusted_macro)
{:halt, adjusted_macro}
false ->
{:cont, macro}
end
end)
end
end
end

View file

@ -0,0 +1,113 @@
defmodule Temple.Parser.Private do
@moduledoc false
def snake_to_kebab(stringable),
do: stringable |> to_string() |> String.replace_trailing("_", "") |> String.replace("_", "-")
def kebab_to_snake(stringable),
do: stringable |> to_string() |> String.replace("-", "_")
def compile_attrs([]), do: ""
def compile_attrs([attrs]) when is_list(attrs) do
compile_attrs(attrs)
end
def compile_attrs(attrs) when is_list(attrs) do
if Keyword.keyword?(attrs) do
for {name, value} <- attrs, into: "" do
name = snake_to_kebab(name)
case value do
{_, _, _} = macro ->
" " <> name <> "=\"<%= " <> Macro.to_string(macro) <> " %>\""
value ->
" " <> name <> "=\"" <> to_string(value) <> "\""
end
end
else
"<%= Temple.Parser.Private.runtime_attrs(" <>
(attrs |> List.first() |> Macro.to_string()) <> ") %>"
end
end
def runtime_attrs(attrs) do
{:safe,
for {name, value} <- attrs, into: "" do
name = snake_to_kebab(name)
" " <> name <> "=\"" <> to_string(value) <> "\""
end}
end
def split_args(not_what_i_want) when is_nil(not_what_i_want) or is_atom(not_what_i_want),
do: {[], []}
def split_args(args) do
{do_and_else, args} =
args
|> Enum.split_with(fn arg ->
if Keyword.keyword?(arg) do
arg
|> Keyword.drop([:do, :else])
|> Enum.empty?()
else
false
end
end)
{List.flatten(do_and_else), args}
end
def split_on_fn([{:fn, _, _} = func | rest], {args_before, _, args_after}) do
split_on_fn(rest, {args_before, func, args_after})
end
def split_on_fn([arg | rest], {args_before, nil, args_after}) do
split_on_fn(rest, {[arg | args_before], nil, args_after})
end
def split_on_fn([arg | rest], {args_before, func, args_after}) do
split_on_fn(rest, {args_before, func, [arg | args_after]})
end
def split_on_fn([], {args_before, func, args_after}) do
{Enum.reverse(args_before), func, Enum.reverse(args_after)}
end
def pop_compact?([]), do: {false, []}
def pop_compact?([args]) when is_list(args), do: pop_compact?(args)
def pop_compact?(args) do
Keyword.pop(args, :compact, false)
end
def traverse(buffer, {:__block__, _meta, block}) do
traverse(buffer, block)
end
def traverse(buffer, [first | rest]) do
traverse(buffer, first)
traverse(buffer, rest)
end
def traverse(buffer, original_macro) do
Temple.Parser.parsers()
|> Enum.reduce_while(original_macro, fn parser, macro ->
with true <- parser.applicable?(macro),
:ok <- parser.run(macro, buffer) do
{:halt, macro}
else
{:component_applied, adjusted_macro} ->
traverse(buffer, adjusted_macro)
{:halt, adjusted_macro}
false ->
{:cont, macro}
end
end)
end
end