README.md
# SwiftUI to LiveViewNative Converter
Transform 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`:
```elixir
def deps do
[
{:swiftui_2_lvn, "~> 0.1.0"}
]
end
```
## Usage
### Basic Conversion
```elixir
# 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
```elixir
# 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:
```elixir
ast = Swiftui2Lvn.to_ast(~s|Text("Hello")|)
# Returns the AST structure that can be modified before printing
```
## Features
- **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 structure
- `Swiftui2Lvn.Transformer`: Converts Swift AST to Neex AST
- `Swiftui2Lvn.Printer`: Converts Neex AST to LiveViewNative template strings
- `Swiftui2Lvn`: Main public API
## Development
### Running Tests
```bash
mix test
```
### Documentation
```bash
mix docs
```
## Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Acknowledgments
- Built with [ex_swift_parser](https://github.com/dockyard/ex_swift_parser) for Swift code parsing
- Inspired by the need to simplify LiveViewNative development workflows