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

should be able to pass empty results to a tag and have it stay on same line. #13

Open
cortfritz opened this issue Nov 14, 2018 · 7 comments

Comments

@cortfritz
Copy link

cortfritz commented Nov 14, 2018

consider:

    - sum = fn (a, b) -> a + b end
    - has_value = sum.(2, 3)
    - is_empty = nil
    p= has_value
    p= is_empty

I would expect

  <p>5</p>
  <p></p>

instead i get

  <p>
    5
  </p>
  <p>
    
  </p>

...which seems wrong. Is there a mode to turn off the unintended newlines?

@rstacruz
Copy link
Owner

Hey there, sorry there isn't any! There are newlines going to be inserted; p= xyz will translate to <p><%= "\n" %><%= xyz %><%= "\n" %></p>.

This feature was never planned in Expug, unfortunately.

@cortfritz
Copy link
Author

cortfritz commented Jul 26, 2019 via email

@thepeoplesbourgeois
Copy link

thepeoplesbourgeois commented Feb 18, 2020

Oh cool, this issue's still open.

It's disappointing to hear this isn't considered a bug, and won't be fixed being that it was not a planned feature. It implies having to either accept visual artifacts on an expug-rendered page when no data is available for a given variable or function return, or having to incorporate kludgy if statements anywhere there is the potential for data to not be returned to the template.

As an example of what I mean, this is the standard Phoenix Framework templates/layout/app.html rendered after being converted from .eex to .pug

Info and error alert boxes on page because of bug when no text is rendered within an element

The blue and red boxes are info and error alert boxes, rendering because no text is returned via the get_flash/2 calls inside of those elements. I wasn't able to prevent these from appearing by wrapping the get_flash calls inside of an interpolated string, like I had hoped, nor was I able to make the if statement a one-liner within the p.alert elements. Instead, I had to nest the entire p element inside of an if which checked for the value before rendering its corresponding alert, like so:

main.container(role="main")
  = if get_flash(@conn, :info) do
    p.alert.alert-info(role="alert")= get_flash(@conn, :info)
  = if get_flash(@conn, :error) do
    p.alert.alert-danger(role="alert")= get_flash(@conn, :error)

Simple as this was to do for this one top-level layout template, it is a brittle coding pattern overall, and I can imagine similar visual artifacts ending up on larger websites because of the need to implement the if check on every potential nil or blankish value.

I'm hoping this doesn't become a showstopper in building my app using Expug for my template files. The syntax is refreshingly terse compared to .eex, and I quite like that, but if it winds up necessitating more overhead to ensure a clean interface for my users, I'm likely going to revert to .eex, using Emmet to reduce the number of keystrokes to generate the boilerplate stuff

@thepeoplesbourgeois
Copy link

Annnd I reverted to .eex. This remained hilarious until it became sad.

The good news is, I'm sure it'll circle back to hilarious in due time

@cortfritz
Copy link
Author

cortfritz commented Jan 11, 2021

this seems like it wouldn't be an expensive PR. I'm open to submitting one, but I'd like a pointer for which section of code would be the right spot to start.

@thepeoplesbourgeois
Copy link

I've just decided to use Slime instead

@rstacruz
Copy link
Owner

rstacruz commented Jan 22, 2021 via email

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

3 participants