Mailinglist Archive: yast-devel (62 mails)

< Previous Next >
[yast-devel] Using ERB templates for RichText in Yast


I was adding AutoYast support to the registration module and found a nice
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") %
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
ERB template like for any other RoR application:


<h3><%= _("Registration Settings") %></h3>
<li><%= _("Email: %s") % h( %></li>

This looks much better! (Notice the h() method for escaping <>& characters in
the value!)

Then simply render it when needed:

erb ="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
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 [1].




Ladislav Slez√°k
Appliance department / YaST Developer
Lihovarsk√° 1060/12
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages