simple_mustache 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

simple_mustache #

Dart implementation of a mustache subset for simple String templates with filters.

This library implements dart:convert specification

Usage #

// Create a mustache converter
final m = Mustache(map: {'name': 'David'});

// Convert a template
final output = m.convert('Hello, my name is {{ name }}.');

Changelog #

1.0.0 #

  • Initial release.

example/main.dart

import 'package:simple_mustache/simple_mustache.dart';

void main() {
  // Create a mustache converter
  final m = Mustache(
    map: <String, dynamic>{
      'name': 'David',
    },
  );

  // Convert a template
  final output = m.convert('Hello, my name is {{ name }}.');
  print(output);

  // Create a more complicated mustache converter
  final m1 = Mustache(
    map: <String, dynamic>{
      'events': <Map>[
        <String, dynamic>{
          'name': 'Event 1',
          'date': DateTime.fromMillisecondsSinceEpoch(-1893200147000),
        },
        <String, dynamic>{
          'name': 'Event 2',
          'date': DateTime.fromMillisecondsSinceEpoch(1893200147000),
        },
      ],
    },
    filters: {
      'dt': (dynamic d) => d is DateTime ? d.year : 'Invalid data',
    },
  );

  // Convert a template
  print(m1.convert(
      'List of events:\n{{# events }}  {{ name }}, year: {{ date | dt }}\n{{/ events }}'));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  simple_mustache: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:simple_mustache/simple_mustache.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
meta ^1.1.0 1.2.2 1.3.0-nullsafety
Dev dependencies
pedantic ^1.8.0
test any