Skip to content

Commit d4a9862

Browse files
authored
Add SwiftFormat to Build Phases (#9)
* Add SwiftFormat to Build Phases * Update MarkupTokenizer.swift Update comment
1 parent 69c2f57 commit d4a9862

File tree

11 files changed

+136
-50
lines changed

11 files changed

+136
-50
lines changed

Markup.xcodeproj/project.pbxproj

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
isa = PBXNativeTarget;
247247
buildConfigurationList = 52D6D9901BEFF229002C0205 /* Build configuration list for PBXNativeTarget "Markup-iOS" */;
248248
buildPhases = (
249+
991DA25A21CED6C100C5DBBC /* Run SwiftFormat */,
249250
52D6D9771BEFF229002C0205 /* Sources */,
250251
52D6D9781BEFF229002C0205 /* Frameworks */,
251252
52D6D9791BEFF229002C0205 /* Headers */,
@@ -282,6 +283,7 @@
282283
isa = PBXNativeTarget;
283284
buildConfigurationList = 52D6D9E71BEFFF6E002C0205 /* Build configuration list for PBXNativeTarget "Markup-watchOS" */;
284285
buildPhases = (
286+
991DA25C21CED7C800C5DBBC /* Run SwiftFormat */,
285287
52D6D9DD1BEFFF6E002C0205 /* Sources */,
286288
52D6D9DE1BEFFF6E002C0205 /* Frameworks */,
287289
52D6D9DF1BEFFF6E002C0205 /* Headers */,
@@ -300,6 +302,7 @@
300302
isa = PBXNativeTarget;
301303
buildConfigurationList = 52D6DA011BEFFFBE002C0205 /* Build configuration list for PBXNativeTarget "Markup-tvOS" */;
302304
buildPhases = (
305+
991DA25D21CED7FA00C5DBBC /* Run SwiftFormat */,
303306
52D6D9EB1BEFFFBE002C0205 /* Sources */,
304307
52D6D9EC1BEFFFBE002C0205 /* Frameworks */,
305308
52D6D9ED1BEFFFBE002C0205 /* Headers */,
@@ -318,6 +321,7 @@
318321
isa = PBXNativeTarget;
319322
buildConfigurationList = 52D6DA201BF000BD002C0205 /* Build configuration list for PBXNativeTarget "Markup-macOS" */;
320323
buildPhases = (
324+
991DA25B21CED78D00C5DBBC /* Run SwiftFormat */,
321325
52D6DA0A1BF000BD002C0205 /* Sources */,
322326
52D6DA0B1BF000BD002C0205 /* Frameworks */,
323327
52D6DA0C1BF000BD002C0205 /* Headers */,
@@ -483,6 +487,81 @@
483487
};
484488
/* End PBXResourcesBuildPhase section */
485489

490+
/* Begin PBXShellScriptBuildPhase section */
491+
991DA25A21CED6C100C5DBBC /* Run SwiftFormat */ = {
492+
isa = PBXShellScriptBuildPhase;
493+
buildActionMask = 2147483647;
494+
files = (
495+
);
496+
inputFileListPaths = (
497+
);
498+
inputPaths = (
499+
);
500+
name = "Run SwiftFormat";
501+
outputFileListPaths = (
502+
);
503+
outputPaths = (
504+
);
505+
runOnlyForDeploymentPostprocessing = 0;
506+
shellPath = /bin/sh;
507+
shellScript = "\"${SRCROOT}/Scripts/run-swiftformat.sh\"\n";
508+
};
509+
991DA25B21CED78D00C5DBBC /* Run SwiftFormat */ = {
510+
isa = PBXShellScriptBuildPhase;
511+
buildActionMask = 2147483647;
512+
files = (
513+
);
514+
inputFileListPaths = (
515+
);
516+
inputPaths = (
517+
);
518+
name = "Run SwiftFormat";
519+
outputFileListPaths = (
520+
);
521+
outputPaths = (
522+
);
523+
runOnlyForDeploymentPostprocessing = 0;
524+
shellPath = /bin/sh;
525+
shellScript = "\"${SRCROOT}/Scripts/run-swiftformat.sh\"\n";
526+
};
527+
991DA25C21CED7C800C5DBBC /* Run SwiftFormat */ = {
528+
isa = PBXShellScriptBuildPhase;
529+
buildActionMask = 2147483647;
530+
files = (
531+
);
532+
inputFileListPaths = (
533+
);
534+
inputPaths = (
535+
);
536+
name = "Run SwiftFormat";
537+
outputFileListPaths = (
538+
);
539+
outputPaths = (
540+
);
541+
runOnlyForDeploymentPostprocessing = 0;
542+
shellPath = /bin/sh;
543+
shellScript = "\"${SRCROOT}/Scripts/run-swiftformat.sh\"\n";
544+
};
545+
991DA25D21CED7FA00C5DBBC /* Run SwiftFormat */ = {
546+
isa = PBXShellScriptBuildPhase;
547+
buildActionMask = 2147483647;
548+
files = (
549+
);
550+
inputFileListPaths = (
551+
);
552+
inputPaths = (
553+
);
554+
name = "Run SwiftFormat";
555+
outputFileListPaths = (
556+
);
557+
outputPaths = (
558+
);
559+
runOnlyForDeploymentPostprocessing = 0;
560+
shellPath = /bin/sh;
561+
shellScript = "\"${SRCROOT}/Scripts/run-swiftformat.sh\"\n";
562+
};
563+
/* End PBXShellScriptBuildPhase section */
564+
486565
/* Begin PBXSourcesBuildPhase section */
487566
52D6D9771BEFF229002C0205 /* Sources */ = {
488567
isa = PBXSourcesBuildPhase;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

MarkupExample/AppDelegate.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1111

1212
var window: UIWindow?
1313

14-
1514
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1615
// Override point for customization after application launch.
1716
return true
@@ -38,7 +37,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3837
func applicationWillTerminate(_ application: UIApplication) {
3938
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4039
}
41-
42-
4340
}
44-

MarkupExample/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// See LICENSE file for license
55
//
66

7-
import UIKit
87
import Markup
8+
import UIKit
99

1010
class ViewController: UIViewController {
11-
@IBOutlet weak var plainTextLabel: UILabel!
12-
@IBOutlet weak var richTextLabel: UILabel!
11+
@IBOutlet var plainTextLabel: UILabel!
12+
@IBOutlet var richTextLabel: UILabel!
1313

1414
private let renderer = MarkupRenderer(baseFont: .systemFont(ofSize: 16))
1515
private let sampleText = "~Annihilate?~ No. No violence. I won't stand for it. _Not now, not ever, do you understand me?!_ *I'm the Doctor, the Oncoming Storm - and you basically meant beat them in a football match, didn't you?* I'm nobody's taxi service; I'm not gonna be there to catch you every time you feel like _*jumping out of a spaceship*_."

Scripts/run-swiftformat.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
set -e
3+
4+
"${PROJECT_DIR}/Tools/swiftformat" --indent tabs --stripunusedargs closure-only --decimalgrouping 3,4 --commas inline --disable hoistPatternLet "${SRCROOT}/MarkupExample/" "${SRCROOT}/Sources/" "${SRCROOT}/Tests/"

Sources/MarkupRenderer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ extension Array where Element: NSAttributedString {
8585
return UIFont(descriptor: descriptor, size: 0)
8686
}
8787
}
88+
8889
#elseif os(OSX)
8990
extension NSFont {
9091
func boldFont() -> NSFont? {

Sources/MarkupToken.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ enum MarkupToken {
1313
}
1414

1515
extension MarkupToken: Equatable {
16-
static func ==(lhs: MarkupToken, rhs: MarkupToken) -> Bool {
16+
static func == (lhs: MarkupToken, rhs: MarkupToken) -> Bool {
1717
switch (lhs, rhs) {
1818
case let (.text(lvalue), .text(rvalue)):
1919
return lvalue == rvalue

Sources/MarkupTokenizer.swift

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ private extension UnicodeScalar {
1717
static let space: UnicodeScalar = " "
1818
}
1919

20-
/**
21-
Breaks a string into markup tokens.
22-
23-
How to use it:
24-
25-
var tokenizer = MarkupTokenizer(string: "_Hello *world*_")
26-
while let token = tokenizer.nextToken() {
27-
switch token {
28-
case let .text(value):
29-
print("text: \(value)"
30-
case let .leftDelimiter(value):
31-
print("left delimiter: \(value)"
32-
case let .rightDelimiter(value):
33-
print("right delimiter: \(value)"
34-
}
35-
}
36-
*/
20+
/// Breaks a string into markup tokens.
21+
///
22+
/// How to use it:
23+
///
24+
/// var tokenizer = MarkupTokenizer(string: "_Hello *world*_")
25+
/// while let token = tokenizer.nextToken() {
26+
/// switch token {
27+
/// case let .text(value):
28+
/// print("text: \(value)"
29+
/// case let .leftDelimiter(value):
30+
/// print("left delimiter: \(value)"
31+
/// case let .rightDelimiter(value):
32+
/// print("right delimiter: \(value)"
33+
/// }
34+
/// }
3735
struct MarkupTokenizer {
3836
/// The input string
3937
private let input: String.UnicodeScalarView
@@ -117,7 +115,7 @@ struct MarkupTokenizer {
117115
guard CharacterSet.whitespaceAndPunctuation.contains(p) &&
118116
!CharacterSet.whitespacesAndNewlines.contains(n) &&
119117
!leftDelimiters.contains(delimiter) else {
120-
return nil
118+
return nil
121119
}
122120

123121
leftDelimiters.append(delimiter)
@@ -138,7 +136,7 @@ struct MarkupTokenizer {
138136
guard !CharacterSet.whitespacesAndNewlines.contains(p) &&
139137
CharacterSet.whitespaceAndPunctuation.contains(n) &&
140138
leftDelimiters.contains(delimiter) else {
141-
return nil
139+
return nil
142140
}
143141

144142
while !leftDelimiters.isEmpty {
@@ -159,7 +157,7 @@ struct MarkupTokenizer {
159157
return nil
160158
}
161159

162-
return .text(String(input[startIndex..<currentIndex]))
160+
return .text(String(input[startIndex ..< currentIndex]))
163161
}
164162

165163
private mutating func scanUntil(_ predicate: (UnicodeScalar) -> Bool) {

Tests/MarkupTests/MarkupParserTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// See LICENSE file for license
55
//
66

7-
import XCTest
87
import Markup
8+
import XCTest
99

1010
private func equalDump<T>(_ lhs: T, _ rhs: T) -> Bool {
1111
var (ldump, rdump) = ("", "")

Tests/MarkupTests/MarkupRendererTests.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44
// See LICENSE file for license
55
//
66

7-
import XCTest
87
@testable import Markup
8+
import XCTest
99

1010
class MarkupRendererTests: XCTestCase {
1111
let baseFont = Font.systemFont(ofSize: 16)
1212
var sut: MarkupRenderer!
13-
13+
1414
override func setUp() {
1515
super.setUp()
1616
sut = MarkupRenderer(baseFont: baseFont)
1717
}
18-
18+
1919
func testPlainText_render_rendersPlainText() {
2020
// given
2121
let input = "hello there"
2222
let expected = NSAttributedString(string: "hello there",
23-
attributes: [NSAttributedString.Key.font: baseFont])
24-
23+
attributes: [NSAttributedString.Key.font: baseFont])
24+
2525
// when
2626
let result = sut.render(text: input)
27-
27+
2828
// then
2929
XCTAssertEqual(result, expected)
3030
}
31-
31+
3232
func testStrongText_render_rendersBoldText() {
3333
// given
3434
let input = "hello *there*"
3535
let boldFont = baseFont.boldFont()!
3636
let expected = [
3737
NSAttributedString(string: "hello ",
38-
attributes: [NSAttributedString.Key.font: baseFont]),
38+
attributes: [NSAttributedString.Key.font: baseFont]),
3939
NSAttributedString(string: "there",
40-
attributes: [NSAttributedString.Key.font: boldFont])
41-
].joined()
40+
attributes: [NSAttributedString.Key.font: boldFont])
41+
].joined()
4242

4343
// when
4444
let result = sut.render(text: input)
@@ -53,10 +53,10 @@ class MarkupRendererTests: XCTestCase {
5353
let italicFont = baseFont.italicFont()!
5454
let expected = [
5555
NSAttributedString(string: "hello ",
56-
attributes: [NSAttributedString.Key.font: baseFont]),
56+
attributes: [NSAttributedString.Key.font: baseFont]),
5757
NSAttributedString(string: "there",
58-
attributes: [NSAttributedString.Key.font: italicFont])
59-
].joined()
58+
attributes: [NSAttributedString.Key.font: italicFont])
59+
].joined()
6060

6161
// when
6262
let result = sut.render(text: input)
@@ -75,10 +75,10 @@ class MarkupRendererTests: XCTestCase {
7575
]
7676
let expected = [
7777
NSAttributedString(string: "hello ",
78-
attributes: [NSAttributedString.Key.font: baseFont]),
78+
attributes: [NSAttributedString.Key.font: baseFont]),
7979
NSAttributedString(string: "there",
80-
attributes: strikethroughAttributes)
81-
].joined()
80+
attributes: strikethroughAttributes)
81+
].joined()
8282

8383
// when
8484
let result = sut.render(text: input)
@@ -93,14 +93,14 @@ class MarkupRendererTests: XCTestCase {
9393
let boldItalicFont = baseFont.boldFont()!.italicFont()!
9494
let expected = [
9595
NSAttributedString(string: "hello ",
96-
attributes: [NSAttributedString.Key.font: baseFont]),
96+
attributes: [NSAttributedString.Key.font: baseFont]),
9797
NSAttributedString(string: "there",
98-
attributes: [NSAttributedString.Key.font: boldItalicFont]),
98+
attributes: [NSAttributedString.Key.font: boldItalicFont]),
9999
NSAttributedString(string: " ",
100-
attributes: [NSAttributedString.Key.font: baseFont]),
100+
attributes: [NSAttributedString.Key.font: baseFont]),
101101
NSAttributedString(string: "there",
102-
attributes: [NSAttributedString.Key.font: boldItalicFont])
103-
].joined()
102+
attributes: [NSAttributedString.Key.font: boldItalicFont])
103+
].joined()
104104

105105
// when
106106
let result = sut.render(text: input)

0 commit comments

Comments
 (0)