Skip to content

Commit

Permalink
allow variables in nested included files
Browse files Browse the repository at this point in the history
  • Loading branch information
monken committed Feb 20, 2016
1 parent 461f683 commit 817ed11
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Include a file literally

## Fn::Map

`Fn::Map` is the equivalent of the JavaScript `map()` function allowing for the trasformation of an input array to an output array.
`Fn::Map` is the equivalent of the JavaScript `map()` function allowing for the transformation of an input array to an output array.
By default the string `_` is used as the variable in the map function.

```json
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function recurse(base, scope, object) {
delete object["Fn::Include"];
_.extend(object, json);
return object;
}).then(_.bind(recurse, this, base, scope));
}).then(_.bind(findAndReplace, this, scope)).then(_.bind(recurse, this, base, scope));
} else {
return object;
}
Expand Down
8 changes: 8 additions & 0 deletions t/includes/mapvariable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"foo": "_",
"bar": "$",
"baz": [{
"foo": "_",
"bar": "$"
}]
}
42 changes: 42 additions & 0 deletions t/tests/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,47 @@
}, {
"Value": "2"
}]
}, {
"name": "include template with variables",
"template": {
"Fn::Map": [
[1, 2], "$", {
"Fn::Map": [
[3, 4], {
"Fn::Include": "includes/mapvariable.json"
}
]
}
]
},
"output": [[{
"foo": "3",
"bar": "1",
"baz": [{
"foo": "3",
"bar": "1"
}]
}, {
"foo": "4",
"bar": "1",
"baz": [{
"foo": "4",
"bar": "1"
}]
}], [{
"foo": "3",
"bar": "2",
"baz": [{
"foo": "3",
"bar": "2"
}]
}, {
"foo": "4",
"bar": "2",
"baz": [{
"foo": "4",
"bar": "2"
}]
}]]
}]
}

0 comments on commit 817ed11

Please sign in to comment.