xxgreg / mustache

Mustache template Dart library
BSD 2-Clause "Simplified" License
57 stars 59 forks source link

Documentation for mirrors, dart2js and the @mustache annotation #19

Open xxgreg opened 9 years ago

xxgreg commented 9 years ago

@MikeMitterer

Added this so I remember to update the docs with an example.

e-belair commented 4 years ago

Hi, I get the following error after I've installed the package. I don't know how to make it work, could you provide a real working example, please?

[WARNING]build_web_compilers:entrypoint on web/main.dart: Skipping compiling my_app_web|web/main.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:

mustache|lib/src/renderer.dart
xxgreg commented 4 years ago

If you're planning on using this with dart2js or flutter you'll need to remove the code which uses mirrors. The dart:mirrors package is now only supported by the VM running in JIT mode.

See _getNamedProperty() in renderer.dart. This should require commenting out a few lines, and the dart:mirrors import. Then using maps rather than objects as input.

I'd like to add another entry point to the library to allow using this package as is with dart2js and AOT, but I haven't found the time. I'd happily take a contribution.

There's also a forked version which uses the reflectable package for code generating the mirrors code. https://pub.dev/packages/reflected_mustache I'm not sure if that's being maintained or not.

e-belair commented 4 years ago

How do I remove these lines of code after installed the package via pubspec ? Do I need to fork the project to do this?

xxgreg commented 4 years ago

Yup. You can fork it, and then add it to your pubspec using a git dependency.

https://flutter.dev/docs/development/packages-and-plugins/using-packages#dependencies-on-unpublished-packages

Hopefully I'll find time to add this support for AOT/js. But merge requests are also always welcome.

e-belair commented 4 years ago

Why not using reflectable as the other libs?

xxgreg commented 4 years ago

Which other libs?

I'd rather not bake in a dependency on reflectable, but rather let the user of the library choose. I'd like to make it easy for end user to plug the libraries together with whichever library they use.

e-belair commented 4 years ago

I was talking about mustache_reflectable. For instance, I'm using it because I already use reflectable in my project. Anyway, thank you for your help, and if I have enough time ... one day .... would be a pleasure to help

lloy0076 commented 4 years ago

Just out of morbid interest, is there a particular reason why this doesn't use something that doesn't work through more the of the whole Dart ecosystem?

xxgreg commented 4 years ago

It was built before flutter and dart2native existed. At the time it worked with both dart2js and the VM, which was the entire ecosystem.

AOT exists now, and dart2js no longer supports mirrors, so some work is required to make the library work with these targets. Somebody should definitely do this. It's not much work.