mustachex 0.9.9 copy "mustachex: ^0.9.9" to clipboard
mustachex: ^0.9.9 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
0
pub points
76%
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

License

unknown (license)

Dependencies

collection, mustache_recase, path, quiver, recase

More

Packages that depend on mustachex