Hi, I am trying to write an RSpec 2 extension, which lets me test my templating view logic standalone without loading the "full rails", including controller, routes etc. etc. I simply want to be able to take a String in the form of a valid ERB template and render it, where the @outputbuffer is on (for delayed handling of blocks), and then set any values in the view context and extend it with whatever helper modules that suit the particular context. The ActionView::TestCase, is a bit too "heavy" (includes too much outside of basic view functionality), so I have been looking at ActionView::Template. The #render method takes arguments view and a locals, which I think is a Hash. Is this what I should be aiming to use? Any examples of this kind of usage outside Rails? Kristian -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kristian Mandrup
2010-Aug-25 16:23 UTC
Re: How can I use Rails Erubis templating standalone?
I found the file ''actionpack/template/template_test.rb'', which shows how to run simple templates: def test_basic_template @template = new_template assert_equal "Hello", render end def test_locals @template = new_template("<%= my_local %>") assert_equal "I''m a local", render(:my_local => "I''m a local") end def test_restores_buffer @template = new_template assert_equal "Hello", render assert_equal "original", @obj.my_buffer end But not sure how to make it work with the @output_buffer for blocks, fx when using view helpers that take blocks and such? <% posts.each do |post| %> hello <%= post %> <% end %> Where should I look for this? Is this functionality isolated and demonstrated with test cases somewhere? Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kristian Mandrup
2010-Aug-25 17:52 UTC
Re: How can I use Rails Erubis templating standalone?
After a lot of experimentation and reverse engineering the Rails 3 ActionView code, I figured out this solution: http://gist.github.com/549965 Hope it can help others with a similar need ;) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.