diff --git a/lib/live_view_native/extensions.ex b/lib/live_view_native/extensions.ex
index c21455c3..af885371 100644
--- a/lib/live_view_native/extensions.ex
+++ b/lib/live_view_native/extensions.ex
@@ -9,9 +9,11 @@ defmodule LiveViewNative.Extensions do
respectively.
"""
defmacro __using__(opts) do
+ compiled_at = :os.system_time(:nanosecond)
role = opts[:role]
- quote bind_quoted: [caller: Macro.escape(__CALLER__), role: role], location: :keep do
+ quote bind_quoted: [caller: Macro.escape(__CALLER__), compiled_at: compiled_at, role: role],
+ location: :keep do
Code.put_compiler_option(:ignore_module_conflict, true)
for {platform_id, platform_context} <- LiveViewNative.platforms() do
@@ -43,10 +45,12 @@ defmodule LiveViewNative.Extensions do
if is_nil(platform_context.render_macro) do
use LiveViewNative.Extensions.InlineRender,
+ compiled_at: compiled_at,
platform_id: platform_id,
role: role
else
use LiveViewNative.Extensions.RenderMacro,
+ compiled_at: compiled_at,
platform_id: platform_id,
render_macro: platform_context.render_macro,
role: role
diff --git a/lib/live_view_native/extensions/inline_render.ex b/lib/live_view_native/extensions/inline_render.ex
index 73ae14d2..07524bfb 100644
--- a/lib/live_view_native/extensions/inline_render.ex
+++ b/lib/live_view_native/extensions/inline_render.ex
@@ -31,10 +31,12 @@ defmodule LiveViewNative.Extensions.InlineRender do
"""
defmacro __using__(opts \\ []) do
quote bind_quoted: [
+ compiled_at: opts[:compiled_at],
platform_id: opts[:platform_id],
stylesheet: opts[:stylesheet],
role: opts[:role]
- ], location: :keep do
+ ],
+ location: :keep do
require EEx
defmacro sigil_LVN({:<<>>, meta, [expr]}, modifiers) do
@@ -47,6 +49,7 @@ defmodule LiveViewNative.Extensions.InlineRender do
platform_module <- Module.concat(__ENV__.module, context.template_namespace) do
base_opts = [
caller: __CALLER__,
+ compiled_at: unquote(compiled_at),
engine: Phoenix.LiveView.TagEngine,
file: __CALLER__.file,
indentation: meta[:indentation] || 0,
diff --git a/lib/live_view_native/extensions/modifiers.ex b/lib/live_view_native/extensions/modifiers.ex
index c40d4397..dd0a1f14 100644
--- a/lib/live_view_native/extensions/modifiers.ex
+++ b/lib/live_view_native/extensions/modifiers.ex
@@ -100,7 +100,8 @@ defmodule LiveViewNative.Extensions.Modifiers do
modifiers_struct: opts[:modifiers_struct],
platform_modifiers: opts[:platform_modifiers],
platform_module: opts[:platform_module]
- ], location: :keep do
+ ],
+ location: :keep do
all_modifiers = Keyword.merge(platform_modifiers, custom_modifiers)
if is_nil(platform_module) do
diff --git a/lib/live_view_native/extensions/render_macro.ex b/lib/live_view_native/extensions/render_macro.ex
index 14a03a97..7e6c7192 100644
--- a/lib/live_view_native/extensions/render_macro.ex
+++ b/lib/live_view_native/extensions/render_macro.ex
@@ -9,10 +9,12 @@ defmodule LiveViewNative.Extensions.RenderMacro do
"""
defmacro __using__(opts \\ []) do
quote bind_quoted: [
+ compiled_at: opts[:compiled_at],
render_macro: opts[:render_macro],
platform_id: opts[:platform_id],
role: opts[:role]
- ], location: :keep do
+ ],
+ location: :keep do
defmacro unquote(:"#{render_macro}")({:<<>>, meta, [expr]}, _modifiers) do
unless Macro.Env.has_var?(__CALLER__, {:assigns, nil}) do
raise "#{unquote(render_macro)} requires a variable named \"assigns\" to exist and be set to a map"
@@ -22,6 +24,7 @@ defmodule LiveViewNative.Extensions.RenderMacro do
%LiveViewNativePlatform.Env{} = context <- Map.get(platforms, unquote(platform_id)),
platform_module <- Module.concat(__ENV__.module, context.template_namespace) do
base_opts = [
+ compiled_at: unquote(compiled_at),
caller: __CALLER__,
engine: Phoenix.LiveView.TagEngine,
file: __CALLER__.file,
diff --git a/lib/live_view_native/extensions/stylesheets.ex b/lib/live_view_native/extensions/stylesheets.ex
index 3957b703..f4915780 100644
--- a/lib/live_view_native/extensions/stylesheets.ex
+++ b/lib/live_view_native/extensions/stylesheets.ex
@@ -11,22 +11,12 @@ defmodule LiveViewNative.Extensions.Stylesheets do
quote bind_quoted: [module: module], location: :keep do
def __compiled_stylesheet__(stylesheet_key) do
- class_tree_module =
- Module.safe_concat([LiveViewNative, Internal, ClassTree, unquote(module)])
+ stylesheet_modules = __stylesheet_modules__()
- class_tree = apply(class_tree_module, :class_tree, [stylesheet_key])
-
- class_names =
- class_tree
- |> Map.values()
- |> List.flatten()
-
- __stylesheet_modules__()
- |> Enum.reduce(%{}, fn stylesheet_module, acc ->
- compiled_stylesheet = apply(stylesheet_module, :compile_ast, [class_names])
-
- Map.merge(acc, compiled_stylesheet)
- end)
+ unquote(module)
+ |> LiveViewNative.Stylesheets.get_class_tree_module()
+ |> LiveViewNative.Stylesheets.get_class_tree(stylesheet_key)
+ |> LiveViewNative.Stylesheets.reduce_stylesheets(stylesheet_modules)
|> inspect(limit: :infinity, charlists: :as_list, printable_limit: :infinity)
end
diff --git a/lib/live_view_native/extensions/templates.ex b/lib/live_view_native/extensions/templates.ex
index 983513f1..260e05ac 100644
--- a/lib/live_view_native/extensions/templates.ex
+++ b/lib/live_view_native/extensions/templates.ex
@@ -24,7 +24,8 @@ defmodule LiveViewNative.Extensions.Templates do
template_basename: opts[:template_basename],
template_directory: opts[:template_directory],
template_extension: opts[:template_extension]
- ], location: :keep do
+ ],
+ location: :keep do
template_path = Path.join(template_directory, template_basename) <> template_extension
if is_binary(template_path) and File.exists?(template_path) do
diff --git a/lib/live_view_native/layouts.ex b/lib/live_view_native/layouts.ex
index d03b041a..59b8abcd 100644
--- a/lib/live_view_native/layouts.ex
+++ b/lib/live_view_native/layouts.ex
@@ -6,7 +6,7 @@ defmodule LiveViewNative.Layouts do
|> extract_layouts_recursive(opts)
|> List.flatten()
|> Enum.map(fn layout_params -> {layout_params.render_function, layout_params} end)
- |> Enum.reject(&(format_excluded?(&1, opts)))
+ |> Enum.reject(&format_excluded?(&1, opts))
|> Enum.into(%{})
|> apply_default_layouts(opts)
|> generate_class_trees(opts)
@@ -26,7 +26,8 @@ defmodule LiveViewNative.Layouts do
def extract_layouts_recursive({_func, _meta, [_ | _] = nodes}, %{} = opts),
do: Enum.map(nodes, &extract_layouts_recursive(&1, opts))
- def extract_layouts_recursive([do: {:__block__, [], args}], %{} = opts), do: extract_layouts_recursive(args, opts)
+ def extract_layouts_recursive([do: {:__block__, [], args}], %{} = opts),
+ do: extract_layouts_recursive(args, opts)
def extract_layouts_recursive([_ | _] = nodes, %{} = opts),
do: Enum.map(nodes, &extract_layouts_recursive(&1, opts))
@@ -49,9 +50,11 @@ defmodule LiveViewNative.Layouts do
|> String.replace(".", "_")
|> String.to_atom()
+ is_root_template? = "#{func_name}" == "root_#{platform.platform_id}"
+
%{
class_tree: %{},
- template: File.read!(template_path),
+ template: layout_template(template_path, is_root_template?),
eex_engine: platform.eex_engine,
platform_id: platform.platform_id,
render_function: func_name,
@@ -62,6 +65,31 @@ defmodule LiveViewNative.Layouts do
def compile_layout(_platform, _template_path, _opts), do: nil
+ def layout_template(template_path, is_root_template?) do
+ template_path
+ |> File.read!()
+ |> layout_template_with_live_reload(Mix.env())
+ |> layout_template_with_csrf_token(is_root_template?)
+ end
+
+ def layout_template_with_live_reload(template, :dev) do
+ """
+ #{template}
+
+ """
+ end
+
+ def layout_template_with_live_reload(template, _mix_env), do: template
+
+ def layout_template_with_csrf_token(template, true) do
+ """
+ #{template}
+
+ """
+ end
+
+ def layout_template_with_csrf_token(template, _is_root_template?), do: template
+
def matches_template?({_key, %{} = platform}, filename) do
case platform.template_extension do
nil ->
@@ -73,12 +101,15 @@ defmodule LiveViewNative.Layouts do
end
def generate_class_trees(%{} = layouts, %{} = opts) do
- Enum.reduce(layouts, layouts, fn {func_name, %{template: template, platform_id: platform_id} = layout}, acc ->
+ Enum.reduce(layouts, layouts, fn {func_name,
+ %{template: template, platform_id: platform_id} = layout},
+ acc ->
opts = Map.put(opts, :render_function, {layout.render_function, 1})
case LiveViewNative.Templates.compile_class_tree(template, platform_id, opts) do
{:ok, %{} = class_tree} ->
- Map.put(acc, func_name, %{layout | class_tree: class_tree})
+ updated_layout = Map.put(layout, :class_tree, class_tree)
+ Map.put(acc, func_name, updated_layout)
_ ->
acc
@@ -88,8 +119,8 @@ defmodule LiveViewNative.Layouts do
def persist_class_trees(%{} = layouts, opts) do
layouts
- |> Enum.map(fn {func_name, %{class_tree: class_tree}} -> {func_name, class_tree} end)
- |> LiveViewNative.Templates.persist_class_tree_map(opts.caller.module)
+ |> Enum.map(&extract_class_tree/1)
+ |> LiveViewNative.Templates.persist_class_tree_map(opts.caller)
layouts
end
@@ -98,7 +129,7 @@ defmodule LiveViewNative.Layouts do
defp apply_default_layouts(%{} = layouts, %{default_layouts: true, platforms: platforms} = opts) do
platforms
- |> Enum.reject(&(format_excluded?(&1, opts)))
+ |> Enum.reject(&format_excluded?(&1, opts))
|> Enum.flat_map(fn {format, %{default_layouts: %{} = default_layouts} = platform} ->
Enum.map(default_layouts, fn {layout_name, layout_source} ->
{String.to_atom("#{layout_name}_#{format}"), {layout_source, platform}}
@@ -123,6 +154,16 @@ defmodule LiveViewNative.Layouts do
defp apply_default_layouts(%{} = layouts, _opts), do: layouts
+ defp extract_class_tree({func_name, layout}) do
+ case layout do
+ %{class_tree: class_tree} ->
+ {func_name, class_tree}
+
+ _ ->
+ {func_name, %{}}
+ end
+ end
+
defp format_excluded?({_, %{platform_id: platform_id}}, %{} = opts) do
case opts do
%{exclude: [_ | _] = excluded_formats} ->
@@ -134,7 +175,10 @@ defmodule LiveViewNative.Layouts do
end
defmacro __using__(_opts \\ []) do
- quote bind_quoted: [caller: Macro.escape(__CALLER__)], location: :keep do
+ compiled_at = :os.system_time(:nanosecond)
+
+ quote bind_quoted: [caller: Macro.escape(__CALLER__), compiled_at: compiled_at],
+ location: :keep do
use LiveViewNative.Extensions, role: :layouts
layout_templates =
@@ -154,6 +198,7 @@ defmodule LiveViewNative.Layouts do
eex_opts = [
caller: caller,
+ compiled_at: compiled_at,
engine: layout_params.eex_engine,
file: __ENV__.file,
render_function: {render_func, 1},
@@ -161,8 +206,15 @@ defmodule LiveViewNative.Layouts do
persist_class_tree: false,
tag_handler: layout_params.tag_handler
]
- LiveViewNative.Templates.compile_class_tree(layout_params.template, layout_params.platform_id, eex_opts)
- expr = LiveViewNative.Templates.with_stylesheet_wrapper(layout_params.template, render_func)
+
+ LiveViewNative.Templates.compile_class_tree(
+ layout_params.template,
+ layout_params.platform_id,
+ eex_opts
+ )
+
+ expr =
+ LiveViewNative.Templates.with_stylesheet_wrapper(layout_params.template, render_func)
EEx.function_from_string(:def, render_func, expr, [:assigns], eex_opts)
end)
diff --git a/lib/live_view_native/live_session.ex b/lib/live_view_native/live_session.ex
index fd09ef3b..77de613f 100644
--- a/lib/live_view_native/live_session.ex
+++ b/lib/live_view_native/live_session.ex
@@ -13,6 +13,7 @@ defmodule LiveViewNative.LiveSession do
case get_native_assigns(socket, params) do
%Assigns{} = native_assigns ->
assigns = Map.from_struct(native_assigns)
+
socket =
socket
|> assign(assigns)
@@ -79,10 +80,13 @@ defmodule LiveViewNative.LiveSession do
defp put_target(assigns, _lvn_params), do: assigns
defp put_native_layout(%Socket{} = socket) do
- with %Socket{assigns: %{format: format}, private: private, view: view} when not is_nil(view) <- socket,
- %{layout: {layout_mod, layout_name}} <- apply(view, :__live__, [])
- do
- %Socket{socket | private: Map.put(private, :live_layout, {layout_mod, "#{layout_name}_#{format}"})}
+ with %Socket{assigns: %{format: format}, private: private, view: view} when not is_nil(view) <-
+ socket,
+ %{layout: {layout_mod, layout_name}} <- apply(view, :__live__, []) do
+ %Socket{
+ socket
+ | private: Map.put(private, :live_layout, {layout_mod, "#{layout_name}_#{format}"})
+ }
else
_ ->
socket
diff --git a/lib/live_view_native/session_plug.ex b/lib/live_view_native/session_plug.ex
index b25b9976..ec411eb7 100644
--- a/lib/live_view_native/session_plug.ex
+++ b/lib/live_view_native/session_plug.ex
@@ -1,14 +1,16 @@
defmodule LiveViewNative.SessionPlug do
def init(default), do: default
- def call(%Plug.Conn{
- params: %{"_lvn" => %{"format" => lvn_platform}},
- private:
- %{
- :phoenix_format => "html",
- :phoenix_root_layout => %{"html" => {root_layout_mod, root_layout_func}}
- }
- } = conn, _default) do
+ def call(
+ %Plug.Conn{
+ params: %{"_lvn" => %{"format" => lvn_platform}},
+ private: %{
+ :phoenix_format => "html",
+ :phoenix_root_layout => %{"html" => {root_layout_mod, root_layout_func}}
+ }
+ } = conn,
+ _default
+ ) do
root_layout_func = String.to_existing_atom("#{root_layout_func}_#{lvn_platform}")
root_layout = {root_layout_mod, root_layout_func}
@@ -18,4 +20,4 @@ defmodule LiveViewNative.SessionPlug do
end
def call(conn, _default), do: conn
-end
\ No newline at end of file
+end
diff --git a/lib/live_view_native/stylesheets.ex b/lib/live_view_native/stylesheets.ex
new file mode 100644
index 00000000..82acbaad
--- /dev/null
+++ b/lib/live_view_native/stylesheets.ex
@@ -0,0 +1,74 @@
+defmodule LiveViewNative.Stylesheets do
+ @moduledoc """
+ Provides runtime support for LiveView Native's stylesheet system.
+ """
+
+ @doc """
+ Returns a map containing all class names for templates within the given
+ LiveView, LiveComponent or Phoenix Components module. `tree_key` can be
+ passed for retrieving a specific class tree; this should only used for
+ modules which have multiple tree shaking passes applied at compile-time
+ (for example, layout modules), otherwise `:default` should be passed.
+ """
+ def get_class_tree(class_tree_module, tree_key \\ :default, opts \\ []) do
+ expand = Keyword.get(opts, :expand, true)
+
+ case apply(class_tree_module, :class_tree, [tree_key]) do
+ result when expand ->
+ expand_class_tree(result)
+
+ result ->
+ result
+ end
+ end
+
+ @doc """
+ Returns the internal class tree module for the given LiveView, LiveComponent
+ or Phoenix Components module.
+ """
+ def get_class_tree_module(module) do
+ Module.safe_concat([LiveViewNative, Internal, ClassTree, module])
+ end
+
+ @doc """
+ Compiles all stylesheets for the given class tree and returns them
+ as a single map.
+ """
+ def reduce_stylesheets(%{contents: %{class_names: class_names}}, stylesheet_modules) do
+ stylesheet_modules
+ |> Enum.reduce(%{}, fn stylesheet_module, acc ->
+ compiled_stylesheet = apply(stylesheet_module, :compile_ast, [class_names])
+
+ Map.merge(acc, compiled_stylesheet)
+ end)
+ end
+
+ ###
+
+ defp expand_class_tree(%{branches: branches} = class_tree) do
+ branches
+ |> Enum.reject(&(&1 in class_tree.expanded_branches))
+ |> Enum.reduce(class_tree, fn branch, %{contents: %{} = acc_contents} = acc ->
+ branch_class_tree =
+ branch
+ |> get_class_tree(:default)
+ |> expand_class_tree()
+
+ acc_class_names = acc_contents.class_names ++ branch_class_tree.contents.class_names
+
+ acc_class_mappings =
+ Map.merge(acc_contents.class_mappings, branch_class_tree.contents.class_mappings)
+
+ %{
+ acc
+ | branches: acc.branches,
+ contents: %{
+ acc_contents
+ | class_names: acc_class_names,
+ class_mappings: acc_class_mappings
+ },
+ expanded_branches: class_tree.expanded_branches ++ [branch]
+ }
+ end)
+ end
+end
diff --git a/lib/live_view_native/templates.ex b/lib/live_view_native/templates.ex
index 00ea2ee9..9e116577 100644
--- a/lib/live_view_native/templates.ex
+++ b/lib/live_view_native/templates.ex
@@ -17,14 +17,14 @@ defmodule LiveViewNative.Templates do
end
def compile_class_tree(expr, platform_id, eex_opts) do
- %Macro.Env{module: template_module} = eex_opts[:caller]
+ caller = eex_opts[:caller]
+ %Macro.Env{module: template_module} = caller
with %Meeseeks.Document{} = doc <- Meeseeks.parse(expr, :html),
- [_ | _] = class_names <- extract_all_class_names(doc),
- %{} = class_tree_context <- class_tree_context(platform_id, template_module),
- %{} = class_tree <- build_class_tree(class_tree_context, class_names, eex_opts)
- do
- if eex_opts[:persist_class_tree], do: persist_class_tree_map(%{default: class_tree}, template_module)
+ class_names <- extract_all_class_names(doc),
+ %{} = class_tree_context <- class_tree_context(platform_id, template_module, eex_opts),
+ %{} = class_tree <- build_class_tree(class_tree_context, class_names, eex_opts) do
+ if eex_opts[:persist_class_tree], do: persist_class_tree_map(%{default: class_tree}, caller)
{:ok, class_tree}
else
@@ -33,34 +33,62 @@ defmodule LiveViewNative.Templates do
end
end
- def persist_class_tree_map(class_tree_map, template_module) do
- dump_class_tree_bytecode(class_tree_map, template_module)
+ def persist_class_tree_map(class_tree_map, caller) do
+ dump_class_tree_bytecode(class_tree_map, caller)
end
def with_stylesheet_wrapper(expr, stylesheet_key \\ :default) do
- "\n" <> expr <> "\n"
+ "#{expr}"
end
###
defp build_class_tree(%{} = class_tree_context, class_names, eex_opts) do
{func_name, func_arity} = eex_opts[:render_function] || eex_opts[:caller].function
+ function_tag = "#{func_name}/#{func_arity}"
+ incremental_class_names = Map.get(class_tree_context, :class_names, [])
+ incremental_mappings = Map.get(class_tree_context, :class_mappings, %{})
+ class_names_for_function = Map.get(incremental_mappings, function_tag, []) ++ class_names
+ class_mappings = Enum.uniq(class_names_for_function)
+
+ class_names =
+ class_mappings
+ |> Enum.concat(incremental_class_names)
+ |> Enum.uniq()
class_tree_context
- |> put_in([:class_tree, "#{func_name}/#{func_arity}"], Enum.uniq(class_names))
+ |> Map.put(:class_names, class_names)
+ |> put_in([:class_mappings, function_tag], class_mappings)
|> persist_to_class_tree()
end
- defp class_tree_context(platform_id, template_module) do
+ defp class_tree_context(platform_id, template_module, eex_opts) do
+ compiled_at = eex_opts[:compiled_at]
filename = class_tree_filename(platform_id, template_module)
with {:ok, body} <- File.read(filename),
- {:ok, %{} = class_tree} <- Jason.decode(body)
- do
- %{class_tree: class_tree, meta: %{filename: filename}}
+ {:ok, %{} = class_tree} <- Jason.decode(body) do
+ class_mappings = class_tree["class_mappings"] || %{}
+ class_names = Map.values(class_mappings)
+
+ %{
+ class_mappings: class_mappings,
+ class_names: List.flatten(class_names),
+ meta: %{
+ compiled_at: compiled_at,
+ filename: get_in(class_tree, ["meta", "filename"]) || filename
+ }
+ }
else
_ ->
- %{class_tree: %{}, meta: %{filename: filename}}
+ %{
+ class_mappings: %{},
+ class_names: [],
+ meta: %{
+ compiled_at: compiled_at,
+ filename: filename
+ }
+ }
end
end
@@ -68,26 +96,49 @@ defmodule LiveViewNative.Templates do
"#{:code.lib_dir(:live_view_native)}/.lvn/#{platform_id}/#{template_module}.classtree.json"
end
- defp dump_class_tree_bytecode(class_tree_map, template_module) do
+ defp dump_class_tree_bytecode(class_tree_map, caller) do
class_tree_map
- |> generate_class_tree_module(template_module)
+ |> generate_class_tree_module(caller)
|> Code.compile_string()
:ok
end
- defp generate_class_tree_module(class_tree_map, template_module) do
- module_name = Module.concat([LiveViewNative, Internal, ClassTree, template_module])
+ defp generate_class_tree_module(class_tree_map, caller) do
+ %Macro.Env{module: template_module, requires: requires} = caller
+ module_name = generate_class_tree_module_name(template_module)
+ branches = get_class_tree_branches(requires)
Macro.to_string(
quote location: :keep do
defmodule unquote(module_name) do
- def class_tree(stylesheet_key), do: unquote(class_tree_map)[stylesheet_key] || %{}
+ def class_tree(stylesheet_key),
+ do:
+ %{
+ branches: unquote(branches),
+ contents: unquote(class_tree_map)[stylesheet_key],
+ expanded_branches: [unquote(module_name)]
+ } ||
+ %{
+ branches: [],
+ contents: %{},
+ expanded_branches: [unquote(module_name)]
+ }
end
end
)
end
+ defp generate_class_tree_module_name(module) do
+ Module.concat([LiveViewNative, Internal, ClassTree, module])
+ end
+
+ defp get_class_tree_branches(requires) do
+ requires
+ |> Enum.filter(&module_has_stylesheet?/1)
+ |> Enum.map(&generate_class_tree_module_name/1)
+ end
+
defp extract_all_class_names(doc) do
Enum.flat_map(doc.nodes, &extract_class_names/1)
end
@@ -106,7 +157,13 @@ defmodule LiveViewNative.Templates do
end
end
- defp persist_to_class_tree(%{class_tree: %{} = class_tree, meta: %{filename: filename}}) do
+ defp module_has_stylesheet?(module) do
+ :functions
+ |> module.__info__()
+ |> Enum.member?({:__compiled_stylesheet__, 1})
+ end
+
+ defp persist_to_class_tree(%{meta: %{filename: filename}} = class_tree) do
with {:ok, encoded_tree} <- Jason.encode(class_tree),
dirname <- Path.dirname(filename),
:ok <- File.mkdir_p(dirname),
diff --git a/mix.lock b/mix.lock
index daf718dd..5a29cd50 100644
--- a/mix.lock
+++ b/mix.lock
@@ -6,7 +6,7 @@
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"},
"earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"},
- "ecto": {:hex, :ecto, "3.11.0", "ff8614b4e70a774f9d39af809c426def80852048440e8785d93a6e91f48fec00", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7769dad267ef967310d6e988e92d772659b11b09a0c015f101ce0fff81ce1f81"},
+ "ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.30.6", "5f8b54854b240a2b55c9734c4b1d0dd7bdd41f71a095d42a70445c03cf05a281", [: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", "bd48f2ddacf4e482c727f9293d9498e0881597eae6ddc3d9562bd7923375109f"},
"floki": {:hex, :floki, "0.34.3", "5e2dcaec5d7c228ce5b1d3501502e308b2d79eb655e4191751a1fe491c37feac", [:mix], [], "hexpm", "9577440eea5b97924b4bf3c7ea55f7b8b6dce589f9b28b096cc294a8dc342341"},
diff --git a/test/live_view_native/components_test.exs b/test/live_view_native/components_test.exs
index 72502643..3fd134a2 100644
--- a/test/live_view_native/components_test.exs
+++ b/test/live_view_native/components_test.exs
@@ -10,12 +10,12 @@ defmodule LiveViewNative.ComponentsTest do
test_context = LiveViewNativePlatform.Kit.compile(%LiveViewNative.TestPlatform{})
web_result =
- render_component(&TestComponents.test_component/1, platform_id: :web, native: web_context)
+ render_component(&TestComponents.test_component/1, format: :web, native: web_context)
|> Meeseeks.parse(:html)
test_result =
render_component(&TestComponents.test_component/1,
- platform_id: :lvntest,
+ format: :lvntest,
native: test_context
)
|> Meeseeks.parse(:xml)
diff --git a/test/live_view_native/live_view_test.exs b/test/live_view_native/live_view_test.exs
index 15db9f1f..d85c7954 100644
--- a/test/live_view_native/live_view_test.exs
+++ b/test/live_view_native/live_view_test.exs
@@ -13,8 +13,8 @@ defmodule LiveViewNative.LiveViewTest do
test "calling render_native/1 renders the correct platform for `assigns`" do
web_context = LiveViewNativePlatform.Kit.compile(%LiveViewNative.Platforms.Web{})
test_context = LiveViewNativePlatform.Kit.compile(%LiveViewNative.TestPlatform{})
- web_result = TestLiveView.render(%{platform_id: :html, native: web_context})
- test_result = TestLiveView.render(%{platform_id: :lvntest, native: test_context})
+ web_result = TestLiveView.render(%{format: :html, native: web_context})
+ test_result = TestLiveView.render(%{format: :lvntest, native: test_context})
assert web_result.static == [
"
\n This is an HTML template\n \n
"
@@ -28,11 +28,14 @@ defmodule LiveViewNative.LiveViewTest do
test "calling render/1 renders platform-specific templates inline" do
web_context = LiveViewNativePlatform.Kit.compile(%LiveViewNative.Platforms.Web{})
test_context = LiveViewNativePlatform.Kit.compile(%LiveViewNative.TestPlatform{})
- web_result = TestLiveViewInline.render(%{platform_id: :html, native: web_context})
- test_result = TestLiveViewInline.render(%{platform_id: :lvntest, native: test_context})
+ web_result = TestLiveViewInline.render(%{format: :html, native: web_context})
+ test_result = TestLiveViewInline.render(%{format: :lvntest, native: test_context})
assert web_result.static == ["Hello from the web
"]
- assert test_result.static == ["\nHello from the test platform\n\n"]
+ assert test_result.static == [
+ "Hello from the test platform\n"
+ ]
end
end
diff --git a/test/support/test_components.ex b/test/support/test_components.ex
index 190a81e0..65ade8a8 100644
--- a/test/support/test_components.ex
+++ b/test/support/test_components.ex
@@ -2,18 +2,18 @@ defmodule LiveViewNative.TestComponents do
use Phoenix.Component
use LiveViewNative.Component
- attr :platform_id, :atom
+ attr :format, :atom
- def test_component(%{platform_id: :lvntest} = assigns) do
+ def test_component(%{format: :lvntest} = assigns) do
~LVN"""
- <.local_component_example platform_id={:lvntest} />
-
- <.imported_component_example platform_id={:lvntest} />
- <.component_with_inner_block_example platform_id={:lvntest}>
+ <.local_component_example format={:lvntest} />
+
+ <.imported_component_example format={:lvntest} />
+ <.component_with_inner_block_example format={:lvntest}>
Inner Block Rendered
- <.component_with_slot_example platform_id={:lvntest}>
+ <.component_with_slot_example format={:lvntest}>
<:item>
Slot Rendered
@@ -28,34 +28,34 @@ defmodule LiveViewNative.TestComponents do
"""
end
- attr :platform_id, :atom
+ attr :format, :atom
- def local_component_example(%{platform_id: :lvntest} = assigns) do
+ def local_component_example(%{format: :lvntest} = assigns) do
~LVN"""
Local Component Rendered
"""lvntest
end
- attr :platform_id, :atom
+ attr :format, :atom
- def remote_component_example(%{platform_id: :lvntest} = assigns) do
+ def remote_component_example(%{format: :lvntest} = assigns) do
~LVN"""
Remote Component Rendered
"""lvntest
end
- attr :platform_id, :atom
+ attr :format, :atom
- def imported_component_example(%{platform_id: :lvntest} = assigns) do
+ def imported_component_example(%{format: :lvntest} = assigns) do
~LVN"""
Imported Component Rendered
"""lvntest
end
- attr :platform_id, :atom
+ attr :format, :atom
slot :inner_block
- def component_with_inner_block_example(%{platform_id: :lvntest} = assigns) do
+ def component_with_inner_block_example(%{format: :lvntest} = assigns) do
~LVN"""
Component With Inner Block Rendered
@@ -64,10 +64,10 @@ defmodule LiveViewNative.TestComponents do
"""lvntest
end
- attr :platform_id, :atom
+ attr :format, :atom
slot :item
- def component_with_slot_example(%{platform_id: :lvntest} = assigns) do
+ def component_with_slot_example(%{format: :lvntest} = assigns) do
~LVN"""
Component With Slot Rendered
diff --git a/test/support/test_live_view_inline.ex b/test/support/test_live_view_inline.ex
index 33510653..5908a22e 100644
--- a/test/support/test_live_view_inline.ex
+++ b/test/support/test_live_view_inline.ex
@@ -3,7 +3,7 @@ defmodule LiveViewNative.TestLiveViewInline do
use LiveViewNative.LiveView
@impl true
- def render(%{platform_id: :lvntest} = assigns) do
+ def render(%{format: :lvntest} = assigns) do
~LVN"""
Hello from the test platform
"""lvntest
diff --git a/test/support/test_platform.ex b/test/support/test_platform.ex
index 34194ce7..f3baed71 100644
--- a/test/support/test_platform.ex
+++ b/test/support/test_platform.ex
@@ -20,6 +20,10 @@ defmodule LiveViewNative.TestPlatform do
defimpl LiveViewNativePlatform.Kit do
def compile(_struct) do
LiveViewNativePlatform.Env.define(:lvntest,
+ default_layouts: %{
+ app: "<%= @inner_content %>",
+ root: "<%= @inner_content %>"
+ },
template_extension: ".test.heex",
template_namespace: Test,
otp_app: :live_view_native,