jinja 0.1.2

Jinja 2 for Dart 2 #

Pub

Jinja 2 server-side template engine port for Dart 2. Variables, expressions, control structures and template inheritance.

Done #

  • Loaders
    • FileSystemLoader
    • MapLoader (DictLoader)
  • Comments
  • Variables
  • Expressions: variables, literals, subscription, math, comparison, logic, tests, filters, calls
  • Filters (not all)
  • Tests
  • Statements
    • Filter
    • For (without recursive)
    • If
    • Set
    • Raw
    • Inlcude
    • Extends
    • Block

Using it #

Add package to your pubspec.yaml as a dependency

  dependencies:
    jinja: ^0.1.0

Import library and use it:

import 'package:jinja/jinja.dart';

// code ...

var template = Template('...source...');
// or
var env = Environment(blockStart: '...', ... );
var template = env.fromString('...source...');

template.render(key: value, );
// or 
template.renderMap({ 'key': value, });

Note: all variables and literals used in the template are dart objects with their own fields and methods.

Docs #

In progress ...

Contributing #

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

0.1.2 #

  • fix example

0.1.1 #

  • fix template blocks ref

0.1.0 #

  • little speed up
  • new statements:
    • filter
    • set
    • raw
  • add namespace
  • environment
    • add leftStrip and trimBlocks
    • add extensions
    • rename:
      • stmtOpen to blockStart
      • stmtClose to blockEnd
      • varOpen to variableStart
      • varClose to variableEnd
      • commentOpen to commentStart
      • commentClose to commentEnd
    • move autoReload to FileSystemLoader
    • remove getFilter and getTest
  • update context and parser
  • parser:
    • parsing *args, **kwargs in calls (not in filters and tests)
    • custom tags support
    • context
    • onParseName
  • template:
    • update render function: render(kv1: ..., kv2: ...) calls renderMap({'kv1': ..., 'kv2': ...})
    • add simple module
    • add self.blockName callback ref in context
  • removed filters:
    • batch
    • filesizeformat

0.0.8+1 #

  • Fixes

0.0.8 #

  • Add and update filters
  • Update escaping
  • Update package tests
  • Formatting & fixes

0.0.7+1 #

  • Set (one variable assign statement)
  • Recursive For-Loop
  • Unpacking argument expression
  • Formatting & fixes

0.0.7 #

  • Add global namespace to env and update context
  • Add all missing builtin tests
  • Fix expression group parsing
  • Update package tests
  • Formatting & fixes

0.0.6 #

  • Add undefined & env.finalize
  • Add and switch to env call template, filter, test methods
  • Add is and in expressions
  • Add sum filter
  • Formatting & fixes

0.0.5 #

  • Add batch and escape filters
  • Template and context required env
  • Environment fromSource can store template
  • Formatting & fixes

0.0.4 #

  • Add test for for-loop & if-condition
  • Add defined filter
  • Immutable context
  • Little Docs
  • Formatting & fixes

0.0.3 #

  • Fixes & formatting
  • More filters & tests, package tests

0.0.2 #

  • Fixes & formatting

0.0.1 #

  • Base statements, variables, inheritance, filters & tests and example

example/example.dart

import 'package:jinja/jinja.dart';

void main() {
  const source = '{% for user in users %}'
      '{{ user["fullname"] }}, {{ user["email"] }}; '
      '{% else %}No users{% endfor %}';

  final env = Environment();
  final template = env.fromString(source, path: 'index.html');

  print(template.render(users: [
    {'fullname': 'Jhon Doe', 'email': 'jhondoe@dev.py'},
    {'fullname': 'Jane Doe', 'email': 'janedoe@dev.py'},
  ]));
}

Use this package as a library

1. Depend on it

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


dependencies:
  jinja: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


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

We analyzed this package on Sep 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: other

Primary library: package:jinja/jinja.dart with components: io, mirrors.

Health suggestions

Fix lib/src/nodes/template.dart. (-0.50 points)

Analysis of lib/src/nodes/template.dart reported 1 hint:

line 107 col 29: Extending 'Function' is deprecated.

Fix lib/src/utils.dart. (-0.50 points)

Analysis of lib/src/utils.dart reported 1 hint:

line 6 col 31: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
meta ^1.1.7 1.1.7
path ^1.6.2 1.6.4
string_scanner ^1.0.4 1.0.5
Transitive dependencies
charcode 1.1.2
source_span 1.5.5
term_glyph 1.1.0
Dev dependencies
test ^1.5.3