Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveView 0.20.2+ #728

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/surface/compiler/eex_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Surface.Compiler.EExEngine do
for information on this). Finally, it passes these tokens into the engine sequentially in the same
manner as EEx.Compiler.compile/2
"""
alias Surface.Compiler.Helpers
alias Surface.AST
alias Surface.IOHelper
alias Surface.Components.Context
Expand All @@ -27,7 +28,8 @@ defmodule Surface.Compiler.EExEngine do
engine: opts[:engine] || @default_engine,
depth: 0,
context_vars: %{count: 0, changed: []},
scope: []
scope: [],
root_tag?: root_tag?(nodes)
}

nodes
Expand All @@ -40,6 +42,22 @@ defmodule Surface.Compiler.EExEngine do
)
end

defp root_tag?(nodes) do
Enum.reduce_while(nodes, false, fn
%AST.Tag{}, false ->
{:cont, true}

%AST.Tag{}, true ->
{:halt, false}

%AST.Literal{value: value}, acc ->
if Helpers.blank?(value), do: {:cont, acc}, else: {:halt, false}

_node, _acc ->
{:halt, false}
end)
end

defp to_token_sequence(nodes) do
nodes
|> to_dynamic_nested_html()
Expand All @@ -48,7 +66,7 @@ defmodule Surface.Compiler.EExEngine do
end

defp generate_buffer([], buffer, state) do
ast = state.engine.handle_body(buffer, root: true)
ast = state.engine.handle_body(buffer, root: state.root_tag?)

quote do
require Phoenix.LiveView.TagEngine
Expand Down
2 changes: 1 addition & 1 deletion lib/surface/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Surface.Component do
use Surface.BaseComponent, type: unquote(__MODULE__)

use Surface.API, include: [:prop, :slot, :data]
import Phoenix.HTML
import PhoenixHTMLHelpers

@before_compile {Surface.BaseComponent, :__before_compile_init_slots__}
@before_compile {unquote(__MODULE__), :__before_compile_handle_from_context__}
Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/checkbox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.Checkbox do
@moduledoc """
Defines a checkbox.

Provides a wrapper for Phoenix.HTML.Form's `checkbox/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `checkbox/3` function.

All options passed via `opts` will be sent to `checkbox/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.Checkbox do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [checkbox: 3]
import PhoenixHTMLHelpers.Form, only: [checkbox: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/color_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Surface.Components.Form.ColorInput do
An input field that let the user specify a **color**, either with a
text field or a color picker interface.

Provides a wrapper for Phoenix.HTML.Form's `color_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `color_input/3` function.

All options passed via `opts` will be sent to `color_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -18,7 +18,7 @@ defmodule Surface.Components.Form.ColorInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [color_input: 3]
import PhoenixHTMLHelpers.Form, only: [color_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/date_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Surface.Components.Form.DateInput do
An input field that let the user enter a **date**, either with a text field
or a date picker interface.

Provides a wrapper for Phoenix.HTML.Form's `date_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `date_input/3` function.

All options passed via `opts` will be sent to `date_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -18,7 +18,7 @@ defmodule Surface.Components.Form.DateInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [date_input: 3]
import PhoenixHTMLHelpers.Form, only: [date_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/date_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.DateSelect do
@moduledoc """
Generates select tags for date.

Provides a wrapper for Phoenix.HTML.Form's `date_select/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `date_select/3` function.

All options passed via `opts` will be sent to `date_select/3`,
`value`, `default`, `year`, `month`, `day` and `builder`
Expand All @@ -21,7 +21,7 @@ defmodule Surface.Components.Form.DateSelect do

use Surface.Component

import Phoenix.HTML.Form, only: [date_select: 3]
import PhoenixHTMLHelpers.Form, only: [date_select: 3]
import Surface.Components.Form.Utils

@doc "The form identifier"
Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/datetime_local_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Surface.Components.Form.DateTimeLocalInput do
An input field that let the user enter both **date** and **time**, using a
text field and a date picker interface.

Provides a wrapper for Phoenix.HTML.Form's `datetime_local_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `datetime_local_input/3` function.

All options passed via `opts` will be sent to `datetime_local_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -18,7 +18,7 @@ defmodule Surface.Components.Form.DateTimeLocalInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [datetime_local_input: 3]
import PhoenixHTMLHelpers.Form, only: [datetime_local_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/datetime_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.DateTimeSelect do
@moduledoc """
Generates select tags for datetime.

Provides a wrapper for Phoenix.HTML.Form's `datetime_select/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `datetime_select/3` function.

All options passed via `opts` will be sent to `datetime_select/3`,
`value`, `default`, `year`, `month`, `day`, `hour`, `minute`, `second` and `builder`
Expand All @@ -21,7 +21,7 @@ defmodule Surface.Components.Form.DateTimeSelect do

use Surface.Component

import Phoenix.HTML.Form, only: [datetime_select: 3]
import PhoenixHTMLHelpers.Form, only: [datetime_select: 3]
import Surface.Components.Form.Utils

@doc "The form identifier"
Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/email_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.EmailInput do
@moduledoc """
An input field that let the user enter one or multiple **e-mails**.

Provides a wrapper for Phoenix.HTML.Form's `email_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `email_input/3` function.

All options passed via `opts` will be sent to `email_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.EmailInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [email_input: 3]
import PhoenixHTMLHelpers.Form, only: [email_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/file_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Surface.Components.Form.FileInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [file_input: 3]
import PhoenixHTMLHelpers.Form, only: [file_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/hidden_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.HiddenInput do
@moduledoc """
A **hidden** input field.

Provides a wrapper for Phoenix.HTML.Form's `hidden_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `hidden_input/3` function.

All options passed via `opts` will be sent to `hidden_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.HiddenInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [hidden_input: 3]
import PhoenixHTMLHelpers.Form, only: [hidden_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/multiple_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ defmodule Surface.Components.Form.MultipleSelect do
@moduledoc """
Defines a select.

Provides a wrapper for Phoenix.HTML.Form's `multiple_select/4` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `multiple_select/4` function.

All options passed via `opts` will be sent to `multiple_select/4`, `class` can
be set directly and will override anything in `opts`.
"""

use Surface.Component

import Phoenix.HTML.Form, only: [multiple_select: 4]
import PhoenixHTMLHelpers.Form, only: [multiple_select: 4]
import Surface.Components.Form.Utils

@doc "The form identifier"
Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/number_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.NumberInput do
@moduledoc """
An input field that let the user to enter a **number**.

Provides a wrapper for Phoenix.HTML.Form's `number_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `number_input/3` function.

All options passed via `opts` will be sent to `number_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.NumberInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [number_input: 3]
import PhoenixHTMLHelpers.Form, only: [number_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
2 changes: 1 addition & 1 deletion lib/surface/components/form/options_for_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Surface.Components.Form.OptionsForSelect do

This is useful when building the select by hand.

Provides a wrapper for Phoenix.HTML.Form's `options_for_select/2` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `options_for_select/2` function.
"""

use Surface.Component
Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/password_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.PasswordInput do
@moduledoc """
An input field that let the user securely specify a **password**.

Provides a wrapper for Phoenix.HTML.Form's `password_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `password_input/3` function.

All options passed via `opts` will be sent to `password_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.PasswordInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [password_input: 3]
import PhoenixHTMLHelpers.Form, only: [password_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/radio_button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.RadioButton do
@moduledoc """
Defines a radio button.

Provides a wrapper for Phoenix.HTML.Form's `radio_button/4` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `radio_button/4` function.

All options passed via `opts` will be sent to `radio_button/4`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.RadioButton do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [radio_button: 4]
import PhoenixHTMLHelpers.Form, only: [radio_button: 4]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/range_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Surface.Components.Form.RangeInput do
An input field that let the user specify a numeric value in a given **range**,
usually using a slider.

Provides a wrapper for Phoenix.HTML.Form's `range_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `range_input/3` function.

All options passed via `opts` will be sent to `range_input/3`, `value`, `min`, `max`
and `class` can be set directly and will override anything in `opts`.
Expand All @@ -18,7 +18,7 @@ defmodule Surface.Components.Form.RangeInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [range_input: 3]
import PhoenixHTMLHelpers.Form, only: [range_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/reset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.Reset do
@moduledoc """
Defines a reset button.

Provides a wrapper for Phoenix.HTML.Form's `reset/2` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `reset/2` function.

All options passed via `opts` will be sent to `reset/2`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -18,7 +18,7 @@ defmodule Surface.Components.Form.Reset do
use Surface.Component
use Surface.Components.Events

import Phoenix.HTML.Form, only: [reset: 2]
import PhoenixHTMLHelpers.Form, only: [reset: 2]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/search_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.SearchInput do
@moduledoc """
An input field that let the user enter **search** queries.

Provides a wrapper for Phoenix.HTML.Form's `search_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `search_input/3` function.

All options passed via `opts` will be sent to `search_input/3`, `value` and
`class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.SearchInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [search_input: 3]
import PhoenixHTMLHelpers.Form, only: [search_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ defmodule Surface.Components.Form.Select do
@moduledoc """
Defines a select.

Provides a wrapper for Phoenix.HTML.Form's `select/4` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `select/4` function.

All options passed via `opts` will be sent to `select/4`, `class` can
be set directly and will override anything in `opts`.
"""

use Surface.Component

import Phoenix.HTML.Form, only: [select: 4]
import PhoenixHTMLHelpers.Form, only: [select: 4]
import Surface.Components.Form.Utils

@doc "The form identifier"
Expand Down
4 changes: 2 additions & 2 deletions lib/surface/components/form/telephone_input.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Surface.Components.Form.TelephoneInput do
@moduledoc """
An input field that let the user enter a **telephone number**.

Provides a wrapper for Phoenix.HTML.Form's `telephone_input/3` function.
Provides a wrapper for PhoenixHTMLHelpers.Form's `telephone_input/3` function.

All options passed via `opts` will be sent to `telephone_input/3`, `value`,
`pattern` and `class` can be set directly and will override anything in `opts`.
Expand All @@ -17,7 +17,7 @@ defmodule Surface.Components.Form.TelephoneInput do

use Surface.Components.Form.Input

import Phoenix.HTML.Form, only: [telephone_input: 3]
import PhoenixHTMLHelpers.Form, only: [telephone_input: 3]
import Surface.Components.Utils, only: [events_to_opts: 1]
import Surface.Components.Form.Utils

Expand Down
Loading
Loading