Swiftpack.co - Package - stencilproject/Stencil

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

stencilproject/Stencil

Stencil is a simple and powerful template language for Swift.

Stencil

Build Status

Stencil is a simple and powerful template language for Swift. It provides a syntax similar to Django and Mustache. If you're familiar with these, you will feel right at home with Stencil.

Example

There are {{ articles.count }} articles.

<ul>
  {% for article in articles %}
    <li>{{ article.title }} by {{ article.author }}</li>
  {% endfor %}
</ul>
import Stencil

struct Article {
  let title: String
  let author: String
}

let context = [
  "articles": [
    Article(title: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
    Article(title: "Memory Management with ARC", author: "Kyle Fuller"),
  ]
]

let environment = Environment(loader: FileSystemLoader(paths: ["templates/"]))
let rendered = try environment.renderTemplate(name: "article_list.html", context: context)

print(rendered)

Philosophy

Stencil follows the same philosophy of Django:

If you have a background in programming, or if you’re used to languages which mix programming code directly into HTML, you’ll want to bear in mind that the Django template system is not simply Python embedded into HTML. This is by design: the template system is meant to express presentation, not program logic.

The User Guide

Resources for Stencil template authors to write Stencil templates:

Resources to help you integrate Stencil into a Swift project:

Projects that use Stencil

Sourcery, SwiftGen, Kitura, Weaver, Genesis

License

Stencil is licensed under the BSD license. See LICENSE for more info.

Github

link
Stars: 1932
Last commit: 2 weeks ago

Releases

0.14.0 - 2020-08-17T18:45:21

Breaking

  • Drop support for Swift < 4.2. For Swift 4 support, you should use Stencil 0.13.1.
    David Jennes #294

Enhancements

  • Added support for dynamic filter using filter filter. With that you can define a variable with a name of filter , i.e. myfilter = "uppercase" and then use it to invoke this filter with {{ string|filter:myfilter }}.
    Ilya Puchka #203

Deprecations

None

Bug Fixes

  • Fixed using parenthesis in boolean expressions, they now can be used without spaces around them.
    Ilya Puchka #254
  • Throw syntax error on empty variable tags ({{ }}) instead fatalError.
    Ilya Puchka #263

Internal Changes