Compare commits
10 Commits
e57f85ff19
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6061715025 | ||
|
|
999fda1e52 | ||
|
|
534f9f9e60 | ||
|
|
6df64896f4 | ||
|
|
28df3156e2 | ||
|
|
2aee7d23bc | ||
|
|
aaacbd989b | ||
|
|
2add8847a1 | ||
|
|
eeb4eec97f | ||
|
|
c8b6af450d |
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -1 +1 @@
|
||||
* @adam-fowler @Joannis
|
||||
* @astzweig/coders
|
||||
|
||||
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@@ -1 +0,0 @@
|
||||
github: adam-fowler
|
||||
3
.github/dependabot.yml
vendored
3
.github/dependabot.yml
vendored
@@ -4,6 +4,9 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
ignore:
|
||||
- dependency-name: "codecov/codecov-action"
|
||||
update-types: ["version-update:semver-major"]
|
||||
groups:
|
||||
dependencies:
|
||||
patterns:
|
||||
|
||||
2
.github/workflows/api-breakage.yml
vendored
2
.github/workflows/api-breakage.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
image: swift:latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
# https://github.com/actions/checkout/issues/766
|
||||
|
||||
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
- name: SPM tests
|
||||
run: swift test --enable-code-coverage
|
||||
- name: Convert coverage files
|
||||
@@ -30,20 +30,21 @@ jobs:
|
||||
-ignore-filename-regex="\/Benchmarks\/" \
|
||||
-instr-profile=.build/debug/codecov/default.profdata > info.lcov
|
||||
- name: Upload to codecov.io
|
||||
uses: codecov/codecov-action@v5
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
files: info.lcov
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
linux:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
strategy:
|
||||
matrix:
|
||||
image: ["swift:5.9", "swift:5.10", "swift:6.0", "swiftlang/swift:nightly-6.1-jammy"]
|
||||
image: ["swift:6.0", "swift:6.1", "swift:6.2"]
|
||||
container:
|
||||
image: ${{ matrix.image }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
- name: Test
|
||||
run: |
|
||||
swift test --enable-code-coverage
|
||||
@@ -55,18 +56,19 @@ jobs:
|
||||
-ignore-filename-regex="\/Benchmarks\/" \
|
||||
-instr-profile .build/debug/codecov/default.profdata > info.lcov
|
||||
- name: Upload to codecov.io
|
||||
uses: codecov/codecov-action@v5
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
files: info.lcov
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
windows:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
swift-version: ["6.0"]
|
||||
swift-version: ["6.1"]
|
||||
steps:
|
||||
- uses: compnerd/gha-setup-swift@main
|
||||
with:
|
||||
branch: swift-${{ matrix.swift-version }}-release
|
||||
tag: ${{ matrix.swift-version }}-RELEASE
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- run: swift test
|
||||
|
||||
2
.github/workflows/nightly.yml
vendored
2
.github/workflows/nightly.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
image: swiftlang/swift:${{ matrix.image }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
- name: Test
|
||||
run: |
|
||||
swift test
|
||||
|
||||
2
.github/workflows/validate.yml
vendored
2
.github/workflows/validate.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: run script
|
||||
|
||||
4
.github/workflows/verify-documentation.yml
vendored
4
.github/workflows/verify-documentation.yml
vendored
@@ -17,12 +17,12 @@ jobs:
|
||||
run: |
|
||||
apt-get update && apt-get install -y rsync bc
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
path: "package"
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
repository: "hummingbird-project/hummingbird-docs"
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.7
|
||||
// swift-tools-version:5.9
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
@@ -13,5 +13,6 @@ let package = Package(
|
||||
targets: [
|
||||
.target(name: "Mustache", dependencies: []),
|
||||
.testTarget(name: "MustacheTests", dependencies: ["Mustache"]),
|
||||
]
|
||||
],
|
||||
swiftLanguageVersions: [.v5, .version("6")]
|
||||
)
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
Package for rendering Mustache templates. Mustache is a "logic-less" templating language commonly used in web and mobile platforms. You can find out more about Mustache [here](http://mustache.github.io/mustache.5.html).
|
||||
|
||||
> [!NOTE]
|
||||
> This repository is a fork of [hummingbird-project/swift-mustache](https://github.com/hummingbird-project/swift-mustache). It may contain modifications required by our other open source tools.
|
||||
|
||||
## Usage
|
||||
|
||||
Load your templates from the filesystem
|
||||
Load your templates from the filesystem
|
||||
```swift
|
||||
import Mustache
|
||||
let library = MustacheLibrary("folder/my/templates/are/in")
|
||||
```
|
||||
This will look for all the files with the extension ".mustache" in the specified folder and subfolders and attempt to load them. Each file is registed with the name of the file (with subfolder, if inside a subfolder) minus the "mustache" extension.
|
||||
|
||||
Render an object with a template
|
||||
Render an object with a template
|
||||
```swift
|
||||
let output = library.render(object, withTemplate: "myTemplate")
|
||||
```
|
||||
@@ -19,7 +22,7 @@ let output = library.render(object, withTemplate: "myTemplate")
|
||||
|
||||
## Support
|
||||
|
||||
Swift-Mustache supports all standard Mustache tags and is fully compliant with the Mustache [spec](https://github.com/mustache/spec) with the exception of the Lambda support.
|
||||
Swift-Mustache supports all standard Mustache tags and is fully compliant with the Mustache [spec](https://github.com/mustache/spec) with the exception of the Lambda support.
|
||||
|
||||
## Additional features
|
||||
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
import Foundation
|
||||
|
||||
/// Protocol for content types
|
||||
public protocol MustacheContentType: Sendable {
|
||||
@@ -38,8 +26,13 @@ struct HTMLContentType: MustacheContentType {
|
||||
/// the content type required. The default available types are `TEXT` and `HTML`. You can register your own
|
||||
/// with `MustacheContentTypes.register`.
|
||||
public enum MustacheContentTypes {
|
||||
|
||||
private static let lock = NSLock()
|
||||
|
||||
static func get(_ name: String) -> MustacheContentType? {
|
||||
self.types[name]
|
||||
lock.withLock {
|
||||
self.types[name]
|
||||
}
|
||||
}
|
||||
|
||||
/// Register new content type
|
||||
@@ -47,11 +40,19 @@ public enum MustacheContentTypes {
|
||||
/// - contentType: Content type
|
||||
/// - name: String to identify it
|
||||
public static func register(_ contentType: MustacheContentType, named name: String) {
|
||||
self.types[name] = contentType
|
||||
lock.withLock {
|
||||
self.types[name] = contentType
|
||||
}
|
||||
}
|
||||
|
||||
static var types: [String: MustacheContentType] = [
|
||||
private static let _types: [String: MustacheContentType] = [
|
||||
"HTML": HTMLContentType(),
|
||||
"TEXT": TextContentType(),
|
||||
]
|
||||
|
||||
#if compiler(>=6.0)
|
||||
nonisolated(unsafe) static var types: [String: MustacheContentType] = _types
|
||||
#else
|
||||
static var types: [String: MustacheContentType] = _types
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Context while rendering mustache tokens
|
||||
struct MustacheContext {
|
||||
let stack: [Any]
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Allow object to override standard hummingbird type rendering which uses
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Below is a list of unavailable symbols with the "HB" prefix. These are available
|
||||
// temporarily to ease transition from the old symbols that included the "HB"
|
||||
// prefix to the new ones.
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Lambda function. Can add this to object being rendered to filter contents of objects.
|
||||
///
|
||||
/// See http://mustache.github.io/mustache.5.html for more details on
|
||||
|
||||
@@ -1,22 +1,8 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension MustacheLibrary {
|
||||
/// Load templates from a folder
|
||||
static func loadTemplates(from directory: String, withExtension extension: String = "mustache") async throws -> [String: MustacheTemplate] {
|
||||
static func loadTemplates(from directory: String, withExtension extension: String = "mustache") throws -> [String: MustacheTemplate] {
|
||||
var directory = directory
|
||||
if !directory.hasSuffix("/") {
|
||||
directory += "/"
|
||||
@@ -31,7 +17,11 @@ extension MustacheLibrary {
|
||||
guard let template = try MustacheTemplate(filename: directory + path) else { continue }
|
||||
// drop ".mustache" from path to get name
|
||||
let name = String(path.dropLast(extWithDot.count))
|
||||
#if os(Windows)
|
||||
templates[name.replacingOccurrences(of: "\\", with: "/")] = template
|
||||
#else
|
||||
templates[name] = template
|
||||
#endif
|
||||
} catch let error as MustacheTemplate.ParserError {
|
||||
throw ParserError(filename: path, context: error.context, error: error.error)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Class holding a collection of mustache templates.
|
||||
///
|
||||
/// Each template can reference the others via a partial using the name the template is registered under
|
||||
@@ -39,7 +25,7 @@ public struct MustacheLibrary: Sendable {
|
||||
/// - Parameter directory: Directory to look for mustache templates
|
||||
/// - Parameter extension: Extension of files to look for
|
||||
public init(directory: String, withExtension extension: String = "mustache") async throws {
|
||||
self.templates = try await Self.loadTemplates(from: directory, withExtension: `extension`)
|
||||
self.templates = try Self.loadTemplates(from: directory, withExtension: `extension`)
|
||||
}
|
||||
|
||||
/// Register template under name
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension Mirror {
|
||||
/// Return value from Mirror given name
|
||||
func getValue(forKey key: String) -> Any? {
|
||||
|
||||
13
Sources/Mustache/NSLock+Backport.swift
Normal file
13
Sources/Mustache/NSLock+Backport.swift
Normal file
@@ -0,0 +1,13 @@
|
||||
#if compiler(<6.0)
|
||||
import Foundation
|
||||
|
||||
extension NSLock {
|
||||
func withLock<Value>(_ operation: () throws -> Value) rethrows -> Value {
|
||||
self.lock()
|
||||
defer {
|
||||
self.unlock()
|
||||
}
|
||||
return try operation()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Protocol for object that has a custom method for accessing their children, instead
|
||||
/// of using Mirror
|
||||
public protocol MustacheParent {
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Reader object for parsing String buffers
|
||||
@@ -303,7 +289,7 @@ extension Parser {
|
||||
}
|
||||
|
||||
/// context used in parser error
|
||||
public struct MustacheParserContext {
|
||||
public struct MustacheParserContext: Sendable {
|
||||
public let line: String
|
||||
public let lineNumber: Int
|
||||
public let columnNumber: Int
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Protocol for objects that can be rendered as a sequence in Mustache
|
||||
public protocol MustacheSequence: Sequence {}
|
||||
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Context that current object inside a sequence is being rendered in. Only relevant when rendering a sequence
|
||||
struct MustacheSequenceContext: MustacheTransformable {
|
||||
var first: Bool
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension String {
|
||||
private static let htmlEscapedCharacters: [Character: String] = [
|
||||
"<": "<",
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension MustacheTemplate {
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension MustacheTemplate {
|
||||
/// Error return by `MustacheTemplate.parse`. Includes information about where error occurred
|
||||
public struct ParserError: Swift.Error {
|
||||
@@ -441,7 +427,7 @@ extension MustacheTemplate {
|
||||
/// parse partial name
|
||||
static func parsePartialName(_ parser: inout Parser, state: ParserState) throws -> String {
|
||||
parser.read(while: \.isWhitespace)
|
||||
let text = String(parser.read(while: self.sectionNameChars))
|
||||
let text = String(parser.read(while: self.partialNameChars))
|
||||
parser.read(while: \.isWhitespace)
|
||||
guard try parser.read(string: state.endDelimiter) else { throw Error.unfinishedName }
|
||||
return text
|
||||
@@ -518,5 +504,5 @@ extension MustacheTemplate {
|
||||
|
||||
private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*")
|
||||
private static let sectionNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?()*")
|
||||
private static let partialNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_()")
|
||||
private static let partialNameChars = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?()*/")
|
||||
}
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension MustacheTemplate {
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Class holding Mustache template
|
||||
public struct MustacheTemplate: Sendable, CustomStringConvertible {
|
||||
/// Initialize template
|
||||
/// - Parameter string: Template text
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Objects that can have a transforms run on them. Mustache transforms are specific to this implementation
|
||||
/// of Mustache. They allow you to process objects before they are rendered.
|
||||
///
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2024 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import Mustache
|
||||
@@ -48,6 +34,24 @@ final class LibraryTests: XCTestCase {
|
||||
XCTAssertEqual(library.render(object, withTemplate: "test"), "<test><value>value1</value><value>value2</value></test>")
|
||||
}
|
||||
|
||||
func testPartialInSubfolder() async throws {
|
||||
let fs = FileManager()
|
||||
try? fs.createDirectory(atPath: "templates/subfolder", withIntermediateDirectories: true)
|
||||
let mustache = Data("<test>{{#value}}<value>{{.}}</value>{{/value}}</test>".utf8)
|
||||
try mustache.write(to: URL(fileURLWithPath: "templates/subfolder/test-partial.mustache"))
|
||||
let mustache2 = Data("{{>subfolder/test-partial}}".utf8)
|
||||
try mustache2.write(to: URL(fileURLWithPath: "templates/test.mustache"))
|
||||
defer {
|
||||
XCTAssertNoThrow(try fs.removeItem(atPath: "templates/subfolder/test-partial.mustache"))
|
||||
XCTAssertNoThrow(try fs.removeItem(atPath: "templates/test.mustache"))
|
||||
XCTAssertNoThrow(try fs.removeItem(atPath: "templates"))
|
||||
}
|
||||
|
||||
let library = try await MustacheLibrary(directory: "./templates")
|
||||
let object = ["value": ["value1", "value2"]]
|
||||
XCTAssertEqual(library.render(object, withTemplate: "test"), "<test><value>value1</value><value>value2</value></test>")
|
||||
}
|
||||
|
||||
func testLibraryParserError() async throws {
|
||||
let fs = FileManager()
|
||||
try? fs.createDirectory(atPath: "templates", withIntermediateDirectories: false)
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import Mustache
|
||||
@@ -23,7 +9,7 @@ final class PartialTests: XCTestCase {
|
||||
string: """
|
||||
<h2>Names</h2>
|
||||
{{#names}}
|
||||
{{> user}}
|
||||
{{> us/er}}
|
||||
{{/names}}
|
||||
"""
|
||||
)
|
||||
@@ -33,7 +19,7 @@ final class PartialTests: XCTestCase {
|
||||
|
||||
"""
|
||||
)
|
||||
let library = MustacheLibrary(templates: ["base": template, "user": template2])
|
||||
let library = MustacheLibrary(templates: ["base": template, "us/er": template2])
|
||||
|
||||
let object: [String: Any] = ["names": ["john", "adam", "claire"]]
|
||||
XCTAssertEqual(
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import Mustache
|
||||
@@ -65,11 +51,7 @@ extension MustacheTemplate {
|
||||
}
|
||||
}
|
||||
|
||||
#if hasFeature(RetroactiveAttribute)
|
||||
extension MustacheTemplate: @retroactive Equatable {}
|
||||
#else
|
||||
extension MustacheTemplate: Equatable {}
|
||||
#endif
|
||||
|
||||
extension MustacheTemplate.Token {
|
||||
public static func == (lhs: MustacheTemplate.Token, rhs: MustacheTemplate.Token) -> Bool {
|
||||
@@ -92,8 +74,4 @@ extension MustacheTemplate.Token {
|
||||
}
|
||||
}
|
||||
|
||||
#if hasFeature(RetroactiveAttribute)
|
||||
extension MustacheTemplate.Token: @retroactive Equatable {}
|
||||
#else
|
||||
extension MustacheTemplate.Token: Equatable {}
|
||||
#endif
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) 2021-2021 the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
|
||||
@@ -1,31 +1,4 @@
|
||||
#!/bin/bash
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the Hummingbird server framework project
|
||||
##
|
||||
## Copyright (c) 2021-2024 the Hummingbird authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the SwiftNIO open source project
|
||||
##
|
||||
## Copyright (c) 2017-2019 Apple Inc. and the SwiftNIO project authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
SWIFT_FORMAT_VERSION=0.53.10
|
||||
|
||||
set -eu
|
||||
@@ -49,78 +22,3 @@ if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
|
||||
else
|
||||
printf "\033[0;32mokay.\033[0m\n"
|
||||
fi
|
||||
printf "=> Checking license headers... "
|
||||
tmp=$(mktemp /tmp/.soto-core-sanity_XXXXXX)
|
||||
|
||||
exit 0
|
||||
|
||||
for language in swift-or-c; do
|
||||
declare -a matching_files
|
||||
declare -a exceptions
|
||||
expections=( )
|
||||
matching_files=( -name '*' )
|
||||
case "$language" in
|
||||
swift-or-c)
|
||||
exceptions=( -path '*/Benchmarks/.build/*' -o -name Package.swift)
|
||||
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
|
||||
cat > "$tmp" <<"EOF"
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Hummingbird server framework project
|
||||
//
|
||||
// Copyright (c) YEARS the Hummingbird authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
EOF
|
||||
;;
|
||||
bash)
|
||||
matching_files=( -name '*.sh' )
|
||||
cat > "$tmp" <<"EOF"
|
||||
##===----------------------------------------------------------------------===##
|
||||
##
|
||||
## This source file is part of the Hummingbird server framework project
|
||||
##
|
||||
## Copyright (c) YEARS the Hummingbird authors
|
||||
## Licensed under Apache License v2.0
|
||||
##
|
||||
## See LICENSE.txt for license information
|
||||
## See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
|
||||
##
|
||||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
EOF
|
||||
;;
|
||||
*)
|
||||
echo >&2 "ERROR: unknown language '$language'"
|
||||
;;
|
||||
esac
|
||||
|
||||
lines_to_compare=$(cat "$tmp" | wc -l | tr -d " ")
|
||||
# need to read one more line as we remove the '#!' line
|
||||
lines_to_read=$(expr "$lines_to_compare" + 1)
|
||||
expected_sha=$(cat "$tmp" | shasum)
|
||||
|
||||
(
|
||||
cd "$here/.."
|
||||
find . \
|
||||
\( \! -path './.build/*' -a \
|
||||
\( "${matching_files[@]}" \) -a \
|
||||
\( \! \( "${exceptions[@]}" \) \) \) | while read line; do
|
||||
if [[ "$(cat "$line" | head -n $lines_to_read | replace_acceptable_years | head -n $lines_to_compare | shasum)" != "$expected_sha" ]]; then
|
||||
printf "\033[0;31mmissing headers in file '$line'!\033[0m\n"
|
||||
diff -u <(cat "$line" | head -n $lines_to_read | replace_acceptable_years | head -n $lines_to_compare) "$tmp"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
printf "\033[0;32mokay.\033[0m\n"
|
||||
)
|
||||
done
|
||||
|
||||
rm "$tmp"
|
||||
|
||||
Reference in New Issue
Block a user