Skip to content

Support named references for use in other templated properties#8

Open
elijahmanor wants to merge 1 commit into
mennovanslooten:masterfrom
elijahmanor:master
Open

Support named references for use in other templated properties#8
elijahmanor wants to merge 1 commit into
mennovanslooten:masterfrom
elijahmanor:master

Conversation

@elijahmanor
Copy link
Copy Markdown
Contributor

Over the past couple of years I have wanted the ability to reference the output of one templated item inside another property. This hasn't been available from what I've seen so I've make some minor tweaks to support this feature.

Basic Usage

If you want to name the output of a templated property then append the name with |$someKey. To use the value you would just reference the $someKey inside the value of your templated item. See the following for an example

$.mockJSON.generateFromTemplate({
    "name|$1": "@LOREM",
    "path": "My @LOREM",
    "created": "@DATE_YYYY@DATE_MM@DATE_DD",
    "created by|$2": "@LETTER_UPPER.@LAST_NAME",
    "title": "My $1 by $2",
});

The output of the above snippet would show something like the following

output

Limitations

  • You can't combine the naming feature (|$someKey) and the auto-increment feature (|+1)
  • You can only use a named reference for items already generated. You will notice I don't reference $1 or '$2` until after I have named them

This feature could be a lot better, but in the meantime it does provide value.

@elijahmanor
Copy link
Copy Markdown
Contributor Author

@mennovanslooten Do you have any questions about this pull request? Do you think it is helpful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant