mustachex 1.0.0 copy "mustachex: ^1.0.0" to clipboard
mustachex: ^1.0.0 copied to clipboard

Mustache Extended. A fork from mustache and mustache_template that will be maintained and that has improvements over it.... or just "Mustache with steroids"

example/mustachex_example.dart

import 'package:mustachex/mustachex.dart';

main() async {
  var template = '{{greeting_pascalCase}} {{world_pc}}!';
  var vars = {'greeting': 'HELLO'};
  String fulfillmentFunction(MissingVariableException variable) {
    if (variable.varName == 'world') {
      return 'WORLD';
    } else {
      return 'UNIVERSE';
    }
  }

  var processor = MustachexProcessor(
      initialVariables: vars, missingVarFulfiller: fulfillmentFunction);
  var rendered = await processor.process(template);
  assert(rendered == 'Hello World!');
  print(rendered);
  var classesJSON = {
    'classes': [
      {
        'name': 'claseUno',
        'fields': [
          {'name': 'field1', 'type': 'String', 'final': true},
          {'name': 'Field2', 'type': 'int'},
        ],
        'methods': []
      },
      {
        'name': 'clase_dos',
        'fields': [
          {'name': 'field1', 'type': 'int'},
        ],
        'methods': [
          {
            'name': 'METHOD_UNO',
            'returnType': 'String',
            'parameters': [
              {'name': 'param1', 'type': 'String'},
              {'name': 'param2', 'type': 'double'}
            ]
          },
          {'name': 'method-dos', 'returnType': 'String'}
        ]
      }
    ]
  };
  template = '''
{{#classes}}
class {{name_pc}} {
  {{#fields}}
  {{#hasDocs}}///{{docs}}{{/hasDocs}}
  {{#hasFinal}}final {{/hasFinal}}{{type}} {{name_cc}};
  {{/fields}}

  {{name_pc}}();

  {{#methods}}
  {{returnType_pc}} {{name_cc}}({{#hasParameters}}{{#parameters}}{{type}} {{name}},{{/parameters}}{{/hasParameters}}){}
  {{/methods}}
}
{{/classes}}
''';
  processor = MustachexProcessor(initialVariables: classesJSON);
  rendered = await processor.process(template);
  print(rendered);
}
9
likes
150
pub points
77%
popularity

Publisher

unverified uploader

Mustache Extended. A fork from mustache and mustache_template that will be maintained and that has improvements over it.... or just "Mustache with steroids"

Repository (GitLab)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

collection, mustache_recase, path, quiver, recase

More

Packages that depend on mustachex