Skip to content

Commit

Permalink
Rework MustacheContext (#64)
Browse files Browse the repository at this point in the history
Introduce `mirrors.dart` and make use of it for creating mirrors. This should make dart2js work a little bit better. As a side effect of the reworks dropped support of invoking methods starting with `get`. 

fix #62
  • Loading branch information
valotas authored Jun 13, 2017
1 parent 8a09ade commit 33da62f
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 330 deletions.
25 changes: 24 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
language: dart
dist: trusty
sudo: false

addons:
firefox: 53.0.3
apt:
packages:
- google-chrome-stable

dart:
- stable
- 1.23.0
- 1.22.0
- 1.21.1
- 1.20.1
- 1.19.1
script: ./build.sh

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start &
- sleep 3

script: ./build.sh

branches:
only:
- master

cache:
directories:
- $HOME/.pub-cache
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# CHANGELOG

## next
## 2.0.0 (2017-06-13)

* Rework MustacheContext ([#64][pr-64])
* Use dartanalyzer `--strong` mode ([#61](https://github.com/valotas/mustache4dart/issues/61))

As part of the [MustacheContext rework][pr-64], a couple of simplifications have been made. Most
notable one is the drop support of mirroring methods starting with `get` as it does not make any
sense with dart. Use a getter instead.

## 1.1.0 (2017-05-10)

* Avoid trapping exceptions by using reflection ([#59](https://github.com/valotas/mustache4dart/pull/59))
Expand All @@ -29,3 +35,5 @@
## 1.0.8 (2015-02-01)

* Find property names in superclasses [issue](https://github.com/valotas/mustache4dart/issues/33)

[pr-64][https://github.com/valotas/mustache4dart/pull/64]
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mustache for Dart

[![Build Status](https://travis-ci.org/valotas/mustache4dart.svg?branch=v1.0.12)](https://travis-ci.org/valotas/mustache4dart)
[![Build Status](https://travis-ci.org/valotas/mustache4dart.svg?branch=master)](https://travis-ci.org/valotas/mustache4dart)
[![Coverage Status](https://coveralls.io/repos/github/valotas/mustache4dart/badge.svg?branch=master)](https://coveralls.io/github/valotas/mustache4dart?branch=master)

A simple implementation of [Mustache][mustache] for the
Expand All @@ -13,7 +13,7 @@ Using it
In order to use the library, just add it to your `pubspec.yaml` as a dependency

dependencies:
mustache4dart: '>= 1.0.0 < 2.0.0'
mustache4dart: '>= 2.0.0 < 3.0.0'

and then import the package

Expand All @@ -39,22 +39,21 @@ mustache4dart will try the followings
1. use the `[]` operator with `firstname` as the parameter
2. search for a field named `firstname`
3. search for a getter named `firstname`
4. search for a method named `firstname`
5. search for a method named `getFirstname`
4. search for a method named `firstname` (see Lambdas support)

in each case the first valid value will be used.

#### @MirrorsUsed
In order to do the stuff described above the mirror library is being used which
could lead to big js files when compiling the library with dartjs. The
implementation does use the `@MirrorsUsed` annotation but
[as documented][mirrorsused] this is experimental.
could lead to big js files when compiling the library with dartjs. In order to
preserve the type information you have to annotate the objects used as
contextes with `@MirrorsUsed`. Have in mind though that [as documented][mirrorsused]
this is experimental.

In order to avoid the use of the mirrors package, make sure that you compile
your library with `dart2js -DMIRRORS=false `. In that case though you must
always make sure that your context object have a right implementation of the
`[]` operator as it will be the only check made against them (from the ones
described above) in order to define a value.
`[]` operator as no other checks on the object will be available.

### Partials
mustache4dart support partials but it needs somehow to know how to find a
Expand Down
25 changes: 15 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ echo "Analyzing with `dartanalyzer --version`"
dartanalyzer --strong --fatal-warnings lib/*.dart test/*.dart

# Assert that code is formatted.
pub global activate dart_style
dirty_code=$(pub global run dart_style:format --dry-run lib/ test/ example/)
if [[ -n "$dirty_code" ]]; then
echo Unformatted files:
echo "$dirty_code" | sed 's/^/ /'
exit 1
else
echo All Dart source files are formatted.
if [ "$TRAVIS_DART_VERSION" = "stable" ]; then
pub global activate dart_style
dirty_code=$(pub global run dart_style:format --dry-run lib/ test/ example/)
if [[ -n "$dirty_code" ]]; then
echo Unformatted files:
echo "$dirty_code" | sed 's/^/ /'
exit 1
else
echo All Dart source files are formatted.
fi
fi

# run the tests
Expand All @@ -26,6 +28,9 @@ if [ "$COVERALLS_TOKEN" ] && [ "$TRAVIS_DART_VERSION" = "stable" ]; then
pub global run dart_coveralls report \
--retry 2 \
--exclude-test-files \
--debug \
test/mustache_all.dart
fi
fi

if [ "$TRAVIS_DART_VERSION" = "stable" ]; then
pub run test -p chrome,firefox
fi
Loading

0 comments on commit 33da62f

Please sign in to comment.