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

Break, continue and loops' labels #175

Merged
merged 5 commits into from
Jul 28, 2022
Merged

Break, continue and loops' labels #175

merged 5 commits into from
Jul 28, 2022

Conversation

ilyapuchka
Copy link
Collaborator

@ilyapuchka ilyapuchka commented Dec 27, 2017

This PR adds break and continue tags for loops. They can be labeled, like in Swift, or not.

{% for item in items %}
  {{ item }}{% if condition %}{% break %}{% endif %}
{% endfor %}

Labeled loops:

{% outer: for item in items %}
  {% for key in keys %}
    {{ item.key }}{% if condition %}{% break outer %}{% endif %}
  {% endfor %}
{% endfor %}

Also with labels it's now possible to access outer loop context from inner loop:

{% outer: for item in items %}
  {% for key in keys %}
   {{ forloop.counter }}-{{ forloop.outer.counter }}
  {% endfor %}
{% endfor %}

@ilyapuchka ilyapuchka force-pushed the break-continue branch 2 times, most recently from 87cd89f to 58df5b6 Compare December 28, 2017 14:17
@ilyapuchka ilyapuchka changed the title Break & continue Break, continue and loops' labels Dec 28, 2017
@ilyapuchka ilyapuchka force-pushed the break-continue branch 2 times, most recently from 20677fe to 9cb7c6b Compare January 1, 2018 15:04
Copy link
Contributor

@djbe djbe left a comment

Choose a reason for hiding this comment

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

While template writers can do this now with the set tag, I think this would be easier (and shorter) to use.

I'm not 100% sold on the location/syntax of the label, but I don't have any better ideas 🤷‍♂️ What are other people's thoughts?

CHANGELOG.md Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/ForTag.swift Outdated Show resolved Hide resolved
Sources/Parser.swift Outdated Show resolved Hide resolved
@djbe
Copy link
Contributor

djbe commented Jul 11, 2018

Before I forget: This PR should document the changes in the docs.

@djbe djbe added this to the 0.12.0 milestone Jul 11, 2018
@djbe djbe modified the milestones: 0.12.0, 0.13.0, 0.14.0 Sep 21, 2018
@ilyapuchka
Copy link
Collaborator Author

Is it something we still want to have or it can be closed?

@kylef kylef removed their request for review December 17, 2019 11:20
@djbe djbe modified the milestones: 0.14.0, 0.15.0 Aug 17, 2020
@SwiftGen-Eve
Copy link

SwiftGen-Eve commented Jul 28, 2022

1 Message
📖 Big PR

Hey 👋 I'm Eve, the friendly bot watching over Stencil 🤖

Thanks a lot for your contribution!


Seems like everything is in order 👍 You did a good job here! 🤝

Generated by 🚫 Danger

Copy link
Contributor

@djbe djbe left a comment

Choose a reason for hiding this comment

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

Rebased on master, added support for multi-level forloop access, and fixed a bug in the tokenizer because of #178. The fix for that last one is "okay-ish" 🤷

@djbe djbe merged commit 242bea5 into master Jul 28, 2022
@djbe djbe deleted the break-continue branch July 28, 2022 22:02
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.

4 participants