Filtered content and indentation

9 views
Skip to first unread message

Lars Olsson

unread,
Oct 13, 2009, 6:25:18 AM10/13/09
to Haml
Hi list,

I have some textile content that I'm inserting into one of my Haml
templates by using the :textile filter. The resulting XHTML works ok,
but the contents generated from textile lacks the nice indentation
that the rest of the template has. Is there a way to properly indent
filtered content (in the resulting XHTML) as well?

/lasso

Nathan Weizenbaum

unread,
Oct 13, 2009, 11:46:22 AM10/13/09
to ha...@googlegroups.com
Not without passing it through some sort of tidy helper that Haml doesn't provide, I'm afraid. Haml only takes responsibility for prettifying the content it generates.

Lars Olsson

unread,
Oct 16, 2009, 5:00:05 AM10/16/09
to Haml
Perhaps something like this? It's ugly, but it works.

require 'rubygems'
require 'haml'
require 'haml/html'
require 'redcloth'

# Method that converts HAML to HTML
def haml2html(haml_data, haml_options = {})
Haml::Engine.new(haml_data, haml_options).render
end

# Method that imports textile inte a HAML template, fixing indentation
def import_textile(textile_data, textile2html_options = {},
html2haml_options = {}, haml2html_options = {})
data = textile_data
data = textile2html(data, textile2html_options)
data = html2haml(data, html2haml_options)
data = haml2html(data, haml2html_options)
data
end

# Method that converts HTML to HAML
def html2haml(html_data, haml_options = {})
Haml::HTML.new(html_data, haml_options).render
end

# Method that converts Textile to HTML
def textile2html(textile_data, textile_options = {})
RedCloth.new(textile_data, textile_options).to_html
end

# Example usage
haml_data = <<EOF
%html
%head
%title Big bang
%body
%p Haml content
= import_textile("<p>*Textile content*</p>", {}, {:xhtml => true})
%p some more haml content
EOF

puts Haml::Engine.new(haml_data).render

/lasso
> > /lasso- Dölj citerad text -
>
> - Visa citerad text -

Nathan Weizenbaum

unread,
Oct 16, 2009, 5:38:08 AM10/16/09
to ha...@googlegroups.com
That seems to me like way more trouble than it's worth.

Lars Olsson

unread,
Oct 16, 2009, 6:54:29 AM10/16/09
to Haml
Thats probably very true... ;)

/lasso
> > > - Visa citerad text -- Dölj citerad text -
Reply all
Reply to author
Forward
0 new messages