Update from Hummingbird Project Template (#58)

* Update from hummingbird-project-template 572d468b2cabeca286314c5a35196bd42445c8ef

* run swift-format

* Remove .swiftformat

---------

Co-authored-by: adam-fowler <adam-fowler@users.noreply.github.com>
Co-authored-by: Adam Fowler <adamfowler71@gmail.com>
This commit is contained in:
hummingbird-automation[bot]
2024-11-28 07:31:09 +00:00
committed by GitHub
parent 8c5c8ead74
commit ec4ef9aa04
21 changed files with 663 additions and 430 deletions

View File

@@ -21,14 +21,14 @@ public protocol MustacheContentType: Sendable {
/// Text content type where no character is escaped
struct TextContentType: MustacheContentType {
func escapeText(_ text: String) -> String {
return text
text
}
}
/// HTML content where text is escaped for HTML output
struct HTMLContentType: MustacheContentType {
func escapeText(_ text: String) -> String {
return text.htmlEscape()
text.htmlEscape()
}
}
@@ -39,7 +39,7 @@ struct HTMLContentType: MustacheContentType {
/// with `MustacheContentTypes.register`.
public enum MustacheContentTypes {
static func get(_ name: String) -> MustacheContentType? {
return self.types[name]
self.types[name]
}
/// Register new content type

View File

@@ -131,7 +131,7 @@ struct MustacheContext {
/// return context with sequence info and sequence element added to stack
func withContentType(_ contentType: MustacheContentType) -> MustacheContext {
return .init(
.init(
stack: self.stack,
sequenceContext: self.sequenceContext,
indentation: self.indentation,

View File

@@ -50,6 +50,6 @@ public struct MustacheLambda {
}
internal func callAsFunction(_ s: String) -> Any? {
return self.callback(s)
self.callback(s)
}
}

View File

@@ -21,5 +21,5 @@ public protocol MustacheParent {
/// Extend dictionary where the key is a string so that it uses the key values to access
/// it values
extension Dictionary: MustacheParent where Key == String {
public func child(named: String) -> Any? { return self[named] }
public func child(named: String) -> Any? { self[named] }
}

View File

@@ -38,7 +38,7 @@ struct Parser {
self.position = string.startIndex
}
var buffer: String { return self._storage.buffer }
var buffer: String { self._storage.buffer }
private(set) var position: String.Index
}
@@ -59,7 +59,10 @@ extension Parser {
/// - Returns: If current character was the one we expected
mutating func read(_ char: Character) throws -> Bool {
let c = try character()
guard c == char else { unsafeRetreat(); return false }
guard c == char else {
unsafeRetreat()
return false
}
return true
}
@@ -84,7 +87,10 @@ extension Parser {
/// - Returns: If current character is in character set
mutating func read(_ characterSet: Set<Character>) throws -> Bool {
let c = try character()
guard characterSet.contains(c) else { unsafeRetreat(); return false }
guard characterSet.contains(c) else {
unsafeRetreat()
return false
}
return true
}
@@ -236,7 +242,7 @@ extension Parser {
@discardableResult mutating func read(while: Character) -> Int {
var count = 0
while !self.reachedEnd(),
unsafeCurrent() == `while`
unsafeCurrent() == `while`
{
unsafeAdvance()
count += 1
@@ -250,7 +256,7 @@ extension Parser {
@discardableResult mutating func read(while keyPath: KeyPath<Character, Bool>) -> Substring {
let startIndex = self.position
while !self.reachedEnd(),
unsafeCurrent()[keyPath: keyPath]
unsafeCurrent()[keyPath: keyPath]
{
unsafeAdvance()
}
@@ -263,7 +269,7 @@ extension Parser {
@discardableResult mutating func read(while cb: (Character) -> Bool) -> Substring {
let startIndex = self.position
while !self.reachedEnd(),
cb(unsafeCurrent())
cb(unsafeCurrent())
{
unsafeAdvance()
}
@@ -276,7 +282,7 @@ extension Parser {
@discardableResult mutating func read(while characterSet: Set<Character>) -> Substring {
let startIndex = self.position
while !self.reachedEnd(),
characterSet.contains(unsafeCurrent())
characterSet.contains(unsafeCurrent())
{
unsafeAdvance()
}
@@ -286,13 +292,13 @@ extension Parser {
/// Return whether we have reached the end of the buffer
/// - Returns: Have we reached the end
func reachedEnd() -> Bool {
return self.position == self.buffer.endIndex
self.position == self.buffer.endIndex
}
/// Return whether we are at the start of the buffer
/// - Returns: Are we are the start
func atStart() -> Bool {
return self.position == self.buffer.startIndex
self.position == self.buffer.startIndex
}
}
@@ -378,7 +384,7 @@ extension Parser {
// unsafe versions without checks
extension Parser {
func unsafeCurrent() -> Character {
return self.buffer[self.position]
self.buffer[self.position]
}
mutating func unsafeAdvance() {

View File

@@ -327,7 +327,8 @@ extension MustacheTemplate {
}
if self.isStandalone(&parser, state: state) {
setNewLine = true
} else if whiteSpaceBefore.count > 0 {}
} else if whiteSpaceBefore.count > 0 {
}
let sectionTemplate = try parse(&parser, state: state.withSectionName(name, newLine: setNewLine))
tokens.append(.blockExpansion(name: name, default: sectionTemplate, indentation: String(whiteSpaceBefore)))
whiteSpaceBefore = ""
@@ -415,7 +416,7 @@ extension MustacheTemplate {
nameParser.unsafeAdvance()
// We need to have a `)` for each transform that we've parsed
guard nameParser.read(while: ")") + 1 == existing.count,
nameParser.reachedEnd()
nameParser.reachedEnd()
else {
throw Error.unfinishedName
}
@@ -512,7 +513,7 @@ extension MustacheTemplate {
}
static func isStandalone(_ parser: inout Parser, state: ParserState) -> Bool {
return state.newLine && self.hasLineFinished(&parser)
state.newLine && self.hasLineFinished(&parser)
}
private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*")

View File

@@ -285,7 +285,7 @@ extension MustacheTemplate {
// run transform on the current child
for transform in transforms.reversed() {
if let runnable = child as? MustacheTransformable,
let transformed = runnable.transform(transform)
let transformed = runnable.transform(transform)
{
child = transformed
continue

View File

@@ -31,13 +31,13 @@ public protocol MustacheTransformable {
func transform(_ name: String) -> Any?
}
public extension StringProtocol {
extension StringProtocol {
/// Transform String/Substring
///
/// Transforms available are `capitalized`, `lowercased`, `uppercased` and `reversed`
/// - Parameter name: transform name
/// - Returns: Result
func transform(_ name: String) -> Any? {
public func transform(_ name: String) -> Any? {
switch name {
case "empty":
return isEmpty
@@ -209,13 +209,13 @@ extension Dictionary: ComparableSequence where Key: Comparable {
}
}
public extension FixedWidthInteger {
extension FixedWidthInteger {
/// Transform FixedWidthInteger
///
/// Transforms available are `plusone`, `minusone`, `odd`, `even`
/// - Parameter name: transform name
/// - Returns: Result
func transform(_ name: String) -> Any? {
public func transform(_ name: String) -> Any? {
switch name {
case "equalzero":
return self == 0