# Rendering radius inside preview extension

**URL:** <https://www.ruby-forum.com/t/rendering-radius-inside-preview-extension/111392>\
**Category:** Radiant CMS\
**Created:** [August 6, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/rendering-radius-inside-preview-extension/111392 "2007-08-06T21:47:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Micah\_Wylde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@Micah\_Wylde](https://www.ruby-forum.com/u/Micah_Wylde)\
**Post date:** [August 6, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/rendering-radius-inside-preview-extension/111392/1 "2007-08-06T21:47:17Z")

</div>

Hi, everyone. I’m new to Radiant, developing my first Radiant-powered  
site.  
I’ve developed a preview extension, which injects via javascript a  
preview  
link into the page editor, which when clicked hides the textbox and  
shows a  
div filled with the preview (obtained through Ajax.Updater). To  
accomplish  
this, I have a controller method which takes the raw text from the  
textbox  
and returns rendered html. My problem is, while my method works fine for  
built-in radius tags, it does not work for radius tags defined in  
extensions. My code is below.  
def filter\_text(filter, text, slug)  
filterClass = nil  
eval(“filterClass = #{filter}Filter”)  
filter = filterClass.new  
filteredText = filter.filter(text)  
page = Page.find(:first, :conditions =\> [“slug = ?”, slug])  
context = PageContext.new(page)  
parser = Radius::Parser.new(context, :tag\_prefix =\> ‘r’)  
begin  
return parser.parse(filteredText);  
rescue  
return filteredText  
end  
end

I admit that I don’t really have much of an idea of what I’m doing here.  
I’ve been looking through the code of Radiant trying to figure out how  
it  
does it, but I’ve been unable to find the place where it actually does  
the  
rendering (I assume it’s somewhere in the Page model, but the only  
radius  
code I’ve been able to find there I’ve replicated above). Any help would  
be  
greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Micah\_Wylde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@Micah\_Wylde](https://www.ruby-forum.com/u/Micah_Wylde)\
**Post date:** [August 6, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/rendering-radius-inside-preview-extension/111392/2 "2007-08-06T23:23:24Z")

</div>

Micah,

Feel free to rip the controller code from the page\_preview extension  
that I wrote for the facets branch. The code is here:

[http://dev.radiantcms.org/radiant/browser/branches/facets/extensions/page\_preview/lib/preview\_controller\_extensions.rb](http://dev.radiantcms.org/radiant/browser/branches/facets/extensions/page_preview/lib/preview_controller_extensions.rb)

This module is included into the admin/page controller, giving it a  
“preview” action. Essentially it wraps the creating and updating of  
associated page-parts in a transaction, then raises an exception so the  
transaction rolls back. However, the render has happened already inside  
the transaction, so you get the page as it would look on the site.

Enjoy!

Sean

---

<div class="post-metadata">

**Author:** ![Micah\_Wylde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@Micah\_Wylde](https://www.ruby-forum.com/u/Micah_Wylde)\
**Post date:** [August 7, 2007, 12:46am UTC](https://www.ruby-forum.com/t/rendering-radius-inside-preview-extension/111392/3 "2007-08-07T00:46:32Z")

</div>

I’ve looked at that code, but I’m having some trouble understanding a  
lot of  
it, in particular the call to handle\_new\_or\_edit\_post, which seems to do  
something very different in the trunk than it does in the facets branch.  
Additionally, I’d rather not save the page (which is what that extension  
appears to do). Is there a simple way to modify my code so that it will  
import non-radiant radius tags?

---

<div class="post-metadata">

**Author:** ![Micah\_Wylde](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9d8465/32.png) [@Micah\_Wylde](https://www.ruby-forum.com/u/Micah_Wylde)\
**Post date:** [August 7, 2007, 1:27am UTC](https://www.ruby-forum.com/t/rendering-radius-inside-preview-extension/111392/4 "2007-08-07T01:27:36Z")

</div>

It doesn’t actually save the page. When exceptions are raised inside a  
transaction, they rollback.

Sean
