Swiftui2Lvn.API (swiftui_2_lvn v0.1.6)
View SourceClean API interface for VSCode plugin and other programmatic consumers.
This module provides a direct interface to the SwiftUI to LiveViewNative converter without the overhead and stdout pollution of Mix tasks.
Summary
Functions
Converts SwiftUI code to LiveViewNative template with structured response.
Converts SwiftUI code to LiveViewNative template, raising on error.
Batch converts multiple SwiftUI code snippets.
Converts SwiftUI code to JSON response format.
Functions
Converts SwiftUI code to LiveViewNative template with structured response.
Returns {:ok, lvn_code} on success or {:error, reason} on failure.
Examples
iex> Swiftui2Lvn.API.convert("Text(\"Hello\")")
{:ok, "<Text>Hello</Text>"}
iex> Swiftui2Lvn.API.convert("InvalidSwiftUI")
{:error, "Parse error: ..."}
Converts SwiftUI code to LiveViewNative template, raising on error.
This is a direct wrapper around Swiftui2Lvn.convert/1 for cases where
you want exceptions instead of tuples.
Examples
iex> Swiftui2Lvn.API.convert!("Text(\"Hello\")")
"<Text>Hello</Text>"
Batch converts multiple SwiftUI code snippets.
Returns a list of results in the same order as input.
Examples
iex> Swiftui2Lvn.API.convert_batch(["Text(\"Hello\")", "Text(\"World\")"])
[{:ok, "<Text>Hello</Text>"}, {:ok, "<Text>World</Text>"}]
Converts SwiftUI code to JSON response format.
Returns JSON string with either success or error response. Useful for HTTP APIs or language servers.
Examples
iex> Swiftui2Lvn.API.convert_to_json("Text(\"Hello\")")
"{\"success\":true,\"result\":\"<Text>Hello</Text>\"}"
iex> Swiftui2Lvn.API.convert_to_json("InvalidSwiftUI")
"{\"success\":false,\"error\":\"Parse error: ...\"}"