SwiftUI to LiveViewNative Converter
View SourceTransform SwiftUI code into LiveViewNative templates with ease.
Installation
The package can be installed by adding swiftui_2_lvn to your list of dependencies in mix.exs:
def deps do
[
{:swiftui_2_lvn, "~> 0.1.0"}
]
endUsage
Basic Conversion
# Convert simple SwiftUI code to LiveViewNative template
Swiftui2Lvn.convert(~s|Text("Hello World")|)
# => "<Text>Hello World</Text>"
# Convert with attributes
Swiftui2Lvn.convert(~s|VStack(alignment: .leading)|)
# => <VStack alignment=".leading" />
# Convert with modifiers
Swiftui2Lvn.convert(~s|Text("Hello").font(.title).padding()|)
# => <Text style={["font(.title)", "padding()"]}>Hello</Text>Complex Examples
# Nested elements
swift_code = ~s|
VStack {
Text("One")
Text("Two")
}
|
Swiftui2Lvn.convert(swift_code)
# => "<VStack>\n <Text>One</Text>\n \n <Text>Two</Text>\n</VStack>\n""
# Elements with complex modifiers
swift_code = ~s|Text("Hello").font(Font.system(size: 18).weight(.medium))|
Swiftui2Lvn.convert(swift_code)
# => <Text style={["font(Font.system(size:18).weight(.medium))"]}>Hello</Text>Working with AST
If you need to inspect or modify the AST before converting to the final template:
ast = Swiftui2Lvn.to_ast(~s|Text("Hello")|)
# Returns the AST structure that can be modified before printingFeatures
- SwiftUI Parsing: Parses SwiftUI code using the Swift AST
- Template Generation: Converts SwiftUI elements to LiveViewNative syntax
- Modifier Support: Handles SwiftUI modifiers like
.font(),.padding(), etc. - Nested Elements: Supports complex nested view structures
- Attribute Mapping: Converts SwiftUI parameters to LiveViewNative attributes
Architecture
The library is composed of several modules:
Swiftui2Lvn.Parser: Parses Swift code into AST structureSwiftui2Lvn.Transformer: Converts Swift AST to Neex ASTSwiftui2Lvn.Printer: Converts Neex AST to LiveViewNative template stringsSwiftui2Lvn: Main public API
Development
Running Tests
mix test
Documentation
mix docs
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with ex_swift_parser for Swift code parsing
- Inspired by the need to simplify LiveViewNative development workflows