All Projects → valotas → Mustache4dart

valotas / Mustache4dart

Licence: other
mustache implementation for Dart

Programming Languages

dart
5743 projects
dartlang
94 projects

Labels

Projects that are alternatives of or similar to Mustache4dart

Banzai Charts
Curated list of Banzai Cloud Helm charts used by the Pipeline Platform
Stars: ✭ 312 (+339.44%)
Mutual labels:  mustache
Harbor Helm
The helm chart to deploy Harbor
Stars: ✭ 647 (+811.27%)
Mutual labels:  mustache
Elastalert Docker
Simple Dockerfile for building a Kubernetes and Elastalert Helm compatible Docker image.
Stars: ✭ 54 (-23.94%)
Mutual labels:  mustache
Client
The Hypothesis web-based annotation client.
Stars: ✭ 416 (+485.92%)
Mutual labels:  mustache
Lightncandy
An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
Stars: ✭ 565 (+695.77%)
Mutual labels:  mustache
Mustache
A simple Mustache parser/evaluator for Swift
Stars: ✭ 20 (-71.83%)
Mutual labels:  mustache
Helm Charts
A curated set of Helm charts brought to you by codecentric
Stars: ✭ 295 (+315.49%)
Mutual labels:  mustache
Mustache
Mustache templating language in Go
Stars: ✭ 57 (-19.72%)
Mutual labels:  mustache
Mormot
Synopse mORMot ORM/SOA/MVC framework
Stars: ✭ 607 (+754.93%)
Mutual labels:  mustache
K8s Minecraft
Running a Minecraft server in Kubernetes
Stars: ✭ 37 (-47.89%)
Mutual labels:  mustache
Charts
Helm charts for applications you run at home
Stars: ✭ 421 (+492.96%)
Mutual labels:  mustache
Grmustache.swift
Flexible Mustache templates for Swift
Stars: ✭ 538 (+657.75%)
Mutual labels:  mustache
Pomerium Helm
Official helm charts for Pomerium.
Stars: ✭ 32 (-54.93%)
Mutual labels:  mustache
Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (+354.93%)
Mutual labels:  mustache
Charts
Community managed Helm charts for running Falco with Kubernetes
Stars: ✭ 55 (-22.54%)
Mutual labels:  mustache
Universe
The Mesosphere Universe package repository.
Stars: ✭ 308 (+333.8%)
Mutual labels:  mustache
Handlebars.net
A real .NET Handlebars engine
Stars: ✭ 723 (+918.31%)
Mutual labels:  mustache
Choerodon Front
Choerodon Front is a total front-end of Choerodon that combines Choerodon IAM and Choerodon DevOps.
Stars: ✭ 62 (-12.68%)
Mutual labels:  mustache
Connect Api Specification
This repository contains the OpenAPI specification as well as templates for generating SDKs for Square's APIs
Stars: ✭ 56 (-21.13%)
Mutual labels:  mustache
Helm Charts
Prometheus community Helm charts
Stars: ✭ 962 (+1254.93%)
Mutual labels:  mustache

Mustache for Dart

Build Status Coverage Status

A simple implementation of Mustache for the Dart language, which passes happily all the mustache v1.1.2+λ specs. If you want to have a look at how it works, just check the tests. For more info, just read further.

Using it

In order to use the library, just add it to your pubspec.yaml as a dependency

dependencies:
  mustache4dart: '>= 2.0.0 < 3.0.0'

and then import the package

import 'package:mustache4dart/mustache4dart.dart';

and you are good to go. You can use the render toplevel function to render your template.

For example:

var salutation = render('Hello {{name}}!', {'name': 'Bob'});
print(salutation); //shoud print Hello Bob!

Context objects

mustache4dart will look at your given object for operators, fields or methods. For example, if you give the template {{firstname}} for rendering, mustache4dart will try the followings

  1. use the [] operator with firstname as the parameter
  2. search for a field named firstname
  3. search for a getter named firstname
  4. search for a method named firstname (see Lambdas support)

in each case the first valid value will be used.

@MirrorsUsed

In order to do the stuff described above the mirror library is being used which could lead to big js files when compiling the library with dartjs. In order to preserve the type information you have to annotate the objects used as contextes with @MirrorsUsed. Have in mind though that as documented this is experimental.

In order to avoid the use of the mirrors package, make sure that you compile your library with dart2js -DMIRRORS=false. In that case though you must always make sure that your context object have a right implementation of the [] operator as no other checks on the object will be available.

Partials

mustache4dart support partials but it needs somehow to know how to find a partial. You can do that by providing a function that returns a template given a name:

String partialProvider(String partialName) => "this is the partial with name: ${partialName}";
expect(render('[{{>p}}]', null, partial: partialProvider), '[this is the partial with name: p]'));

Compiling to functions

If you have a template that you are going to reuse with different contexts, you can compile it to a function using the toplevel function compile:

var salut = compile('Hello {{name}}!');
print(salut({'name': 'Alice'})); //should print Hello Alice!

Lambdas support

The library passes all the optional lambda specs based on which lambdas must be treatable as arity 0 or 1 functions. As dart provides optional named parameters, you can pass to a given lambda function the nestedContext. In that case the current nested context will be given as parameter to the lambda function.

Developing

The project passes all the Mustache specs. You have to make sure though that you've downloaded them. Just make sure that you have done the steps described below.

git clone git://github.com/valotas/mustache4dart.git
git submodule init
git submodule update
pub get

If you are with Linux, you can use what travis does:

./build.sh

Alternatively, if you have Dart Test Runner installed you can just do:

pub global run test_runner

Observatory

To start the observatory after running test:

dart --pause-isolates-on-exit --enable-vm-service=NNNN ./test/mustache_all.dart

Then coverage can be used in order to collect and format data:

pub global run coverage:collect_coverage --uri=http://... -o /tmp/mustache4dart.coverage.json --resume-isolates
pub global run coverage:format_coverage --packages=app_package/.packages -i /tmp/mustache4dart.coverage.json

Contributing

If you found a bug, just create a new issue or even better fork and issue a pull request with you fix.

Versioning

The library will follow a semantic versioning

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].