Files
swiftpm-stencil/README.md
2016-11-28 03:15:56 +00:00

1.7 KiB
Raw Blame History

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.

{% for article in articles %}
  - {{ article.title }} by {{ article.author }}.
{% endfor %}
let context = Context(dictionary: [
  "articles": [
    [ "title": "Migrating from OCUnit to XCTest", "author": "Kyle Fuller" ],
    [ "title": "Memory Management with ARC", "author": "Kyle Fuller" ],
  ]
])

do {
  let template = try Template(named: "template.stencil")
  let rendered = try template.render(context)
  print(rendered)
} catch {
  print("Failed to render template \(error)")
}

Installation

Installation with CocoaPods is recommended.

pod 'Stencil'

Philosophy

Stencil follows the same philosophy of Django:

If you have a background in programming, or if youre used to languages which mix programming code directly into HTML, youll 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

License

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