diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acf9d06..ba18949 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bd21b4f..3902bb8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`. diff --git a/Package.swift b/Package.swift index 7aaedd8..b82f3be 100644 --- a/Package.swift +++ b/Package.swift @@ -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"]), ] ) diff --git a/README.md b/README.md index 0cc4e35..bb3186c 100644 --- a/README.md +++ b/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) diff --git a/Sources/HummingbirdMustache/ContentType.swift b/Sources/Mustache/ContentType.swift similarity index 100% rename from Sources/HummingbirdMustache/ContentType.swift rename to Sources/Mustache/ContentType.swift diff --git a/Sources/HummingbirdMustache/Context.swift b/Sources/Mustache/Context.swift similarity index 100% rename from Sources/HummingbirdMustache/Context.swift rename to Sources/Mustache/Context.swift diff --git a/Sources/HummingbirdMustache/CustomRenderable.swift b/Sources/Mustache/CustomRenderable.swift similarity index 100% rename from Sources/HummingbirdMustache/CustomRenderable.swift rename to Sources/Mustache/CustomRenderable.swift diff --git a/Sources/HummingbirdMustache/Deprecations.swift b/Sources/Mustache/Deprecations.swift similarity index 100% rename from Sources/HummingbirdMustache/Deprecations.swift rename to Sources/Mustache/Deprecations.swift diff --git a/Sources/HummingbirdMustache/Lambda.swift b/Sources/Mustache/Lambda.swift similarity index 100% rename from Sources/HummingbirdMustache/Lambda.swift rename to Sources/Mustache/Lambda.swift diff --git a/Sources/HummingbirdMustache/Library+FileSystem.swift b/Sources/Mustache/Library+FileSystem.swift similarity index 100% rename from Sources/HummingbirdMustache/Library+FileSystem.swift rename to Sources/Mustache/Library+FileSystem.swift diff --git a/Sources/HummingbirdMustache/Library.swift b/Sources/Mustache/Library.swift similarity index 100% rename from Sources/HummingbirdMustache/Library.swift rename to Sources/Mustache/Library.swift diff --git a/Sources/HummingbirdMustache/Mirror.swift b/Sources/Mustache/Mirror.swift similarity index 100% rename from Sources/HummingbirdMustache/Mirror.swift rename to Sources/Mustache/Mirror.swift diff --git a/Sources/HummingbirdMustache/Parent.swift b/Sources/Mustache/Parent.swift similarity index 100% rename from Sources/HummingbirdMustache/Parent.swift rename to Sources/Mustache/Parent.swift diff --git a/Sources/HummingbirdMustache/Parser.swift b/Sources/Mustache/Parser.swift similarity index 100% rename from Sources/HummingbirdMustache/Parser.swift rename to Sources/Mustache/Parser.swift diff --git a/Sources/HummingbirdMustache/Sequence.swift b/Sources/Mustache/Sequence.swift similarity index 100% rename from Sources/HummingbirdMustache/Sequence.swift rename to Sources/Mustache/Sequence.swift diff --git a/Sources/HummingbirdMustache/SequenceContext.swift b/Sources/Mustache/SequenceContext.swift similarity index 100% rename from Sources/HummingbirdMustache/SequenceContext.swift rename to Sources/Mustache/SequenceContext.swift diff --git a/Sources/HummingbirdMustache/String.swift b/Sources/Mustache/String.swift similarity index 100% rename from Sources/HummingbirdMustache/String.swift rename to Sources/Mustache/String.swift diff --git a/Sources/HummingbirdMustache/Template+Parser.swift b/Sources/Mustache/Template+Parser.swift similarity index 100% rename from Sources/HummingbirdMustache/Template+Parser.swift rename to Sources/Mustache/Template+Parser.swift diff --git a/Sources/HummingbirdMustache/Template+Render.swift b/Sources/Mustache/Template+Render.swift similarity index 100% rename from Sources/HummingbirdMustache/Template+Render.swift rename to Sources/Mustache/Template+Render.swift diff --git a/Sources/HummingbirdMustache/Template.swift b/Sources/Mustache/Template.swift similarity index 100% rename from Sources/HummingbirdMustache/Template.swift rename to Sources/Mustache/Template.swift diff --git a/Sources/HummingbirdMustache/Transform.swift b/Sources/Mustache/Transform.swift similarity index 100% rename from Sources/HummingbirdMustache/Transform.swift rename to Sources/Mustache/Transform.swift diff --git a/Tests/HummingbirdMustacheTests/ErrorTests.swift b/Tests/MustacheTests/ErrorTests.swift similarity index 99% rename from Tests/HummingbirdMustacheTests/ErrorTests.swift rename to Tests/MustacheTests/ErrorTests.swift index daaeafe..42ccb4b 100644 --- a/Tests/HummingbirdMustacheTests/ErrorTests.swift +++ b/Tests/MustacheTests/ErrorTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -import HummingbirdMustache +import Mustache import XCTest final class ErrorTests: XCTestCase { diff --git a/Tests/HummingbirdMustacheTests/LibraryTests.swift b/Tests/MustacheTests/LibraryTests.swift similarity index 98% rename from Tests/HummingbirdMustacheTests/LibraryTests.swift rename to Tests/MustacheTests/LibraryTests.swift index d195b62..10f062d 100644 --- a/Tests/HummingbirdMustacheTests/LibraryTests.swift +++ b/Tests/MustacheTests/LibraryTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -@testable import HummingbirdMustache +@testable import Mustache import XCTest final class LibraryTests: XCTestCase { diff --git a/Tests/HummingbirdMustacheTests/PartialTests.swift b/Tests/MustacheTests/PartialTests.swift similarity index 99% rename from Tests/HummingbirdMustacheTests/PartialTests.swift rename to Tests/MustacheTests/PartialTests.swift index b296331..fda39c1 100644 --- a/Tests/HummingbirdMustacheTests/PartialTests.swift +++ b/Tests/MustacheTests/PartialTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -@testable import HummingbirdMustache +@testable import Mustache import XCTest final class PartialTests: XCTestCase { diff --git a/Tests/HummingbirdMustacheTests/SpecTests.swift b/Tests/MustacheTests/SpecTests.swift similarity index 99% rename from Tests/HummingbirdMustacheTests/SpecTests.swift rename to Tests/MustacheTests/SpecTests.swift index e563ddc..a07dc63 100644 --- a/Tests/HummingbirdMustacheTests/SpecTests.swift +++ b/Tests/MustacheTests/SpecTests.swift @@ -16,7 +16,7 @@ import Foundation #if os(Linux) import FoundationNetworking #endif -import HummingbirdMustache +import Mustache import XCTest public struct AnyDecodable: Decodable { diff --git a/Tests/HummingbirdMustacheTests/TemplateParserTests.swift b/Tests/MustacheTests/TemplateParserTests.swift similarity index 99% rename from Tests/HummingbirdMustacheTests/TemplateParserTests.swift rename to Tests/MustacheTests/TemplateParserTests.swift index 6c53ffe..e9f2380 100644 --- a/Tests/HummingbirdMustacheTests/TemplateParserTests.swift +++ b/Tests/MustacheTests/TemplateParserTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -@testable import HummingbirdMustache +@testable import Mustache import XCTest final class TemplateParserTests: XCTestCase { diff --git a/Tests/HummingbirdMustacheTests/TemplateRendererTests.swift b/Tests/MustacheTests/TemplateRendererTests.swift similarity index 99% rename from Tests/HummingbirdMustacheTests/TemplateRendererTests.swift rename to Tests/MustacheTests/TemplateRendererTests.swift index 0c6a29a..66c7852 100644 --- a/Tests/HummingbirdMustacheTests/TemplateRendererTests.swift +++ b/Tests/MustacheTests/TemplateRendererTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -import HummingbirdMustache +import Mustache import XCTest final class TemplateRendererTests: XCTestCase { diff --git a/Tests/HummingbirdMustacheTests/TransformTests.swift b/Tests/MustacheTests/TransformTests.swift similarity index 99% rename from Tests/HummingbirdMustacheTests/TransformTests.swift rename to Tests/MustacheTests/TransformTests.swift index 14d0e7c..26668bc 100644 --- a/Tests/HummingbirdMustacheTests/TransformTests.swift +++ b/Tests/MustacheTests/TransformTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -import HummingbirdMustache +import Mustache import XCTest final class TransformTests: XCTestCase { diff --git a/documentation/Mustache Syntax.md b/documentation/Mustache Syntax.md index a9b2c5c..bb9a294 100644 --- a/documentation/Mustache Syntax.md +++ b/documentation/Mustache Syntax.md @@ -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). diff --git a/documentation/Pragmas.md b/documentation/Pragmas.md index a79d431..2ff9464 100644 --- a/documentation/Pragmas.md +++ b/documentation/Pragmas.md @@ -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 `<>`.