diff --git a/lib/live_view_native/component.ex b/lib/live_view_native/component.ex index 2a55c24..160ef22 100644 --- a/lib/live_view_native/component.ex +++ b/lib/live_view_native/component.ex @@ -182,8 +182,6 @@ defmodule LiveViewNative.Component do raise "~LVN requires a variable named \"assigns\" to exist and be set to a map" end - debug_annotations? = Module.get_attribute(__CALLER__.module, :__debug_annotations__) - options = [ engine: Phoenix.LiveView.TagEngine, file: __CALLER__.file, @@ -191,8 +189,7 @@ defmodule LiveViewNative.Component do caller: __CALLER__, indentation: meta[:indentation] || 0, source: expr, - tag_handler: LiveViewNative.TagEngine, - annotate_tagged_content: debug_annotations? && (&LiveViewNative.Engine.annotate_tagged_content/1) + tag_handler: LiveViewNative.TagEngine ] EEx.compile_string(expr, options) diff --git a/lib/live_view_native/engine.ex b/lib/live_view_native/engine.ex index a8835f6..9cdd661 100644 --- a/lib/live_view_native/engine.ex +++ b/lib/live_view_native/engine.ex @@ -19,7 +19,6 @@ defmodule LiveViewNative.Engine do @doc false defmacro compile(path) do trim = Application.get_env(:phoenix, :trim_on_html_eex_engine, true) - debug_annotations? = Module.get_attribute(__CALLER__.module, :__debug_annotations__) source = File.read!(path) EEx.compile_string(source, @@ -29,8 +28,7 @@ defmodule LiveViewNative.Engine do trim: trim, caller: __CALLER__, source: source, - tag_handler: LiveViewNative.TagEngine, - annotate_tagged_content: debug_annotations? && (&annotate_tagged_content/1) + tag_handler: LiveViewNative.TagEngine ) end @@ -42,15 +40,4 @@ defmodule LiveViewNative.Engine do def encode_to_iodata!(bin) when is_binary(bin), do: Phoenix.HTML.Engine.html_escape(bin) def encode_to_iodata!(list) when is_list(list), do: LiveViewNative.Template.Safe.List.to_iodata(list) def encode_to_iodata!(other), do: LiveViewNative.Template.Safe.to_iodata(other) - - @doc false - def annotate_tagged_content(%Macro.Env{} = caller) 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) - - before = "<#{inspect(mod)}.#{func}> #{file}:#{line}" - aft = "" - {"", ""} - end end diff --git a/lib/live_view_native/tag_engine.ex b/lib/live_view_native/tag_engine.ex index d329c47..6192e79 100644 --- a/lib/live_view_native/tag_engine.ex +++ b/lib/live_view_native/tag_engine.ex @@ -24,6 +24,32 @@ defmodule LiveViewNative.TagEngine do end end + @doc false + @impl true + def annotate_body(%Macro.Env{} = caller) do + if Application.get_env(:phoenix_live_view, :debug_heex_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) + app = Application.get_env(:logger, :compile_time_application) + + before = "<#{inspect(mod)}.#{func}> #{file}:#{line}" + aft = "" + {"", ""} + end + end + + @impl true + def annotate_caller(file, line) do + if Application.get_env(:phoenix_live_view, :debug_heex_annotations, false) do + line = if line == 0, do: 1, else: line + file = Path.relative_to_cwd(file) + app = Application.get_env(:logger, :compile_time_application) + + "" + end + end + @doc false @impl true def classify_type(":inner_block"), do: {:error, "the slot name :inner_block is reserved"} diff --git a/mix.exs b/mix.exs index babcc52..a38e851 100644 --- a/mix.exs +++ b/mix.exs @@ -31,7 +31,7 @@ defmodule LiveViewNative.MixProject do [ {:phoenix, "~> 1.7.0"}, {:phoenix_view, "~> 2.0"}, - {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", ref: "4939fb8", override: true}, + {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", branch: "main", override: true}, {:phoenix_live_reload, "~> 1.4", only: :test}, {:phoenix_template, "~> 1.0.4"}, {:phoenix_html, "~> 3.3 or ~> 4.0 or ~> 4.1"}, diff --git a/mix.lock b/mix.lock index 7b9d7c6..06b28b0 100644 --- a/mix.lock +++ b/mix.lock @@ -21,7 +21,7 @@ "phoenix": {:hex, :phoenix, "1.7.11", "1d88fc6b05ab0c735b250932c4e6e33bfa1c186f76dcf623d8dd52f07d6379c7", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "b1ec57f2e40316b306708fe59b92a16b9f6f4bf50ccfa41aa8c7feb79e0ec02a"}, "phoenix_html": {:hex, :phoenix_html, "4.0.0", "4857ec2edaccd0934a923c2b0ba526c44a173c86b847e8db725172e9e51d11d6", [:mix], [], "hexpm", "cee794a052f243291d92fa3ccabcb4c29bb8d236f655fb03bcbdc3a8214b8d13"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.4.1", "2aff698f5e47369decde4357ba91fc9c37c6487a512b41732818f2204a8ef1d3", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "9bffb834e7ddf08467fe54ae58b5785507aaba6255568ae22b4d46e2bb3615ab"}, - "phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "4939fb878363fe353ec9a68e28b6256c32e696b2", [ref: "4939fb8"]}, + "phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "251f0a413568a540d0c9b3405b96a59b453547d9", [branch: "main"]}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "phoenix_view": {:hex, :phoenix_view, "2.0.3", "4d32c4817fce933693741deeb99ef1392619f942633dde834a5163124813aad3", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "cd34049af41be2c627df99cd4eaa71fc52a328c0c3d8e7d4aa28f880c30e7f64"},