tagz and entities

  • Thread starter Joel VanderWerf
  • Start date
J

Joel VanderWerf

Is this how tagz.<< is supposed to work? It seems that << and #concat
behave differently w.r.t. entity quoting.

require 'tagz'
include Tagz.globally

arrow = "&uarr;"
html = html_ {
___
tagz << arrow
___
tagz.concat arrow
___
___ arrow
}

puts html

__END__

Output:

<html>
&amp;uarr;
&uarr;

&uarr;
</html>
 
J

Joel VanderWerf

ara.t.howard said:
correct. escape in the normal case (<<) but concat works directly
without quoting.

Thanks. That seems a bit arbitrary since these methods are the same for
strings. It's something you just have to remember, but then forget when
you come back to the code after a while.

Would it be possible for the object returned by #tagz to have a method,
say #literally or #unescaped, which returns an object which delegates
back to the original. On the original Tagz::Document, #<< and #concat
have the same quoting behavior. On the delegator, they do not quote.

Just a thought...
 
A

ara.t.howard

Thanks. That seems a bit arbitrary since these methods are the same
for strings. It's something you just have to remember, but then
forget when you come back to the code after a while.

yeah i can see that. i was thinking more of erb's concat - which
appends literal objects.

Would it be possible for the object returned by #tagz to have a
method, say #literally or #unescaped, which returns an object which
delegates back to the original. On the original Tagz::Document, #<<
and #concat have the same quoting behavior. On the delegator, they
do not quote.

that is kinds of how it works already.

def << string
case string
when Document
super string.to_s
else
super XChar.escape(string.to_s)
end
self
end


and anything returned by tagz *is* a document. you can even do

tagz << tagz('<blink> not escaped </blink>')


maybe i'll just reserver #write of unescaped writing - there needs to
be one shortcut i think.

a @ http://codeforpeople.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top