Textile with ERB

B

Bill Atkins

I'm trying to use Textile and ERB together for a website I'm
developing. Basically, a sample file looks like:

---

<%= produce_some_output "param" %>

Here's some *Textile* text.


---

I want the ERB code to be evaluated and I also want the Textile markup
translated into HTML. How can I do this? Right now I'm doing:

s = File.read "myfile.rhtml"
result = RedCloth.new(ERB.new(s).result).to_html

The problem is that the produce_some_output function prints out the
opening <html>, <body>, and <head> tags. RedCloth surrounds this with
<p> tags and thus prevents the page from rendering properly. I tried
running ERB after RedCloth, but RedCloth converted the quotes in the
ERB code to HTML entities.

How can I make this work?

Bill Atkins
 
C

Chad Fowler

I'm trying to use Textile and ERB together for a website I'm
developing. Basically, a sample file looks like:

---

<%= produce_some_output "param" %>

Here's some *Textile* text.

---

I want the ERB code to be evaluated and I also want the Textile markup
translated into HTML. How can I do this? Right now I'm doing:

s = File.read "myfile.rhtml"
result = RedCloth.new(ERB.new(s).result).to_html

The problem is that the produce_some_output function prints out the
opening <html>, <body>, and <head> tags.

This is really the problem, right? Who wrote the produce_some_output
method? There doesn't appear to be an inherent problem with
comingling erb and RedCloth. You would have the same problem if you
replaced the call to produce_some_output with embedded <html>, <body>,
and <head> tags. Maybe I'm misunderstanding.

If you can't change the produce_some_output method to have it stop
returning the unwanted HTML tags, then you could hack the HTML tags
out with gsub, or (more accurate--more of a pain) use something like
the ruby htmltools library to properly parse the output and return
only the sub-nodes you want. Yuck. :)

Chad
 
B

Bill Atkins

Gosh. The problem was indeed in the produce_some_output method. :) Thanks.

I need to start thinking about problems more thoroughly before posting
them here.

Bill
 
B

Bill Atkins

I spoke too soon. I'm still having the problem. Even if i replace
the method call with <%= "<html>\n\ntext" %> it gets wrapped in <p>'s.
I was trying to avoid the gsub solution, but that's looking like my
best bet right now. Hmm.

Bill
 
B

Bill Atkins

OK, my solution (for anyone who's interested) was to put all textile
code between <textile>...</textile> blocks and then just transform the
text between the <textile> delimiters.

Bill
 
J

James Britt

Bill said:
Gosh. The problem was indeed in the produce_some_output method. :) Thanks.

I need to start thinking about problems more thoroughly before posting
them here.

Oh, not to worry. I've long ago discovered that the fastest way to find
a simple bug is to hit the 'send' button.

James
 

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,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top