0

I'm hoping to create templates for pubspec.yml, ask users to supply the name of their package and then output a version of the pubspec.yml populated with their package.

Right now, I'm leaning towards using string interpolation but I believe that would require the strings to be available at compile time. In this case I'd like to be able to load the template from a file, do some form of string replacement to inject the package name and other information, then save the rendered file back to the file system.

Normally I would pull in a separate package to do this, but given that this is pub I am assuming I am restricted to using what's available in the standard Dart library.

Can anyone offer some guidance here? I've search the api documentation to no avail.

UPDATE: To be clear, I'm hoping to contribue a "pub init" command to pub itself. Since this will be part of pub, pub won't be available yet so I can't depend on loading a Dart package.

Mark B
  • 2,870
  • 3
  • 20
  • 18

2 Answers2

2

Check out the mustache package or the mustache4dart package available on pub.dartlang.org.

Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
Juniper Belmont
  • 3,296
  • 2
  • 18
  • 28
  • Thanks for the suggestion. Normally that's what I'd use, but in this case I'm hoping to contribute back to the pub tool itself so I'm guessing it can't depend on any external packages. – Mark B Apr 21 '13 at 00:14
2

I've got some simple substitution code that you could lift out of this package and modify.

Another option, if you want to keep it really simple, is just to use a regexp replace.

I also wrote one of the mustache packages mentioned above. If you do decide to use that, I'm happy to help out.

Greg Lowe
  • 15,430
  • 2
  • 30
  • 33