Rename package to swift-mustache (#27)
* Rename package to swift-mustache * Update CI
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -29,7 +29,7 @@ jobs:
|
||||
- name: Convert coverage files
|
||||
run: |
|
||||
llvm-cov export -format="lcov" \
|
||||
.build/debug/hummingbird-mustachePackageTests.xctest \
|
||||
.build/debug/swift-mustachePackageTests.xctest \
|
||||
-ignore-filename-regex="\/Tests\/" \
|
||||
-ignore-filename-regex="\/Benchmarks\/" \
|
||||
-instr-profile .build/debug/codecov/default.profdata > info.lcov
|
||||
|
||||
@@ -22,8 +22,6 @@ Please ensure to include the following in your Pull Request
|
||||
- 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.
|
||||
|
||||
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.
|
||||
|
||||
The main development branch of the repository is `main`.
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "hummingbird-mustache",
|
||||
name: "swift-mustache",
|
||||
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
|
||||
products: [
|
||||
.library(name: "HummingbirdMustache", targets: ["HummingbirdMustache"]),
|
||||
.library(name: "Mustache", targets: ["Mustache"]),
|
||||
],
|
||||
dependencies: [],
|
||||
targets: [
|
||||
.target(name: "HummingbirdMustache", dependencies: []),
|
||||
.testTarget(name: "HummingbirdMustacheTests", dependencies: ["HummingbirdMustache"]),
|
||||
.target(name: "Mustache", dependencies: []),
|
||||
.testTarget(name: "MustacheTests", dependencies: ["Mustache"]),
|
||||
]
|
||||
)
|
||||
|
||||
31
README.md
31
README.md
@@ -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).
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
@@ -16,35 +15,15 @@ Render an object with a template
|
||||
```swift
|
||||
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).
|
||||
|
||||
### 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")`
|
||||
`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).
|
||||
|
||||
## 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
|
||||
|
||||
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)
|
||||
- [Transforms](https://hummingbird-project.github.io/hummingbird/current/hummingbird-mustache/transforms.html)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import HummingbirdMustache
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
final class ErrorTests: XCTestCase {
|
||||
@@ -12,7 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@testable import HummingbirdMustache
|
||||
@testable import Mustache
|
||||
import XCTest
|
||||
|
||||
final class LibraryTests: XCTestCase {
|
||||
@@ -12,7 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@testable import HummingbirdMustache
|
||||
@testable import Mustache
|
||||
import XCTest
|
||||
|
||||
final class PartialTests: XCTestCase {
|
||||
@@ -16,7 +16,7 @@ import Foundation
|
||||
#if os(Linux)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
import HummingbirdMustache
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
public struct AnyDecodable: Decodable {
|
||||
@@ -12,7 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@testable import HummingbirdMustache
|
||||
@testable import Mustache
|
||||
import XCTest
|
||||
|
||||
final class TemplateParserTests: XCTestCase {
|
||||
@@ -12,7 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import HummingbirdMustache
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
final class TemplateRendererTests: XCTestCase {
|
||||
@@ -12,7 +12,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import HummingbirdMustache
|
||||
import Mustache
|
||||
import XCTest
|
||||
|
||||
final class TransformTests: XCTestCase {
|
||||
@@ -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}}`: 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.
|
||||
- `{{> 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.
|
||||
|
||||
You can find out more about the standard Mustache tags in the [Mustache Manual](https://mustache.github.io/mustache.5.html).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 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 `<>` and `{{%CONTENT_TYPE: TEXT}}{{.}}` will render as `<>`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user