stencil 0.0.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 77

Stencil

A super simple type-safe, analyzer and code-completion friendly HTML template library for Dart

Think code-safe, code-completable alternative to mustache

Features

  • [x] Data binding
    • [x] Content
    • [x] Attribute
  • [x] Conditional nodes (if and else)
  • [ ] Switch
  • [x] Loops
  • [x] Components

Usage

Simple data binding

Model

class Movie {
  final String name;

  final String description;

  final int stars;

  Movie(this.name, this.description, this.stars) {
    if (stars < 0 || stars > 5)
      throw new ArgumentError.value(stars, 'stars', 'Must be between 0 and 5!');
  }
}

Components

class MovieCardComponent extends Component {
  final Movie movie;

  MovieCardComponent(this.movie);

  @override
  String render() {
    return '''
<div class="movie-card">
  <div>${movie.name}</div>
  <div>${movie.description}</div>
</div>
    ''';
  }
}

Usage

final Movie castaway = new Movie(
    'Cast away',
    'Obsessively punctual FedEx executive Chuck Noland (Tom Hanks) is en route to an assignment in Malaysia when his plane crashes over the Pacific Ocean during a storm.',
    4);

print(new MovieCardComponent(castaway).render());

Rendering

<div class="movie-card">
  <div>Cast away</div>
  <div>Obsessively punctual FedEx executive Chuck Noland (Tom Hanks) is en route to an assignment in Malaysia when his plane crashes over the Pacific Ocean during a storm.</div>
</div>

Loop range

Components

class RatingComponent extends Component {
  final int stars;

  RatingComponent(this.stars);

  @override
  String render() {
    return '''
<div class="stars-holder">
  ${until(stars, (i) => '<div class="star-filled"></div>\n  ')}
  ${until(5-stars, (i) => '<div class="star"></div>')}
</div>''';
  }
}

Usage

print(new RatingComponent(4).render());

Rendering

<div class="stars-holder">
  <div class="star-filled"></div>
  <div class="star-filled"></div>
  <div class="star-filled"></div>
  <div class="star-filled"></div>

  <div class="star"></div>
</div>

Component

Components

class RatingComponent extends Component {
  final int stars;

  RatingComponent(this.stars);

  @override
  String render() {
    return '''
<div class="stars-holder">
  ${until(stars, (i) => '<div class="star-filled"></div>\n  ')}
  ${until(5-stars, (i) => '<div class="star"></div>')}
</div>''';
  }
}

class MovieCardComponent extends Component {
  final Movie movie;

  MovieCardComponent(this.movie);

  @override
  String render() {
    return '''
<div class="movie-card">
  <div class="movie-name">${movie.name}</div>
  <div class="movie-description">${movie.description}</div>

  ${comp(new RatingComponent(movie.stars))}
</div>
    ''';
  }

Usage

final Movie castaway = new Movie(
    'Cast away',
    'Obsessively punctual FedEx executive Chuck Noland (Tom Hanks) is en route to an assignment in Malaysia when his plane crashes over the Pacific Ocean during a storm.',
    4);

print(new MovieCardComponent(castaway).render());

Rendering

<div class="movie-card">
  <div class="movie-name">Cast away</div>
  <div class="movie-description">Obsessively punctual FedEx executive Chuck Noland (Tom Hanks) is en route to an assignment in Malaysia when his plane crashes over the Pacific Ocean during a storm.</div>

  <div class="stars-holder">
  <div class="star-filled"></div>
  <div class="star-filled"></div>
  <div class="star-filled"></div>
  <div class="star-filled"></div>

  <div class="star"></div>
</div>
</div>

Loops iterable

TODO example

Loop map

TODO example

Changelog

0.0.2

  • Dependency bug fix

0.0.1

  • Component and Iterator

1. Depend on it

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


dependencies:
  stencil: "^0.0.2"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:stencil/stencil.dart';
        
Version Uploaded Documentation Archive
0.0.2 Oct 15, 2017 Go to the documentation of stencil 0.0.2 Download stencil 0.0.2 archive
0.0.1 Oct 2, 2017 Go to the documentation of stencil 0.0.1 Download stencil 0.0.1 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
54 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
77

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:stencil/stencil.dart.

Suggestions

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use stencil.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
dart_to_js_script_rewriter ^1.0.1 1.0.3
Transitive dependencies
args 1.3.0
async 2.0.3
barback 0.15.2+14
charcode 1.1.1
collection 1.14.5
csslib 0.14.1
html 0.13.2+2
logging 0.11.3+1
path 1.5.1
pool 1.3.4
source_span 1.4.0
stack_trace 1.9.1
utf 0.9.0+4
Dev dependencies
browser ^0.10.0