Skip to content

Commit e3c104c

Browse files
committed
Add Arena support
1 parent 209932d commit e3c104c

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

.arena-sample.swift

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Playground generated with 🏟 Arena (https://github.com/finestructure/arena)
2+
// ℹ️ If running the playground fails with an error "no such module ..."
3+
// go to Product -> Build to re-trigger building the SPM package.
4+
// ℹ️ Please restart Xcode if autocomplete is not working.
5+
6+
import SwiftUI
7+
import TextBuilder
8+
import PlaygroundSupport
9+
10+
struct DemoView: View {
11+
@State var name: String?
12+
13+
var body: some View {
14+
VStack(spacing: 20) {
15+
welcomeText.font(.title)
16+
descriptionText
17+
someClickableText
18+
footnote
19+
}
20+
.multilineTextAlignment(.center)
21+
.padding()
22+
.background(Color(.windowBackgroundColor))
23+
}
24+
25+
@SpacedTextBuilder
26+
var welcomeText: Text {
27+
if let name = name, !name.isEmpty {
28+
"Welcome,"
29+
name.text.bold()
30+
} else {
31+
"Welcome"
32+
}
33+
}
34+
35+
@BasicTextBuilder
36+
var descriptionText: Text {
37+
"This is a demo of "
38+
"TextBuilder".text.italic()
39+
"."
40+
}
41+
42+
var someClickableText: Text {
43+
Text(separator: " ") {
44+
"This paragraph is implemented"
45+
"without".text.underline()
46+
"a builder to showcase the"
47+
"Text.init(separator:content:)".text.font(.system(.body, design: .monospaced)).foregroundColor(.gray)
48+
"initializer provided by this library."
49+
}
50+
}
51+
52+
var footnote: some View {
53+
Text {
54+
"Made by "
55+
"@davdroman".text.bold()
56+
}
57+
.underline()
58+
.font(.system(.caption))
59+
.foregroundColor(.blue)
60+
.pointable()
61+
.onTapGesture { NSWorkspace.shared.open(URL(string: "https://github.com/davdroman/TextBuilder")!) }
62+
}
63+
}
64+
65+
extension View {
66+
func pointable() -> some View {
67+
onHover { inside in
68+
if inside {
69+
NSCursor.pointingHand.push()
70+
} else {
71+
NSCursor.pop()
72+
}
73+
}
74+
}
75+
}
76+
77+
let view = NSHostingController(rootView: DemoView(name: NSFullUserName()))
78+
view.view.frame.size.width = 340
79+
PlaygroundPage.current.needsIndefiniteExecution = true
80+
PlaygroundPage.current.liveView = view

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ var loremIpsum: Text {
102102
"amet, consectetur"
103103
}
104104
```
105+
106+
## Try it out!
107+
108+
TextBuilder supports [Arena](https://github.com/finestructure/Arena) to effortlessly test this library in a playground before you decide to take it for a spin in your own project.
109+
110+
Simply [install Arena](https://github.com/finestructure/Arena#how-to-install-arena) and run `arena davdroman/TextBuilder --platform macos` in your terminal.

0 commit comments

Comments
 (0)