Rename package to swift-mustache (#27)

* Rename package to swift-mustache

* Update CI
This commit is contained in:
Adam Fowler
2024-03-15 07:28:57 +00:00
committed by GitHub
parent bdfa05391a
commit 2663d13ea7
30 changed files with 19 additions and 42 deletions

View File

@@ -29,7 +29,7 @@ jobs:
- name: Convert coverage files - name: Convert coverage files
run: | run: |
llvm-cov export -format="lcov" \ llvm-cov export -format="lcov" \
.build/debug/hummingbird-mustachePackageTests.xctest \ .build/debug/swift-mustachePackageTests.xctest \
-ignore-filename-regex="\/Tests\/" \ -ignore-filename-regex="\/Tests\/" \
-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

View File

@@ -22,8 +22,6 @@ Please ensure to include the following in your Pull Request
- Documentation on how these changes are being tested - Documentation on how these changes are being tested
- Additional tests to show your code working and to ensure future changes don't break your code. - Additional tests to show your code working and to ensure future changes don't break your code.
Remember the requirements for Hummingbird and HummingbirdCore (No Foundation and no new dependencies). If you are submitting a large change to a module (or bringing in a new dependency) please consider making these changes in a separate repository. The idea is that Hummingbird/HummingbirdCore are kept as slimline as possible. These concerns can be discussed in a Github Issue.
Please keep your PRs to a minimal number of changes. If a PR is large try to split it up into smaller PRs. Don't move code around unnecessarily it makes comparing old with new very hard. Please keep your PRs to a minimal number of changes. If a PR is large try to split it up into smaller PRs. Don't move code around unnecessarily it makes comparing old with new very hard.
The main development branch of the repository is `main`. The main development branch of the repository is `main`.

View File

@@ -4,14 +4,14 @@
import PackageDescription import PackageDescription
let package = Package( let package = Package(
name: "hummingbird-mustache", name: "swift-mustache",
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)], platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
products: [ products: [
.library(name: "HummingbirdMustache", targets: ["HummingbirdMustache"]), .library(name: "Mustache", targets: ["Mustache"]),
], ],
dependencies: [], dependencies: [],
targets: [ targets: [
.target(name: "HummingbirdMustache", dependencies: []), .target(name: "Mustache", dependencies: []),
.testTarget(name: "HummingbirdMustacheTests", dependencies: ["HummingbirdMustache"]), .testTarget(name: "MustacheTests", dependencies: ["Mustache"]),
] ]
) )

View File

@@ -1,13 +1,12 @@
# HummingbirdMustache # Swift-Mustache
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).
While Hummingbird Mustache has been designed to be used with the Hummingbird server framework it has no dependencies and can be used as a standalone library.
## Usage ## Usage
Load your templates from the filesystem Load your templates from the filesystem
```swift ```swift
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.
@@ -16,35 +15,15 @@ Render an object with a template
```swift ```swift
let output = library.render(object, withTemplate: "myTemplate") let output = library.render(object, withTemplate: "myTemplate")
``` ```
`HummingbirdMustache` treats an object as a set of key/value pairs when rendering and will render both dictionaries and objects via `Mirror` reflection. Find out more on how Mustache renders objects [here](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/mustache-syntax.html). `Swift-Mustache` treats an object as a set of key/value pairs when rendering and will render both dictionaries and objects via `Mirror` reflection. Find out more on how Mustache renders objects [here](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/mustache-syntax.html).
### Using with Hummingbird
HummingbirdMustache doesn't have any integration with Hummingbird as I wanted to keep the library dependency free. But if you are going to use the library with Hummingbird it is recommended you extend `Application` to store an instance of your library.
```swift
extension Application {
var mustache: MustacheLibrary {
get { self.extensions.get(\.mustache) }
set { self.extensions.set(\.mustache, value: newValue) }
}
}
extension Request {
var mustache: MustacheLibrary { self.application.mustache }
}
// load mustache templates from templates folder
application.mustache = try .init(directory: "templates")
```
You can now access your mustache templates via `Request` eg `Request.mustache.render(obj, withTemplate: "myTemplate")`
## Support ## Support
Hummingbird 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
Hummingbird Mustache includes some features that are specific to its implementation. Please follow the links below to find out more. Swift-Mustache includes some features that are specific to its implementation. Please follow the links below to find out more.
- [Lambda Implementation](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/lambdas.html) - [Lambda Implementation](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/lambdas.html)
- [Transforms](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/transforms.html) - [Transforms](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/transforms.html)

View File

@@ -12,7 +12,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
import HummingbirdMustache import Mustache
import XCTest import XCTest
final class ErrorTests: XCTestCase { final class ErrorTests: XCTestCase {

View File

@@ -12,7 +12,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@testable import HummingbirdMustache @testable import Mustache
import XCTest import XCTest
final class LibraryTests: XCTestCase { final class LibraryTests: XCTestCase {

View File

@@ -12,7 +12,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@testable import HummingbirdMustache @testable import Mustache
import XCTest import XCTest
final class PartialTests: XCTestCase { final class PartialTests: XCTestCase {

View File

@@ -16,7 +16,7 @@ import Foundation
#if os(Linux) #if os(Linux)
import FoundationNetworking import FoundationNetworking
#endif #endif
import HummingbirdMustache import Mustache
import XCTest import XCTest
public struct AnyDecodable: Decodable { public struct AnyDecodable: Decodable {

View File

@@ -12,7 +12,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@testable import HummingbirdMustache @testable import Mustache
import XCTest import XCTest
final class TemplateParserTests: XCTestCase { final class TemplateParserTests: XCTestCase {

View File

@@ -12,7 +12,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
import HummingbirdMustache import Mustache
import XCTest import XCTest
final class TemplateRendererTests: XCTestCase { final class TemplateRendererTests: XCTestCase {

View File

@@ -12,7 +12,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
import HummingbirdMustache import Mustache
import XCTest import XCTest
final class TransformTests: XCTestCase { final class TransformTests: XCTestCase {

View File

@@ -33,7 +33,7 @@ If you want to only search for values in the context at the top of the stack the
- `{{#section}}`: Section render blocks either render text once or multiple times depending on the value of the key in the current context. A section begins with `{{#section}}` and end with `{{/section}}`. If the key represents a `Bool` value it will only render if it is true. If the key represents an `Optional` it will only render if the object is non-nil. If the key represents an `Array` it will then render the internals of the section multiple times, once for each element of the `Array`. Otherwise it will render with the selected value pushed onto the top of the context stack. - `{{#section}}`: Section render blocks either render text once or multiple times depending on the value of the key in the current context. A section begins with `{{#section}}` and end with `{{/section}}`. If the key represents a `Bool` value it will only render if it is true. If the key represents an `Optional` it will only render if the object is non-nil. If the key represents an `Array` it will then render the internals of the section multiple times, once for each element of the `Array`. Otherwise it will render with the selected value pushed onto the top of the context stack.
- `{{^section}}`: An inverted section does the opposite of a section. If the key represents a `Bool` value it will render if it is false. If the key represents an `Optional` it will render if it is `nil`. If the key represents a `Array` it will render if the `Array` is empty. - `{{^section}}`: An inverted section does the opposite of a section. If the key represents a `Bool` value it will render if it is false. If the key represents an `Optional` it will render if it is `nil`. If the key represents a `Array` it will render if the `Array` is empty.
- `{{! comment }}`: This is a comment tag and is ignored. - `{{! comment }}`: This is a comment tag and is ignored.
- `{{> partial}}`: A partial tag renders another mustache file, with the current context stack. In Hummingbird Mustache partial tags only work for templates that are a part of a library and the tag is the name of the referenced file without the ".mustache" extension. - `{{> partial}}`: A partial tag renders another mustache file, with the current context stack. In swift-mustache partial tags only work for templates that are a part of a library and the tag is the name of the referenced file without the ".mustache" extension.
- `{{=<% %>=}}`: The set delimiter tag allows you to change from using the double curly brackets as tag delimiters. In the example the delimiters have been changed to `<% %>` but you can change them to whatever you like. - `{{=<% %>=}}`: The set delimiter tag allows you to change from using the double curly brackets as tag delimiters. In the example the delimiters have been changed to `<% %>` but you can change them to whatever you like.
You can find out more about the standard Mustache tags in the [Mustache Manual](https://mustache.github.io/mustache.5.html). You can find out more about the standard Mustache tags in the [Mustache Manual](https://mustache.github.io/mustache.5.html).

View File

@@ -1,6 +1,6 @@
# Pragmas/Configuration variables # Pragmas/Configuration variables
The syntax `{{% var: value}}` can be used to set template rendering configuration variables specific to Hummingbird Mustache. The only variable you can set at the moment is `CONTENT_TYPE`. This can be set to either to `HTML` or `TEXT` and defines how variables are escaped. A content type of `TEXT` means no variables are escaped and a content type of `HTML` will do HTML escaping of the rendered text. The content type defaults to `HTML`. The syntax `{{% var: value}}` can be used to set template rendering configuration variables specific to swift-mustache. The only variable you can set at the moment is `CONTENT_TYPE`. This can be set to either to `HTML` or `TEXT` and defines how variables are escaped. A content type of `TEXT` means no variables are escaped and a content type of `HTML` will do HTML escaping of the rendered text. The content type defaults to `HTML`.
Given input object "<>", template `{{%CONTENT_TYPE: HTML}}{{.}}` will render as `&lt;&gt;` and `{{%CONTENT_TYPE: TEXT}}{{.}}` will render as `<>`. Given input object "<>", template `{{%CONTENT_TYPE: HTML}}{{.}}` will render as `&lt;&gt;` and `{{%CONTENT_TYPE: TEXT}}{{.}}` will render as `<>`.