Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Aug 25, 2023
1 parent f200fdf commit 7f193ea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
22 changes: 15 additions & 7 deletions lib/phoenix_live_view/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,21 @@ defmodule Phoenix.LiveView.Engine do
analyze_static_and_dynamic(static, dynamic, vars, assigns, caller)

static =
if anno = opts[:root_tag_annotation] do
case static do
[] -> [anno]
[first | rest] -> [anno <> first | rest]
end
else
static
case Keyword.fetch(opts, :root_tag_annotation) do
{:ok, {nil = _before, nil = _aft}} ->
static

{:ok, {before, aft}} ->
case static do
[] ->
["#{before}#{aft}"]

[first | rest] ->
List.update_at([to_string(before) <> first | rest], -1, &(&1 <> to_string(aft)))
end

:error ->
static
end

changed =
Expand Down
9 changes: 5 additions & 4 deletions lib/phoenix_live_view/html_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ defmodule Phoenix.LiveView.HTMLEngine do
if Application.get_env(:phoenix, :heex_debug_annotations, false) do
%Macro.Env{module: mod, function: {func, _}, file: file, line: line} = caller
line = if line == 0, do: 1, else: line
file = Path.relative_to_cwd(file)
begin = "<#{inspect(mod)}.#{func}> #{file}:#{line}"
"<!-- #{begin} -->"
# file = Path.relative_to_cwd(file)
before = "<#{inspect(mod)}.#{func}> #{file}:#{line}"
aft = "</#{inspect(mod)}.#{func}>"
{"<!-- #{before} -->", "<!-- #{aft} -->"}
else
nil
{nil, nil}
end
end
end
14 changes: 10 additions & 4 deletions lib/phoenix_live_view/tag_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ defmodule Phoenix.LiveView.TagEngine do
"""
@callback void?(name :: binary()) :: boolean()

@callback annotate_root_tag(Macro.Env.t()) :: binary() | nil
@callback annotate_root_tag(Macro.Env.t()) ::
{anno_before :: binary() | nil, anno_after :: binary() | nil}

@doc """
Renders a component defined by the given function.
Expand Down Expand Up @@ -185,10 +186,15 @@ defmodule Phoenix.LiveView.TagEngine do
|> handle_tokens(tokens)
|> validate_unclosed_tags!("template")

annotation =
state.has_tags? && state.caller && state.tag_handler.annotate_root_tag(state.caller)
opts = [root: token_state.root || false]

opts =
if state.has_tags? && state.caller do
Keyword.put(opts, :root_tag_annotation, state.tag_handler.annotate_root_tag(state.caller))
else
opts
end

opts = [root: token_state.root || false, root_tag_annotation: annotation]
ast = invoke_subengine(token_state, :handle_body, [opts])

quote do
Expand Down

0 comments on commit 7f193ea

Please sign in to comment.