-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: support descriptive texts (header, title, legend, caption, fo…
…oter) (#62) * ✨ feat: support descriptive texts (header, title, legend, caption, footer) (closes #61) closes #61 * ♻️ refactor: scheme for better auto-completion
- Loading branch information
1 parent
08ba6cd
commit cbeabf0
Showing
9 changed files
with
252 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Sources/SwiftPlantUMLFramework/Configuration/PageTexts.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Foundation | ||
/// Descriptive texts ("common commands") you can add around your diagram | ||
public struct PageTexts: Codable { | ||
internal init(header: String? = nil, title: String? = nil, legend: String? = nil, caption: String? = nil, footer: String? = nil) { | ||
self.header = header | ||
self.title = title | ||
self.legend = legend | ||
self.caption = caption | ||
self.footer = footer | ||
} | ||
|
||
/// add a header to the top right above the diagram | ||
public var header: String? | ||
/// add a title above the diagram | ||
public var title: String? | ||
/// add a legend (boxed text) under the diagram but above the caption | ||
public var legend: String? | ||
/// add a caption under the diagram | ||
public var caption: String? | ||
/// add a footer at the bottom below the diagram | ||
public var footer: String? | ||
} | ||
|
||
extension PageTexts { | ||
func plantuml() -> String? { | ||
if header == nil, | ||
title == nil, | ||
legend == nil, | ||
caption == nil, | ||
footer == nil | ||
{ | ||
return nil | ||
} | ||
var text = "" | ||
if let header = header { | ||
text.appendAsNewLine("header") | ||
text.appendAsNewLine(header) | ||
text.appendAsNewLine("end header") | ||
} | ||
if let title = title { | ||
text.appendAsNewLine("title") | ||
text.appendAsNewLine(title) | ||
text.appendAsNewLine("end title") | ||
} | ||
if let legend = legend { | ||
text.appendAsNewLine("legend") | ||
text.appendAsNewLine(legend) | ||
text.appendAsNewLine("end legend") | ||
} | ||
if let caption = caption { | ||
text.appendAsNewLine("caption") | ||
text.appendAsNewLine(caption) | ||
text.appendAsNewLine("end caption") | ||
} | ||
if let footer = footer { | ||
text.appendAsNewLine("footer") | ||
text.appendAsNewLine(footer) | ||
text.appendAsNewLine("end footer") | ||
} | ||
return text | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
@testable import SwiftPlantUMLFramework | ||
import XCTest | ||
|
||
final class PageTextsTests: XCTestCase { | ||
func testNone() throws { | ||
let texts = PageTexts() | ||
XCTAssertNil(texts.plantuml()) | ||
} | ||
|
||
func testHeader() throws { | ||
let headerText = """ | ||
<u>Simple</u> header example | ||
on <i>several</i> lines and using <font color=red>html</font> | ||
""" | ||
|
||
let texts = PageTexts(header: headerText) | ||
let result = texts.plantuml() | ||
|
||
let expected = """ | ||
header | ||
\(headerText) | ||
end header | ||
""" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testTitle() throws { | ||
let titleText = """ | ||
<u>Simple</u> title example | ||
on <i>several</i> lines and using <font color=red>html</font> | ||
""" | ||
|
||
let texts = PageTexts(title: titleText) | ||
let result = texts.plantuml() | ||
|
||
let expected = """ | ||
title | ||
\(titleText) | ||
end title | ||
""" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testLegend() throws { | ||
let legendText = """ | ||
<u>Simple</u> legend example | ||
on <i>several</i> lines and using <font color=red>html</font> | ||
""" | ||
|
||
let texts = PageTexts(legend: legendText) | ||
let result = texts.plantuml() | ||
|
||
let expected = """ | ||
legend | ||
\(legendText) | ||
end legend | ||
""" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testCaption() throws { | ||
let captionText = """ | ||
<u>Simple</u> caption example | ||
on <i>several</i> lines and using <font color=red>html</font> | ||
""" | ||
|
||
let texts = PageTexts(caption: captionText) | ||
let result = texts.plantuml() | ||
|
||
let expected = """ | ||
caption | ||
\(captionText) | ||
end caption | ||
""" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testFooter() throws { | ||
let footerText = """ | ||
<u>Simple</u> footer example | ||
on <i>several</i> lines and using <font color=red>html</font> | ||
""" | ||
|
||
let texts = PageTexts(footer: footerText) | ||
let result = texts.plantuml() | ||
|
||
let expected = """ | ||
footer | ||
\(footerText) | ||
end footer | ||
""" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testAll() throws { | ||
let texts = PageTexts(header: "1", title: "2", legend: "3", caption: "4", footer: "5") | ||
let result = try XCTUnwrap(texts.plantuml()) | ||
XCTAssertTrue(result.contains("1")) | ||
XCTAssertTrue(result.contains("2")) | ||
XCTAssertTrue(result.contains("3")) | ||
XCTAssertTrue(result.contains("4")) | ||
XCTAssertTrue(result.contains("5")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters