Compare commits
10 Commits
e57f85ff19
...
040862a0c0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
040862a0c0 | ||
|
|
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: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
|
ignore:
|
||||||
|
- dependency-name: "codecov/codecov-action"
|
||||||
|
update-types: ["version-update:semver-major"]
|
||||||
groups:
|
groups:
|
||||||
dependencies:
|
dependencies:
|
||||||
patterns:
|
patterns:
|
||||||
|
|||||||
2
.github/workflows/api-breakage.yml
vendored
2
.github/workflows/api-breakage.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
image: swift:latest
|
image: swift:latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
# https://github.com/actions/checkout/issues/766
|
# 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
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: SPM tests
|
- name: SPM tests
|
||||||
run: swift test --enable-code-coverage
|
run: swift test --enable-code-coverage
|
||||||
- name: Convert coverage files
|
- name: Convert coverage files
|
||||||
@@ -30,20 +30,21 @@ jobs:
|
|||||||
-ignore-filename-regex="\/Benchmarks\/" \
|
-ignore-filename-regex="\/Benchmarks\/" \
|
||||||
-instr-profile=.build/debug/codecov/default.profdata > info.lcov
|
-instr-profile=.build/debug/codecov/default.profdata > info.lcov
|
||||||
- name: Upload to codecov.io
|
- name: Upload to codecov.io
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
files: info.lcov
|
files: info.lcov
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
linux:
|
linux:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
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:
|
container:
|
||||||
image: ${{ matrix.image }}
|
image: ${{ matrix.image }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
swift test --enable-code-coverage
|
swift test --enable-code-coverage
|
||||||
@@ -55,18 +56,19 @@ jobs:
|
|||||||
-ignore-filename-regex="\/Benchmarks\/" \
|
-ignore-filename-regex="\/Benchmarks\/" \
|
||||||
-instr-profile .build/debug/codecov/default.profdata > info.lcov
|
-instr-profile .build/debug/codecov/default.profdata > info.lcov
|
||||||
- name: Upload to codecov.io
|
- name: Upload to codecov.io
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v4
|
||||||
with:
|
with:
|
||||||
files: info.lcov
|
files: info.lcov
|
||||||
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
windows:
|
windows:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
swift-version: ["6.0"]
|
swift-version: ["6.1"]
|
||||||
steps:
|
steps:
|
||||||
- uses: compnerd/gha-setup-swift@main
|
- uses: compnerd/gha-setup-swift@main
|
||||||
with:
|
with:
|
||||||
branch: swift-${{ matrix.swift-version }}-release
|
branch: swift-${{ matrix.swift-version }}-release
|
||||||
tag: ${{ matrix.swift-version }}-RELEASE
|
tag: ${{ matrix.swift-version }}-RELEASE
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- run: swift test
|
- 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 }}
|
image: swiftlang/swift:${{ matrix.image }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
swift test
|
swift test
|
||||||
|
|||||||
2
.github/workflows/validate.yml
vendored
2
.github/workflows/validate.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
|||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 1
|
||||||
- name: run script
|
- name: run script
|
||||||
|
|||||||
4
.github/workflows/verify-documentation.yml
vendored
4
.github/workflows/verify-documentation.yml
vendored
@@ -17,12 +17,12 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
apt-get update && apt-get install -y rsync bc
|
apt-get update && apt-get install -y rsync bc
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
path: "package"
|
path: "package"
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
repository: "hummingbird-project/hummingbird-docs"
|
repository: "hummingbird-project/hummingbird-docs"
|
||||||
fetch-depth: 0
|
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.
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
@@ -13,5 +13,6 @@ let package = Package(
|
|||||||
targets: [
|
targets: [
|
||||||
.target(name: "Mustache", dependencies: []),
|
.target(name: "Mustache", dependencies: []),
|
||||||
.testTarget(name: "MustacheTests", dependencies: ["Mustache"]),
|
.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).
|
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
|
## Usage
|
||||||
|
|
||||||
Load your templates from the filesystem
|
Load your templates from the filesystem
|
||||||
```swift
|
```swift
|
||||||
import Mustache
|
import Mustache
|
||||||
let library = MustacheLibrary("folder/my/templates/are/in")
|
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.
|
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
|
```swift
|
||||||
let output = library.render(object, withTemplate: "myTemplate")
|
let output = library.render(object, withTemplate: "myTemplate")
|
||||||
```
|
```
|
||||||
@@ -19,7 +22,7 @@ let output = library.render(object, withTemplate: "myTemplate")
|
|||||||
|
|
||||||
## Support
|
## 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
|
## Additional features
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
import Foundation
|
||||||
//
|
|
||||||
// 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 content types
|
/// Protocol for content types
|
||||||
public protocol MustacheContentType: Sendable {
|
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
|
/// the content type required. The default available types are `TEXT` and `HTML`. You can register your own
|
||||||
/// with `MustacheContentTypes.register`.
|
/// with `MustacheContentTypes.register`.
|
||||||
public enum MustacheContentTypes {
|
public enum MustacheContentTypes {
|
||||||
|
|
||||||
|
private static let lock = NSLock()
|
||||||
|
|
||||||
static func get(_ name: String) -> MustacheContentType? {
|
static func get(_ name: String) -> MustacheContentType? {
|
||||||
self.types[name]
|
lock.withLock {
|
||||||
|
self.types[name]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register new content type
|
/// Register new content type
|
||||||
@@ -47,11 +40,19 @@ public enum MustacheContentTypes {
|
|||||||
/// - contentType: Content type
|
/// - contentType: Content type
|
||||||
/// - name: String to identify it
|
/// - name: String to identify it
|
||||||
public static func register(_ contentType: MustacheContentType, named name: String) {
|
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(),
|
"HTML": HTMLContentType(),
|
||||||
"TEXT": TextContentType(),
|
"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
|
/// Context while rendering mustache tokens
|
||||||
struct MustacheContext {
|
struct MustacheContext {
|
||||||
let stack: [Any]
|
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
|
import Foundation
|
||||||
|
|
||||||
/// Allow object to override standard hummingbird type rendering which uses
|
/// 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
|
// 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"
|
// temporarily to ease transition from the old symbols that included the "HB"
|
||||||
// prefix to the new ones.
|
// 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.
|
/// 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
|
/// 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
|
import Foundation
|
||||||
|
|
||||||
extension MustacheLibrary {
|
extension MustacheLibrary {
|
||||||
/// Load templates from a folder
|
/// 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
|
var directory = directory
|
||||||
if !directory.hasSuffix("/") {
|
if !directory.hasSuffix("/") {
|
||||||
directory += "/"
|
directory += "/"
|
||||||
@@ -31,7 +17,11 @@ extension MustacheLibrary {
|
|||||||
guard let template = try MustacheTemplate(filename: directory + path) else { continue }
|
guard let template = try MustacheTemplate(filename: directory + path) else { continue }
|
||||||
// drop ".mustache" from path to get name
|
// drop ".mustache" from path to get name
|
||||||
let name = String(path.dropLast(extWithDot.count))
|
let name = String(path.dropLast(extWithDot.count))
|
||||||
|
#if os(Windows)
|
||||||
|
templates[name.replacingOccurrences(of: "\\", with: "/")] = template
|
||||||
|
#else
|
||||||
templates[name] = template
|
templates[name] = template
|
||||||
|
#endif
|
||||||
} catch let error as MustacheTemplate.ParserError {
|
} catch let error as MustacheTemplate.ParserError {
|
||||||
throw ParserError(filename: path, context: error.context, error: error.error)
|
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.
|
/// Class holding a collection of mustache templates.
|
||||||
///
|
///
|
||||||
/// Each template can reference the others via a partial using the name the template is registered under
|
/// 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 directory: Directory to look for mustache templates
|
||||||
/// - Parameter extension: Extension of files to look for
|
/// - Parameter extension: Extension of files to look for
|
||||||
public init(directory: String, withExtension extension: String = "mustache") async throws {
|
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
|
/// 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 {
|
extension Mirror {
|
||||||
/// Return value from Mirror given name
|
/// Return value from Mirror given name
|
||||||
func getValue(forKey key: String) -> Any? {
|
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
|
/// Protocol for object that has a custom method for accessing their children, instead
|
||||||
/// of using Mirror
|
/// of using Mirror
|
||||||
public protocol MustacheParent {
|
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
|
import Foundation
|
||||||
|
|
||||||
/// Reader object for parsing String buffers
|
/// Reader object for parsing String buffers
|
||||||
@@ -303,7 +289,7 @@ extension Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// context used in parser error
|
/// context used in parser error
|
||||||
public struct MustacheParserContext {
|
public struct MustacheParserContext: Sendable {
|
||||||
public let line: String
|
public let line: String
|
||||||
public let lineNumber: Int
|
public let lineNumber: Int
|
||||||
public let columnNumber: 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
|
/// Protocol for objects that can be rendered as a sequence in Mustache
|
||||||
public protocol MustacheSequence: Sequence {}
|
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
|
/// Context that current object inside a sequence is being rendered in. Only relevant when rendering a sequence
|
||||||
struct MustacheSequenceContext: MustacheTransformable {
|
struct MustacheSequenceContext: MustacheTransformable {
|
||||||
var first: Bool
|
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 {
|
extension String {
|
||||||
private static let htmlEscapedCharacters: [Character: 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
|
import Foundation
|
||||||
|
|
||||||
extension MustacheTemplate {
|
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 {
|
extension MustacheTemplate {
|
||||||
/// Error return by `MustacheTemplate.parse`. Includes information about where error occurred
|
/// Error return by `MustacheTemplate.parse`. Includes information about where error occurred
|
||||||
public struct ParserError: Swift.Error {
|
public struct ParserError: Swift.Error {
|
||||||
@@ -441,7 +427,7 @@ extension MustacheTemplate {
|
|||||||
/// parse partial name
|
/// parse partial name
|
||||||
static func parsePartialName(_ parser: inout Parser, state: ParserState) throws -> String {
|
static func parsePartialName(_ parser: inout Parser, state: ParserState) throws -> String {
|
||||||
parser.read(while: \.isWhitespace)
|
parser.read(while: \.isWhitespace)
|
||||||
let text = String(parser.read(while: self.sectionNameChars))
|
let text = String(parser.read(while: self.partialNameChars))
|
||||||
parser.read(while: \.isWhitespace)
|
parser.read(while: \.isWhitespace)
|
||||||
guard try parser.read(string: state.endDelimiter) else { throw Error.unfinishedName }
|
guard try parser.read(string: state.endDelimiter) else { throw Error.unfinishedName }
|
||||||
return text
|
return text
|
||||||
@@ -518,5 +504,5 @@ extension MustacheTemplate {
|
|||||||
|
|
||||||
private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*")
|
private static let sectionNameCharsWithoutBrackets = Set<Character>("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_?*")
|
||||||
private static let sectionNameChars = 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
|
import Foundation
|
||||||
|
|
||||||
extension MustacheTemplate {
|
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 {
|
public struct MustacheTemplate: Sendable, CustomStringConvertible {
|
||||||
/// Initialize template
|
/// Initialize template
|
||||||
/// - Parameter string: Template text
|
/// - 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
|
/// 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.
|
/// 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 Mustache
|
||||||
import XCTest
|
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
|
import XCTest
|
||||||
|
|
||||||
@testable import Mustache
|
@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>")
|
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 {
|
func testLibraryParserError() async throws {
|
||||||
let fs = FileManager()
|
let fs = FileManager()
|
||||||
try? fs.createDirectory(atPath: "templates", withIntermediateDirectories: false)
|
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
|
import XCTest
|
||||||
|
|
||||||
@testable import Mustache
|
@testable import Mustache
|
||||||
@@ -23,7 +9,7 @@ final class PartialTests: XCTestCase {
|
|||||||
string: """
|
string: """
|
||||||
<h2>Names</h2>
|
<h2>Names</h2>
|
||||||
{{#names}}
|
{{#names}}
|
||||||
{{> user}}
|
{{> us/er}}
|
||||||
{{/names}}
|
{{/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"]]
|
let object: [String: Any] = ["names": ["john", "adam", "claire"]]
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
@@ -118,17 +104,17 @@ final class PartialTests: XCTestCase {
|
|||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
library.render(object, withTemplate: "base1"),
|
library.render(object, withTemplate: "base1"),
|
||||||
"""
|
"""
|
||||||
1, 2, 3, 4, 5,
|
1, 2, 3, 4, 5,
|
||||||
>> 1, 2, 3, 4, 5,
|
>> 1, 2, 3, 4, 5,
|
||||||
|
|
||||||
[ 1, 2, 3, 4, 5,
|
[ 1, 2, 3, 4, 5,
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
XCTAssertEqual(
|
XCTAssertEqual(
|
||||||
library.render(object, withTemplate: "base2"),
|
library.render(object, withTemplate: "base2"),
|
||||||
"""
|
"""
|
||||||
1, 2, 3, 4, 5, >> 1, 2, 3, 4, 5,
|
1, 2, 3, 4, 5, >> 1, 2, 3, 4, 5,
|
||||||
[ 1, 2, 3, 4, 5, ]
|
[ 1, 2, 3, 4, 5, ]
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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 Foundation
|
||||||
import Mustache
|
import Mustache
|
||||||
import XCTest
|
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
|
import XCTest
|
||||||
|
|
||||||
@testable import Mustache
|
@testable import Mustache
|
||||||
@@ -65,11 +51,7 @@ extension MustacheTemplate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if hasFeature(RetroactiveAttribute)
|
|
||||||
extension MustacheTemplate: @retroactive Equatable {}
|
|
||||||
#else
|
|
||||||
extension MustacheTemplate: Equatable {}
|
extension MustacheTemplate: Equatable {}
|
||||||
#endif
|
|
||||||
|
|
||||||
extension MustacheTemplate.Token {
|
extension MustacheTemplate.Token {
|
||||||
public static func == (lhs: MustacheTemplate.Token, rhs: MustacheTemplate.Token) -> Bool {
|
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 {}
|
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 Mustache
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
@@ -207,8 +193,8 @@ final class TemplateRendererTests: XCTestCase {
|
|||||||
template.render(object),
|
template.render(object),
|
||||||
"""
|
"""
|
||||||
* Chris & Friends
|
* Chris & Friends
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* <b>GitHub</b>
|
* <b>GitHub</b>
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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 Mustache
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/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
|
SWIFT_FORMAT_VERSION=0.53.10
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
@@ -49,78 +22,3 @@ if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
|
|||||||
else
|
else
|
||||||
printf "\033[0;32mokay.\033[0m\n"
|
printf "\033[0;32mokay.\033[0m\n"
|
||||||
fi
|
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