All Projects → AlwaysRightInstitute → Mustache

AlwaysRightInstitute / Mustache

Licence: Apache-2.0 license
A simple Mustache parser/evaluator for Swift

Programming Languages

swift
15916 projects
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to Mustache

Micromustache
Ⓜ An extremely fast and small sub-implementation of the {{mustache}} template engine for JavaScript
Stars: ✭ 186 (+708.7%)
Mutual labels:  mustache
Statik
Multi-purpose static web site generator aimed at developers.
Stars: ✭ 249 (+982.61%)
Mutual labels:  mustache
ocaml-mustache
mustache.js logic-less templates in OCaml
Stars: ✭ 74 (+221.74%)
Mutual labels:  mustache
Gluebert
gluebert.js is a tiny helper lazy loading DOM Elements, StyleSheets and JavaScript files using dynamic import and code splitting
Stars: ✭ 194 (+743.48%)
Mutual labels:  mustache
Stubble
Trimmed down {{mustache}} templates in .NET
Stars: ✭ 247 (+973.91%)
Mutual labels:  mustache
dssg
A static site generator with a different approach
Stars: ✭ 15 (-34.78%)
Mutual labels:  mustache
Pihole Kubernetes
PiHole on kubernetes
Stars: ✭ 180 (+682.61%)
Mutual labels:  mustache
mustache-cli
Command line interface to mustache template engine in Go.
Stars: ✭ 40 (+73.91%)
Mutual labels:  mustache
Mustache
Mustache text templates for modern C++
Stars: ✭ 248 (+978.26%)
Mutual labels:  mustache
php-mustache
Mustache PHP Extension
Stars: ✭ 55 (+139.13%)
Mutual labels:  mustache
Charts
Stars: ✭ 206 (+795.65%)
Mutual labels:  mustache
Chevron
A Python implementation of mustache
Stars: ✭ 223 (+869.57%)
Mutual labels:  mustache
abap mustache
Mustache template engine for ABAP
Stars: ✭ 14 (-39.13%)
Mutual labels:  mustache
Milk
Milk is Mustache in CoffeeScript -- great with your browser or NodeJS!
Stars: ✭ 192 (+734.78%)
Mutual labels:  mustache
samples
A collection of sample dashboards, custom labels, mustaches, SQL scripts and PowerShell scripts to help you get the most out of SquaredUp. #community-powered
Stars: ✭ 17 (-26.09%)
Mutual labels:  mustache
Swagger Codegen Generators
Stars: ✭ 184 (+700%)
Mutual labels:  mustache
VueXcode
Syntax highlighting for .Vue components and .mustache templates in Xcode
Stars: ✭ 25 (+8.7%)
Mutual labels:  mustache
HandlebarsCookbook
A cookbook of handlebars and mustache, focus on handlebars.js , mustache.js and lightncandy usage
Stars: ✭ 20 (-13.04%)
Mutual labels:  mustache
gogoAST
The simplest tool to parse/transform/generate code on ast
Stars: ✭ 29 (+26.09%)
Mutual labels:  mustache
hesperides
Configuration management tool providing universal text file templating and properties editing through a REST API or a webapp (backend part)
Stars: ✭ 35 (+52.17%)
Mutual labels:  mustache

Mustache

Swift4 Swift5 macOS tuxOS Build and Test

A simple Mustache parser/evaluator for Swift.

Mustache is a very simple templating language. Implementations are available for pretty much any programming language (check the Mustache website) - this is one for Swift.

In the context of Noze.io you don't need to call this manually, but you can just use the Mustache template support in the Noze.io Express module. Checkout the express-simple app as an example on how to do this.

This Mustache implementation comes with a very simple Key-Value coding implementation, which is used to extract values from model objects for rendering. With that you can render both, generic Dictionary/Array structures as well as Swift objects with properties. Since the reflection capabilities of Swift are pretty limited, so is the KVC implementation.

Example

Sample Mustache:

Hello {{name}}
You have just won {{& value}} dollars!
{{#in_ca}}
  Well, {{{taxed_value}}} dollars, after taxes.
{{/in_ca}}
{{#addresses}}
  Has address in: {{city}}
{{/addresses}}
{{^addresses}}
  Has NO addresses
{{/addresses}}

The template features value access: {{name}}, conditionals: {{#in_ca}}, as well as repetitions: {{#addresses}}.

Sample code to parse and evaluate the template:

let sampleDict  : [ String : Any ] = [
  "name"        : "Chris",
  "value"       : 10000,
  "taxed_value" : Int(10000 - (10000 * 0.4)),
  "in_ca"       : true,
  "addresses"   : [
    [ "city"    : "Cupertino" ]
  ]
]

var parser = MustacheParser()
let tree   = parser.parse(string: template)
let result = tree.render(object: sampleDict)

You get the idea.

Swift 5 Dynamic Callable

In Swift 5 you can expose Mustache templates as regular Swift functions.

To declare a Mustache backed function:

let generateHTMLForWinner = Mustache(
    """
    {% raw %}Hello {{name}}
    You have just won {{& value}} dollars!
    {{#in_ca}}
        Well, {{{taxed_value}}} dollars, after taxes.
    {{/in_ca}}
    {{#addresses}}
        Has address in: {{city}}
    {{/addresses}}
    {{^addresses}}
        Has NO addresses
    {{/addresses}}{% endraw %}
    """
)

To call the function:

let winners = [
    generateHTMLForWinner(
        name: "Chris", value: 10000,
        taxed_value: 6000, in_ca: true,
        addresses: [[ "city": "Cupertino" ]]
    ),
    generateHTMLForWinner(
        name: "Michael", value: 6000,
        taxed_value: 6000, in_ca: false,
        addresses: [[ "city": "Austin" ]]
    )
]

Checkout our blog for more info on this.

Who

mustache is brought to you by The Always Right Institute and ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of. We don't like people who are wrong.

Ask questions on the Noze.io Slack.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].