jinja 0.0.8+1

Pub Build Status

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

Draft

All variables passed to the template and literals used in the template are dart objects with their own fields and methods.

To Do #

  • Compile templates to fast Dart code
  • Docs
  • Informative error output
  • Full test coverage
  • Add missing filters
  • Loaders
    • PackageLoader
    • FunctionLoader
    • PrefixLoader
    • ChoiceLoader
  • Whitespace Control
  • Escaping
  • Line Statements
  • Statements
    • Macro
    • Set Block
    • Call
    • Filter
    • Template Inheritance
      • Include
      • Import
  • Expressions
    • ... if ... else ... condition expression
    • ~ concat

Done #

  • Loaders
    • FileSystemLoader
    • MapLoader (DictLoader)
  • Variables
  • Filters
    • length
    • count
    • string
    • escape, e
    • forceescape
    • upper
    • lower
    • capitalize
    • dictsort
    • default
    • d
    • join
    • center
    • first
    • last
    • random
    • filesizeformat
    • int
    • float
    • abs
    • trim
    • batch
    • sum
    • list
    • attr
  • Tests
  • Comments
  • Statements
    • For (not full covered)
    • If
    • Set (one variable statement)
    • Template Inheritance (not covered)
      • Extends
      • Block
        • Super
  • Expressions
    • Literals
    • Math
    • Comparison
    • Logic
    • in
    • is tests
    • | filters
    • () call callable
    • (*iter) call callable
    • ./[] object attribute (. for field, [] for map)

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.fromSource(source, path: 'index.html');

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

Use this package as a library

1. Depend on it

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


dependencies:
  jinja: ^0.0.8+1

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]
34
Health:
Code health derived from static analysis. [more]
71
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
52
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: other

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

Health suggestions

Fix lib/src/parser.dart. (-20.99 points)

Analysis of lib/src/parser.dart reported 47 hints, including:

line 47 col 16: The value of the field '_stmtClose' isn't used.

line 48 col 16: The value of the field '_varClose' isn't used.

line 49 col 16: The value of the field '_commentClose' isn't used.

line 70 col 13: DO use curly braces for all flow control structures.

line 72 col 13: DO use curly braces for all flow control structures.

Fix lib/src/filters.dart. (-4.41 points)

Analysis of lib/src/filters.dart reported 9 hints, including:

line 35 col 5: DO use curly braces for all flow control structures.

line 37 col 5: DO use curly braces for all flow control structures.

line 39 col 5: DO use curly braces for all flow control structures.

line 70 col 5: DO use curly braces for all flow control structures.

line 103 col 5: DO use curly braces for all flow control structures.

Fix lib/src/env.dart. (-2.96 points)

Analysis of lib/src/env.dart reported 6 hints, including:

line 95 col 16: DO use curly braces for all flow control structures.

line 96 col 7: DO use curly braces for all flow control structures.

line 98 col 7: DO use curly braces for all flow control structures.

line 107 col 7: DO use curly braces for all flow control structures.

line 116 col 7: DO use curly braces for all flow control structures.

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

Analysis of lib/src/utils.dart reported 3 hints:

line 19 col 5: DO use curly braces for all flow control structures.

line 20 col 7: DO use curly braces for all flow control structures.

line 22 col 7: DO use curly braces for all flow control structures.

Fix lib/src/loaders.dart. (-1 points)

Analysis of lib/src/loaders.dart reported 2 hints:

line 28 col 7: DO use curly braces for all flow control structures.

line 53 col 7: DO use curly braces for all flow control structures.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/ykmnkmi/jinja.dart was unreachable.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

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

Admin