Haml does try to encode the output properly. When it initially creates the
empty string that's eventually used to build the output HTML, it calls
#encode on that string. However, it does not do so on the text that's being
concatenated to the template, which can cause it to revert to another
encoding. This is partly for performance reasons and partly because it's the
application's responsibility to make sure that the encodings are consistent.

What this basically should come down to is that if you play nice with
encodings, Haml will too.

On Fri, Jan 8, 2010 at 3:50 PM, Phrogz <[email protected]> wrote:

> On Jan 8, 4:22 pm, Phrogz <[email protected]> wrote:
> > Am I doing something incorrect in the following?
> >
> > haml = IO.read( layout )
> > template = Haml::Engine.new( haml, HAML_OPTIONS )
> > result = template.render
> > ( Object.new, :contents=>contents, :page=>self, :global=>@bundle.toc )
> >
> > p RUBY_VERSION, RUBY_PLATFORM,
> >   Encoding.default_external, Encoding.default_internal,
> >   haml.encoding, HAML_OPTIONS, result.encoding
> >
> > "1.9.1"
> > "i386-mingw32"
> > #<Encoding:UTF-8>
> > #<Encoding:UTF-8>
> > #<Encoding:UTF-8>
> > {:format=>:html4, :ugly=>true, :encoding=>"UTF-8"}
> > #<Encoding:ASCII-8BIT>
>
> Ack, the result of posting the question of course led me to the
> answer. This is *not* Haml's fault. The 'contents' String passed as a
> local to the template turned out to be ASCII-8BIT. (BlueCloth 2.0.5
> took a UTF-8 string and handed me back ASCII-8BIT. I'll take it up
> with BlueCloth.)
>
> It would be /nice/ if Haml performed the equivalent of encode
> ( ..., :undef=>:replace ) on the result (not the incoming strings)
> when an encoding is requested, but understandable that it doesn't.
>
> Sorry for the noise; hopefully this will help someone else with a
> similar problem.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haml" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected] <haml%[email protected]>.
> For more options, visit this group at
> http://groups.google.com/group/haml?hl=en.
>
>
>
>
--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Reply via email to