Contributing

#1 · closed · 5 comments

View on GitHub ↗

doowb

@tkellen we're refactoring assemble and I had started to implement something similar to this and the original grunt.config.process function, but I'm using [js-traverse](https://github.com/substack/js-traverse). This basically gives me all the "expand object" and "expand array" functionality without having to think about it. I also implemented it in a way that if there's a function call inside a template it can be expanded and the data object or array will be injected into your data tree instead of just the string... ``` javascript var data = { c: 42, d: { e: '<%= c %>' }, x: '<%= _.expand({a: 1}, {b: 2}, {a: c}, {b: d}) %>' }; var newData = process(data); // newData will be { c: 42, d: { e: 42 }, x: { a: 42: b: { e: 42 } } } ``` I'd like to put a PR together and submit to this project, then I can just use this instead of rolling my own. Does this sound good, or am I going in a different direction? Thanks.

Comments

tkellen

Hey Brian! Good luck with your assemble refactor! I'm stoked to see you found this project. We're going to upstream it into grunt soon. You can accomplish what you're describing right now by doing this: ``` js var expander = require('expander'); var _ = require('lodash'); var data = { c: 42, d: { e: '<%= c %>' }, x: _.extend({a: 1}, {b: 2}, {a: '<%= c %>'}, {b: '<%= d %>'}), }; expander.get(data); ``` Does that help?

tkellen

PS: that won't work in the REPL, thanks to the fact that `_` is a special variable that expose the result of the last expression (http://nodejs.org/api/repl.html#repl_repl_features)

doowb

Our use case usually involves properties specified in yaml front matter or some other configuration file, like json or yml. By allowing us to inject the actual return value instead of just the string, we can use regular json format and do the evaluation at runtime. I was looking around for an issue that I thought I saw on the grunt repo once that talked about this in more detail, but I can't find it. Yeah, I usually have to use `var lodash = require('lodash')` in the REPL. That was frustrating when I first tried it.

tkellen

I've added support for methods which can be automatically invoked. It doesn't get you to a point where you can use JSON strictly, but perhaps it helps. I'm open to checking out your PR--please send away!

doowb

I like how you did the methods since it can allow any arbitrary library to be used. I sent the PR, but the functions need to be in lodash (can be mixins) or on the data object. I'll add a couple of tests to show how they work when on the data object (I forgot about that before sending the PR).