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

hereDoc syntax tweak #1081

Open
determin1st opened this issue Feb 22, 2019 · 1 comment
Open

hereDoc syntax tweak #1081

determin1st opened this issue Feb 22, 2019 · 1 comment

Comments

@determin1st
Copy link

determin1st commented Feb 22, 2019

What do you think about some utilizer of:

hereDoc = (f) ->
  f = f.toString!
  a = f.indexOf '/*'
  b = f.lastIndexOf '*/'
  return f.substring a + 2, b - 1 .trim!

sample = hereDoc !->
  /*
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
    <circle style="stroke:black; fill:none;" cx="50" cy="50" r="49"/>
    <circle style="stroke:none; fill:none;" cx="50" cy="50" r="46"/>
    <path style="stroke:none; fill:gray;" d="M64 17c0-1-1-2-2-2H38c-1 0-2 1-2 2v19H17c-1 0-2 1-2 2v24c0 1 1 2 2 2h19v19c0 1 1 2 2 2h24c1 0 2-1 2-2V64h19c1 0 2-1 2-2V38c0-1-1-2-2-2H64V17z"/>
    <path style="stroke:none; fill:none;" d="M81 60H62c-1 0-2 1-2 2v19H40V62c0-1-1-2-2-2H19V40h19c1 0 2-1 2-2V19h20v19c0 1 1 2 2 2h19v20z"/>
  </svg>
  */

imo, it's a better version of heredoc, because you dont need to refine/escape any special character combinations.

@rhendric
Copy link
Collaborator

Well, that's clever, and if it works for you, great. But bear in mind that you're losing the ability to express the character combination */ at all, since escape sequences won't work. Triple-quoted strings also handle indented contents more gracefully than this approach will.

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

No branches or pull requests

2 participants