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

Make indentation more intuitive #71

Open
Aunmag opened this issue Feb 6, 2020 · 4 comments
Open

Make indentation more intuitive #71

Aunmag opened this issue Feb 6, 2020 · 4 comments

Comments

@Aunmag
Copy link

Aunmag commented Feb 6, 2020

It would be cool if this template might produce something like:

@()
begin
@for n in &vec![0, 1, 2] {
  @if true {
  test
  }
}
end
begin
  test
  test
  test
end

But to get the same output I have to write the template in this way, and it looks kinda dirty:

@()
begin@for n in &vec![0, 1, 2] {@if true {
  test}}
end

So the point is: if a line contains only start or end of an expression, and while spaces or tabs or line-break, then it will be skipped. It will allow to write more readable and intuitive templates.

More examples:

The first one looks better, doesn't it? :)

I hope you will take more attention to Rocker developer's experience, 'cause we need such a great tool in Rust too.

@Aunmag
Copy link
Author

Aunmag commented Feb 6, 2020

Probably this issue intersects with #29

@kaj
Copy link
Owner

kaj commented Feb 6, 2020

After some experimentation, I have more or less decided against the solution I suggsted in #29, and in favor of something like #42 (comment) . That would hopefully make it possilble to get your expected output by adding a backslash at the end of selected lines of the template.

Do you think that would suffice?

@Aunmag
Copy link
Author

Aunmag commented Feb 7, 2020

I'm not sure how it would look like. Like this?

@()
begin\
@for n in &vec![0, 1, 2] {\
@if true {
  test\
}}
end

Personally, this approach is not clean enough for me. Maybe I miss something.

@kaj
Copy link
Owner

kaj commented Feb 7, 2020

Yes, something like that.

Your idea of not generating output for template lines that is only statements would be nice, but a bit harder to implement. Ructe does not look at a template line by line, but would instead have to look at the end of the last thing before a block-opening statement and compare it to the first thing in the block, and similiar for the end of the block (and a special case for "else" blocks).

But I'll keep this issue open and think about it. PR:s welcome, of course.

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

No branches or pull requests

2 participants