Skip to content

Parse ~GPUI templates without Phoenix LiveView - #12

Open
jeregrine wants to merge 1 commit into
elixir-crab:mainfrom
jeregrine:template-parser-without-liveview
Open

jeregrine wants to merge 1 commit into
elixir-crab:mainfrom
jeregrine:template-parser-without-liveview

Conversation

@jeregrine

Copy link
Copy Markdown

Summary

GPUI only used LiveView for Phoenix.LiveView.TagEngine.Parser (a @moduledoc false API) to tokenize ~GPUI markup. Compiling to %GPUI.Element{} was already GPUI's own code. This replaces that parser with GPUI.Template.Parser, a small hand-written parser for the subset GPUI supports: tags, <Remote.component> / <.local> calls, <:slot> entries, and {expr} attributes and children. With it, phoenix_live_view is no longer a dependency, and neither are phoenix, phoenix_html, phoenix_pubsub, phoenix_template or websock/websock_adapter. plug remains through safe_rpc.

Expressions end the same way as in HEEx: braces are counted and \{ / \} escape them.

Evidence

  • Same output: I compiled every ~GPUI template in this repository and in a downstream app (193 templates, 61 files) with both the LiveView-based compiler and the new one, ignoring source metadata. The generated code was identical for all 193.
  • Comments: before, <!-- ... --> was emitted as a literal text child. After, comments are dropped.
  • Unsupported syntax: before, <%= %>, <div {@rest}> and value-less attributes like <div hidden> crashed the compiler with FunctionClauseError or produced odd attributes. After, each raises a CompileError naming the template line and column, as do unclosed/mismatched tags and misplaced slots. New tests cover these.

Compatibility

Applications that relied on HTML comments rendering as text will see that text disappear. Templates that previously compiled produce the same element trees. No schema, native, or package-version changes. Applications that depended on phoenix_live_view only through gpui need to add it themselves.

GPUI only used LiveView's TagEngine.Parser to tokenize HEEx-style markup;
compilation to %GPUI.Element{} was already GPUI's own. Replace it with a
small parser for the subset GPUI supports (tags, remote/local components,
slots, {expr} attributes and children) and drop phoenix_live_view, which
also removes phoenix, phoenix_html, phoenix_pubsub, phoenix_template and
websock from the dependency tree.

Output is unchanged for every existing ~GPUI template in the repo. HTML
comments are now dropped instead of rendered as text, and unsupported
syntax (EEx tags, root attributes, value-less attributes) raises a
CompileError with the template line and column.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant