Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Preventing newlines in :preserve'd text from being escaped
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Twisol  
View profile  
 More options Oct 24, 3:47 pm
From: Twisol <solu...@hotmail.com>
Date: Sat, 24 Oct 2009 12:47:41 -0700 (PDT)
Local: Sat, Oct 24 2009 3:47 pm
Subject: Preventing newlines in :preserve'd text from being escaped
Hello,

So far I really love Haml, but I have an issue with it where it comes
to preformatted text.I have a fairly large amount of preformatted text
(generated on the fly by a Rails helper) that I'm trying to include
into my page. Using the :preserve filter, it /looks/ fine, but in the
source it's all on one line, word-wrapped to about thirty, and
completely indecipherable.

I discussed this briefly with Nex3 on IRC, but he had to run. While
writing this message, though, I did have an idea: would it be possible
to add another tag prefix, using either a _ (underscore) or a |
(pipe), to tell Haml that the tag's indentation (or at least its
content) should be reset? Nex3 had mentioned that Haml couldn't
determine when it was safe to perserve the literal newlines because it
automatically indents text, but if you used | to reset indentation, it
seems like it would be safer for Haml to do. If that was possible, I
think "%pre|<" would work perfectly for my purposes.

Otherwise, some advice would be very much appreciated! Thanks in
advance,
~Jonathan Castello


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Weizenbaum  
View profile  
 More options Oct 24, 4:10 pm
From: Nathan Weizenbaum <nex...@gmail.com>
Date: Sat, 24 Oct 2009 13:10:34 -0700
Local: Sat, Oct 24 2009 4:10 pm
Subject: Re: [haml] Preventing newlines in :preserve'd text from being escaped

First of all, filters like :preserve aren't meant for handling
dynamically-generated text; they're meant for handling literal, in-template
text with maybe some dynamic stuff sprinkled in. If you're dynamically
generating text, it's better to use the #preserve helper (or ~, which is a
shortcut for same).

As for the source code aesthetics, as I mentioned on IRC, there's really no
good way to tell when it's possible to not use newline entities. Declaring
it in the template won't work, because it's *not* safe in that template -
the template still needs to be included in the layout, which will re-indent
it and cause the whitespace to go wrong. The only potential solution is to
have some way of declaring "this template is never going to be included in
another template", something that might be added in the future.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Eppstein  
View profile  
 More options Oct 24, 4:19 pm
From: Chris Eppstein <ch...@eppsteins.net>
Date: Sat, 24 Oct 2009 13:19:11 -0700
Local: Sat, Oct 24 2009 4:19 pm
Subject: Re: [haml] Re: Preventing newlines in :preserve'd text from being escaped

Can't haml have some concept of a pre-formatted bit that gets set and then
is sticky for the rest of the handling of that template? If the bit is set,
haml layouts wouldn't re-indent those strings. This decision could be made
dynamically and helpers could be made to help manage the formatting bit.

chris

(Implementation suggestion: haml can return an extended string object for
tracking the state of preformatting)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Weizenbaum  
View profile  
 More options Oct 24, 4:21 pm
From: Nathan Weizenbaum <nex...@gmail.com>
Date: Sat, 24 Oct 2009 13:21:20 -0700
Local: Sat, Oct 24 2009 4:21 pm
Subject: Re: [haml] Re: Preventing newlines in :preserve'd text from being escaped

Potentially, yes, but that would dramatically increase the cost of string
concatenation, which is something we desperately want to avoid, since string
concatenation happens a lot during the rendering of a Haml template.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Twisol  
View profile  
 More options Oct 24, 4:24 pm
From: Twisol <solu...@hotmail.com>
Date: Sat, 24 Oct 2009 13:24:32 -0700 (PDT)
Local: Sat, Oct 24 2009 4:24 pm
Subject: Re: Preventing newlines in :preserve'd text from being escaped
I've converted the offending preformatted partials back to ERb, since
this seems like a good place for it. Now my only issue is the
indentation, because the layout file is still Haml. If the | mark I
suggested was added, to reset indentation, it would make it easier to
include ERb partials like this, and my problem would be duly solved.

On Oct 24, 1:21 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Weizenbaum  
View profile  
 More options Oct 24, 4:59 pm
From: Nathan Weizenbaum <nex...@gmail.com>
Date: Sat, 24 Oct 2009 13:59:49 -0700
Local: Sat, Oct 24 2009 4:59 pm
Subject: Re: [haml] Re: Preventing newlines in :preserve'd text from being escaped

Converting the partials to ERB isn't going to help, since (as you noted) the
issue comes from the Haml layout re-indenting the code. I don't see how a
syntactic marker could help this, unless you want the entire partial to be
un-indented. A better solution would be to make an unpreserve helper that
you wrap your partial calls in in the layout that converts newline entities
into actual newlines.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Twisol  
View profile  
 More options Oct 24, 5:15 pm
From: Twisol <solu...@hotmail.com>
Date: Sat, 24 Oct 2009 14:15:51 -0700 (PDT)
Local: Sat, Oct 24 2009 5:15 pm
Subject: Re: Preventing newlines in :preserve'd text from being escaped
That's exactly what I'd like to do: make the entire partial
unindented. I envision a | mark resetting the indentation level for
the tag it's used on; if there are nested tags, they would still be
indented, but relative to the reset level. When used with my ERb
partials, I'm basically saying that I'm taking indentation into my own
hands, which is precisely what I require for my preformatted text.

I'll look into writing an unpreserve helper, but I still like the
(perceived) elegance of my | suggestion. Thanks for your time.

On Oct 24, 1:59 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Twisol  
View profile  
 More options Oct 24, 8:13 pm
From: Twisol <solu...@hotmail.com>
Date: Sat, 24 Oct 2009 17:13:07 -0700 (PDT)
Local: Sat, Oct 24 2009 8:13 pm
Subject: Re: Preventing newlines in :preserve'd text from being escaped
After attempting to write an 'unpreserve' helper (which merely gsub's
HTML-entity newlines into literal newlines), I'm still suffering the
exact same indentation issues. It seems like, currently, there's just
no way to stop indentation -and- preserve literal newlines. :perserve
does the former, and ~ the latter, but I can't for the life of me
produce both effects.

On Oct 24, 2:15 pm, Twisol <solu...@hotmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Weizenbaum  
View profile  
 More options Oct 25, 3:28 pm
From: Nathan Weizenbaum <nex...@gmail.com>
Date: Sun, 25 Oct 2009 12:28:03 -0700
Local: Sun, Oct 25 2009 3:28 pm
Subject: Re: [haml] Re: Preventing newlines in :preserve'd text from being escaped

I guess you'd need unpreserve along with some way of not indenting the
partial. Or you could simply run #unpreserve on the finished template once
it's rendered. In any case, I don't want to add new syntax to Haml for what
amounts to a relatively minor, purely aesthetic issue.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Twisol  
View profile  
 More options Oct 25, 6:48 pm
From: Twisol <solu...@hotmail.com>
Date: Sun, 25 Oct 2009 15:48:06 -0700 (PDT)
Local: Sun, Oct 25 2009 6:48 pm
Subject: Re: Preventing newlines in :preserve'd text from being escaped
Pardon my naiveté, but could you give me an example of how to go about
doing that? I've tried using my homemade unpreserve helper at many
points along the chain of partials, with no real success.

On Oct 25, 12:28 pm, Nathan Weizenbaum <nex...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Weizenbaum  
View profile  
 More options Oct 29, 2:07 am
From: Nathan Weizenbaum <nex...@gmail.com>
Date: Wed, 28 Oct 2009 23:07:21 -0700
Local: Thurs, Oct 29 2009 2:07 am
Subject: Re: [haml] Re: Preventing newlines in :preserve'd text from being escaped

You'll need to get access to the final template text and unpreserve that.
That'll take some monkeypatching of Rails to get right.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google