Chris Parrish wrote:
> In an extension I'm working on, I'd like to define some medium to large
> blocks of dynamic html to be inserted via a single radius tag.  Because
> this html isn't just a line or two and is tied to models and their data,
> I'd love to be able to create a true rails partial and tell the snippet
> to behave as a pseudo-controller and render the view in place of the
> radius tag.
> 
> I'm trying to keep a separation of concerns here and keep my code clean
> (and make use of all the html/erb sugar already built into rails).
> 
> I don't suppose that there's any way to have a tag call 'render :partial
> => ...' much less get around the rails double-render when the
> SiteController tries to render.  Clever thoughts anyone?
> 
> -Chris

Hi Chris,

I've a simple example how you can do this:

Model:

require 'radius'
class Content < ActiveRecord::Base
def body
    context = Radius::Context.new do |c|
         c.define_tag 'render' do |tag|
           content = "<!--partial-->[render]=" + tag.attr['partial'] + 
"<!--partial-->"
    end
    end
    parser = Radius::Parser.new(context, :tag_prefix => 'r')
    return parser.parse('<p>hello <r:render 
partial="partials/google_adsense" /></p>')
end
end

View:

<div class="body">
<% @content.body.split("<!--partial-->").each do |body| %>
  <% if body.include?("[render]=") %>
  <%= render :partial=>body.split("[render]=")[1] %>
  <% else %>
  <%= markdown(body) %>
  <% end %>
<% end %>
</div>


Maybe i could help you
-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to