I was adding AutoYast support to the registration module and found a nice improvement
for creating RichText messages.
The current approach is using the Summary module, so for displaying the
overview of the current AutoYast configuration I used code like this:
summary = ""
summary = Summary.AddHeader(summary, _("Registration Settings"))
summary = Summary.OpenList(summary)
summary = Summary.AddListItem(summary, _("Email: %s") % @config.email)
summary = Summary.CloseList(summary)
This does not look nice.
Then I realized that RichText content is actually an HTML subset.
And for rendering HTML Ruby has a native support: ERB templates.
They are used in Ruby on Rails for rendering web pages so it should work
for Yast RichText as well.
I found out that it is actually very easy to use ERB, just create the summary using
ERB template like for any other RoR application:
<h3><%= _("Registration Settings") %></h3>
<li><%= _("Email: %s") % h((a)config.email) %></li>
This looks much better! (Notice the h() method for escaping <>& characters in
Then simply render it when needed:
erb = ERB.new(File.read("summary.erb"))
# render the ERB template in the context of the current object
# i.e. the @config attribute is accessible for the ERB renderer
summary = erb.result(binding)
And that's it!
I have added support for *.erb files in the latest y2makepot so even the translatable
strings from *.erb files are correctly extracted to POT files.
Note: real code needs a small trick with specifying the textdomain
for y2makepot, see the full change in yast2-registration .
Appliance department / YaST Developer
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960
To unsubscribe, e-mail: yast-devel+unsubscribe(a)opensuse.org
To contact the owner, e-mail: yast-devel+owner(a)opensuse.org