Make help text an instance variable and

overridable in maybe_with_help.
pull/6827/head
Markus Kahl 14 years ago
parent 24aaed4c51
commit 83c0fb0378
  1. 19
      lib/widget/base.rb

@ -11,26 +11,35 @@ class Widget::Base < Widget
end
def render_with_options(options = {}, &block)
help_text = options[:help_text]
if canvas = options[:to]
canvas << "\n" << render(&block)
else
render(&block)
end
end
##
# An optional help text. If defined the Help Widget
# displaying the given text is going to be placed
# next to this Widget, if it supports that.
def help_text; end
def help_text
@help_text
end
def help_text=(text)
@help_text = text
end
##
# Appends the Help Widget with this Widget's help text
# if it is defined to the input.
# If the help text is not defined the input is returned.
def maybe_with_help(html, options = {})
if help_text
help = render_widget Widget::Controls::Help, help_text do
text = options[:text]
text ||= help_text unless options[:ignore_default]
if text
help = render_widget Widget::Controls::Help, text do
options
end
html + help

Loading…
Cancel
Save