0

This is the code

  .meta
    = time_ago_in_words(discussion.created_at)
    ago by
    = discussion.user.username
    |
    = link_to "Edit", edit_discussion_path(discussion), class: "meta"
    |
    = link_to "Delete", discussion_path(discussion), method: :delete, confirm: "Are you sure?", class: "meta"

And this is the output:

    <div class='meta'>
      about 7 hours
      ago by
      foo
      |
      <a href="/discussions/2/edit" class="meta">Edit</a>
      |
      <a href="/discussions/2" class="meta" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Delete</a>
    </div>

This makes the output have unbalanced space on either sides of the |.

Is it possible to remove the whitespace between these statements, without adding a span to everything, or just using erb or string interpolation?

Dogbert
  • 212,659
  • 41
  • 396
  • 397

3 Answers3

1

Would explicitly printing it as a Ruby String help?

.meta
  = time_ago_in_words(discussion.created_at)
  ago by
  = discussion.user.username
  = "|"
  = link_to "Edit", edit_discussion_path(discussion), class: "meta"
  = "|"
  = link_to "Delete", discussion_path(discussion), method: :delete, confirm: "Are you sure?", class: "meta"

I mean, it's not the nicest code and I'd prefer to just place the characters like your initial attempt, but since HAML forces indentation you probably have to take some sort of different path for specifying whitespace/space-characters. I figure doing this might give you the simple means of precision as far as adding a specific number of spaces or &nbsp; characters (if you need multiple) to either side.

EDIT: I noticed the title specifies "remove" whitespace, rather than "balance" it - my mistake. As such you can try succeed, as explained here: Haml: Control whitespace around text. Succeed without a follow up, or followed by the empty String, should probably achieve what you want without any whitespace.

EDIT 2: You're absolutely correct, the > modifier doesn't work with ruby print lines (like link to ). Succeed should still work, or you could create a helper function that concatenates all of these lines into a single string.

Community
  • 1
  • 1
DRobinson
  • 4,441
  • 22
  • 31
  • Nope, adding `>` at the end of that kind of statement isn't valid haml. Doesn't work for me. – Dogbert Aug 08 '12 at 12:07
  • You're absolutely right, not sure what I was thinking but the `>` modifier is not available on ruby print lines. Probably best off using `succeed` or a helper function with minor string manipulation. – DRobinson Aug 08 '12 at 13:14
0

As of right now (October 21, 2012), there's no way to elegantly do this.

If it is possible when you read this, please do answer the question, and I'll mark it as the answer.

Dogbert
  • 212,659
  • 41
  • 396
  • 397
-5

Open ur code in adobe dreamwever and pres ctrl + f ..

write below code and with tick regular expression box

in find box : [\r\n]{2,}

in replace box : \n

n replace all...

enjoyyyy