refactor: Revamp docs to separate template writers/devs

This commit is contained in:
Kyle Fuller
2016-12-01 01:30:33 +00:00
parent 9e2a061795
commit f90597fba1
9 changed files with 240 additions and 148 deletions

37
docs/getting-started.rst Normal file
View File

@@ -0,0 +1,37 @@
Getting Started
===============
The easiest way to render a template using Stencil is to create a template and
call render on it providing a context.
.. code-block:: swift
let template = Template(templateString: "Hello {{ name }}")
try template.render(["name": "kyle"])
For more advanced uses, you would normally create an ``Environment`` and call
the ``renderTemplate`` convinience method.
.. code-block:: swift
let environment = Environment()
let context = ["name": "kyle"]
try template.renderTemplate(string: "Hello {{ name }}", context: context)
Template Loaders
----------------
A template loader allows you to load files from disk or elsewhere. Using a
``FileSystemLoader`` we can easily render a template from disk.
For example, to render a template called ``index.html`` inside the
``templates/`` directory we can use the following:
.. code-block:: swift
let fsLoader = FileSystemLoader(paths: ["templates/"])
let environment = Environment(loader: fsLoader)
let context = ["name": "kyle"]
try template.renderTemplate(name: "index.html", context: context)