Skip to content

Vapor based side by side examples of pure Swift templating options: Leaf, Stencil, swift-html, and Swift Language (organic).

License

Notifications You must be signed in to change notification settings

VaporExamplesLab/eval-vapor-leaf-stencil

Repository files navigation

eval-vapor-leaf-stencil

Documentation MIT License Swift 4.2

The eval-vapor-leaf-stencil Vapor project provides some select HTML templating examples with Leaf, Stencil, swift-html DSL (Domain Specific Language), and Swift Programming Language (organic).

Approach

All approaches are setup to use the SwiftNIO EventLoopFuture<ResponseEncodable> (typealias Future<ResponseEncodable>). Three approaches (leaf, stencil, swiftlang) render a View for the ResponseEncodable. The swift-html renders a Html.Node for the ResponseEncodable.

Leaf /leaf/…

Stencil /stencil/…

swift-html DSL /swift-html/…

This approach extends Html.Node to be ResponseEncodable. Thus, the theses templates are rendered into an Html.Node instead of as a View.

Swift Organic /swiftlang/…

"Swift Organic" uses the Swift Programming Language swiftlang without any additional templating packages. This approach assembles a Swift String which is rendered to a Vapor ResponseEncodable View.

Cases

For each use case, replace /<approach> with one of /leaf, /stencil, /swift-html, or /swiftlang in the URL localhost:8080/<approach>/<usecase> URL. For example, the Leaf approach URL for the "Hello" use case would be localhost:8080/hello/Sunshine.

About /<approach>

The /<approach> routes provide some information About specific to each <approach>.

Hello /<approach>/hello/<somename>

Markdown Blog Entries

Example Blog Entries in Resources/HtmlParts/ were converted from Markdown to HTML with Pandoc.

##############
### PANDOC ###
##############
## http://pandoc.org/MANUAL.html#pandocs-markdown

OPTIONS="markdown_strict"
OPTIONS="$OPTIONS+pipe_tables"
OPTIONS="$OPTIONS+space_in_atx_header"
OPTIONS="$OPTIONS+blank_before_blockquote"
OPTIONS="$OPTIONS+backtick_code_blocks"
OPTIONS="$OPTIONS+tex_math_dollars"

pandoc \
  --from=$OPTIONS \
  --to=html5 \
  --mathjax \
  --output=math.html \
  math.md

HTML LaTeX Math /<approach>/math

Programming Blog Snippet /<approach>/codeblog

Markdown To HTML Elements /<approach>/mdtohtml

  • See how markdown elements render via the templates.
  • Determine if/when the HTML generated from Markdown needs modification to work with the template syntax.

Getting Started

Observations

Preliminary Setup

vapor new eval-vapor-leaf-stencil --web
cd eval-vapor-leaf-stencil

mkdir README_files 
touch README_files/.git_keep # create file so folder is not empty for `git`

vapor update -y

Resources

About

Vapor based side by side examples of pure Swift templating options: Leaf, Stencil, swift-html, and Swift Language (organic).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published