Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Set tag #87

Merged
merged 6 commits into from
May 10, 2018
Merged

Advanced Set tag #87

merged 6 commits into from
May 10, 2018

Conversation

djbe
Copy link
Member

@djbe djbe commented May 10, 2018

Refs SwiftGen/SwiftGen#379 (comment).

This feature adds a variation of the set tag to directly set the value of a variable to the contents of another expression, without rendering it down to a String (like the current set does).

Users will be able to use the set tag in 2 ways:

  • {% set myVar %}...{% endset %} to render and store everything between the start and end tag into the variable.
  • {% set myVar someOtherVar.prop1.prop2 #} to evaluate and store an expression's result into the variable.

This is particularly useful if the expression is a complex object such as an Array or a Dictionary.

Copy link
Contributor

@AliSoftware AliSoftware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly LGTM except the typos 😁

I wondered at first if it was a good choice to have the same tag name sometimes needing a end tag and sometimes not. Kind of asymmetrical here.
In the end it's still probably worth having the same tag name for both use cases (as the end goal is the same, set a variable), despite this asymmetry, but I hope this won't be too confusing for users. Maybe worth at least ensuring that errors/diagnostics are nice if people use both 3 components and a body.

The parameters and tags of this node depend on which mode you want to use:

- Use `{% set myVar %}...{% endset %}` to render and store everything between the start and end tag into the variable.
- Use `{% set myVar someOtherVar.prop1.prop2 #}` to evaluate and store an expression's result into the variable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen you twice (here and in the PR description) tell that this ends with #} not %}. Is this intentional or a double typo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how that got in there 😆 It's in the PR description because I copy/pasted it.

| Name | Description |
|-----------|------------------------------------------------------------------------|
| Tag Name | `set` |
| End Tag | `endset` or N/A (if you're creating an alias of an existing variable) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: one space too many before 'or'

enum Content {
case nodes([NodeType])
case value(Resolvable)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn this quite confused me… nodes is actually used when rendering to a single string value, and value is used when pointing to a node tree/object… 😅

I now get the logic but I needed to read the code twice to understand and be sure you didn't invert the logic but my reading did ^^

Maybe renaming case value to case reference(to:) would have helped? Idk

@djbe djbe merged commit 561bce5 into master May 10, 2018
@djbe djbe deleted the feature/advanced-set branch May 10, 2018 15:58
@djbe djbe added this to the 2.6.0 milestone Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants