Module: MasterView::ConfigInfoHelpers

Defined in:
lib/masterview/masterview_info.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_RENDERING_OPTIONS =

HTML fragment templates; optionally include class/style attributes to control rendering

{
  :title => '<h1>%s</h1>',  #parms: config settings title
  :preamble => '<p><b>MasterView Version:</b> %s</p>',  #parms: MasterView version
  :container => "<table%s>\n<tbody>%s</tbody>\n</table>",  #parms: :container_attrs, section/property entries
  :container_attrs => '',
  :section_entry => '<tr%s><td colspan="2">%s</td></tr>', #parms: :section_attrs, section_name
  :section_attrs => 'style="background-color: #dcdcdc; font-weight: bold; margin-top: 6px;"',
  :option_entry => '<tr><td%s>%s</td><td%s>%s</td></tr>',  #parms: :option_name_attrs, option_name, :option_value_attrs, option_value
  :option_name_attrs => 'style="padding-left: 6px; padding-right: 6px; font-weight: bold;"',
  :option_value_attrs => '',
  :postscript => '',
}
ELEMENTS_WITH_ATTRS =
[ :container, :section_entry ]

Class Method Summary collapse

Class Method Details

.getHtmlTemplate(element_option_name, params, defaults = DEFAULT_RENDERING_OPTIONS) ⇒ Object

Get the option parameter value for an html element; provide default in not specified in client params. Resolve any element attributes so rendering can focus on filling in content entries



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/masterview/masterview_info.rb', line 58

def self.getHtmlTemplate(element_option_name, params, defaults=DEFAULT_RENDERING_OPTIONS)
  element_template = getOption( element_option_name, params, defaults )
  return element_template if element_template == :none
  if ELEMENTS_WITH_ATTRS.include? element_option_name
    attrs_option_name = "#{element_option_name.to_s.split('_')[0]}_attrs".to_sym  # :foo_attrs
    element_attrs = getOption( attrs_option_name, params, defaults )
    # ensure separator space for ' style="xxx"' on the section entry style/class attr(s)
    element_attrs.insert(0, ' ') if (element_attrs && element_attrs != '' && element_attrs[0...1] != ' ')
    element_template = element_template.sub(  '%s', element_attrs )  # resolve the first parm slot in the template to the attrs
  elsif element_option_name == :option_entry
    # double-up: attrs/value template parm pair for both option_name and option_value
    option_entry_name_attrs = getOption( :option_name_attrs, params, defaults )
    option_entry_value_attrs = getOption( :option_value_attrs, params, defaults )
    # ensure separator space for ' style="xxx"' on the option name/value style/class attr(s)
    option_entry_name_attrs.insert(0, ' ') if (option_entry_name_attrs && option_entry_name_attrs != '' && option_entry_name_attrs[0...1] != ' ')
    option_entry_value_attrs.insert(0, ' ') if (option_entry_value_attrs && option_entry_value_attrs != '' && option_entry_value_attrs[0...1] != ' ')
    element_template = element_template % [ option_entry_name_attrs, '%s', option_entry_value_attrs, '%s' ]  # install the optional style settings once, just plug in option name/value hereafter
  end
  element_template
end

.getOption(option_name, params, defaults = DEFAULT_RENDERING_OPTIONS) ⇒ Object

get the option parameter value; provide default in not specified in client params.



52
53
54
# File 'lib/masterview/masterview_info.rb', line 52

def self.getOption(option_name, params, defaults=DEFAULT_RENDERING_OPTIONS)
  params.fetch( option_name, defaults[option_name] )
end