Welcome!

What is StringLayout?

It's a plugin for Ruby on Rails that allows you to specify a string (or string-like object) to be used for your layout.

Why would I want it?

Do you keep your layouts in your database? Ever wanted to pass some RHTML as a string to layout?

With StringLayout, it's as easy as

OutOfController < ApplicationController
    string_layout "Larry<br><%= @content_for_layout %>"
end

How about passing a proc?

OutOfController < ApplicationController
    string_layout proc { |controller| "Moe<br><%= @content_for_layout %>" }
end

What about a symbol?

OutOfController < ApplicationController
    string_layout :curly
end

Those will all work. Just keep in mind that whatever you pass must evaluate to an object that responds to :layout or :to_s.

And you can even use :except => action_a or :only => :action_b, just like with layout.

Installation

Browse the source (Trac or SVN) for the tag you want. Then put it into your vendor/plugins directory, in whatever way makes you happy.

License

MIT, just like Rails.

Unit Tests

StringLayout comes with tests, but they won't pass unless they're run when the plugin is installed in a Rails app. You can run them from RAILS_ROOT, with either of the following:

rake string_layout
rake test:plugins:string_layout

Caveats

Trunk expects Rails 1.1.6. Run the tests (or read the code) to see which version other tags expect.

My hunch is that this plugin won't work with other plugins that muss with layouts. For instance, I would be surprised if it works with the venerable Theme support

Cheers

Have fun. To avoid Trac spam, you can't open tickets. However, you can email me at

[the last letter in the English alphabet]atwzphdotcom





For a complete list of local wiki pages, see TitleIndex.