class Wunderbar::HtmlMarkup

Define common page features for whimsy tools using bootstrap styles

Define common page features for whimsy tools using bootstrap styles

Define common page features for whimsy tools using bootstrap styles

Public Instance Methods

_whimsy_accordion_item(listid: 'accordion', itemid: nil, itemtitle: '', n: 0, itemclass: nil) { || ... } click to toggle source

Emit wrapper panels for a single tablist accordion item @param listid of the parent _div.panel_group role: “tablist” @param itemid of this specific item @param itemtitle to display in the header panel @param n unique number of this item (for nav links) @param itemclass optional panel-success or similar styling

# File lib/whimsy/asf/themes.rb, line 208
def _whimsy_accordion_item(listid: 'accordion', itemid: nil, itemtitle: '', n: 0, itemclass: nil)
  raise ArgumentError.new("itemid must not be nil") if not itemid
  args = {id: itemid}
  args[:class] = itemclass if itemclass
  _div!.panel.panel_default args do
    _div!.panel_heading role: "tab", id: "#{listid}h#{n}" do
      _h4!.panel_title do
        _a!.collapsed role: "button", data_toggle: "collapse",  aria_expanded: "false", data_parent: "##{listid}", href: "##{listid}c#{n}", aria_controls: "#{listid}c#{n}" do
          _ "#{itemtitle} "
          _span.glyphicon.glyphicon_chevron_down id: "#{itemid}-nav"
        end
      end
    end
    _div!.panel_collapse.collapse id: "#{listid}c#{n}", role: "tabpanel", aria_labelledby: "#{listid}h#{n}" do
      _div!.panel_body do
        yield
      end
    end
  end
end
_whimsy_body(title: nil, subtitle: 'About This Script', relatedtitle: 'Related Whimsy Links', related: nil, helpblock: nil, breadcrumbs: nil, style: 'panel-info' ) { || ... } click to toggle source

Emit complete bootstrap theme to wrap cgi output, including nav and footer If helpblock or related, then emit helpblock and related* panels before content If breadcrumbs, emit those immediately before content

# File lib/whimsy/asf/themes.rb, line 126
def _whimsy_body(title: nil,
    subtitle: 'About This Script', 
    relatedtitle: 'Related Whimsy Links', 
    related: nil, 
    helpblock: nil,
    breadcrumbs: nil,
    style: 'panel-info'
  )
  _whimsy_nav
  _div.content.container_fluid do
    _div.row do
      _div.col_sm_12 do
        _h1 title if title
      end
    end
    if helpblock or related
      _div.row do
        _div.col_md_8 do
          _whimsy_panel subtitle, style: style do
            if helpblock
              helpblock.call
            else
              _a 'See this code', href: "https://github.com/apache/whimsy/blob/master/www#{ENV['SCRIPT_NAME']}"
            end
          end
        end
        _div.col_md_4 do
          _whimsy_panel relatedtitle, style: "panel-default" do
            _ul list_style_position: 'inside' do
              if related
                related.each do |url, desc|
                  if url =~ /.*\.(png|jpg|svg|gif)\z/i
                    # Extension: allow images, style to align with bullets
                    _li.list_unstyled do
                      _img alt: desc, src: url, height: '60px', style: 'margin-left: -20px; padding: 2px 0px;'
                    end
                  else
                    _li do
                      _a desc, href: url
                    end
                  end
                end
              else
                _li do
                  _a 'See this code', href: "https://github.com/apache/whimsy/blob/master/www#{ENV['SCRIPT_NAME']}"
                end
              end
            end
          end
        end
      end
    end
    _div.row do
      _div.col_sm_12 do
        if breadcrumbs
          _ol.breadcrumb do
            _li do
              _a href: '/' do
                _span.glyphicon.glyphicon_home
              end
            end
            breadcrumbs.each do |name, link|
              _li.active do
                _a name.to_s, href: link
              end
            end
          end
        end
        # Primary content from caller emitted below
        yield
      end
    end
    _whimsy_foot
  end
end
_whimsy_content(colstyle="col-lg-11") { || ... } click to toggle source

DEPRECATED Wrap content with nicer fluid margins

# File lib/whimsy/asf/themes.rb, line 7
def _whimsy_content colstyle="col-lg-11"
  _div.content.container_fluid do
    _div.row do
      _div class: colstyle do
        yield
      end
    end
  end
end
_whimsy_control_wrapper(**args) { || ... } click to toggle source

Utility function for divs around form controls, including help Note: passes :groupclass thru to input-group control for styling

# File lib/whimsy/asf/forms.rb, line 47
def _whimsy_control_wrapper(**args)
  _div.form_group do
    _label.control_label.col_sm_3 args[:label], for: "#{args[:name]}"
    _div.col_sm_9 do
      _div! class: "input-group #{args[:groupclass]}" do
        yield
        _whimsy_forms_iconlink(args)
      end
      if args[:helptext]
        _span.help_block id: "#{args[:aria_describedby]}" do
          _markdown "#{args[:helptext]}"
        end
      end
    end
  end
end
_whimsy_field_chooser(**args) click to toggle source

Emit a form control based on a hash of options with a type:

# File lib/whimsy/asf/forms.rb, line 8
def _whimsy_field_chooser(**args)
  case args[:type]
  when 'subhead'
    _whimsy_forms_subhead label: args[:label]
  when 'text'
    _whimsy_forms_input args
  when 'textarea'
    args[:rows] ||= '3'
    _whimsy_forms_input args
  when 'select'
    _whimsy_forms_select args
  when 'radio', 'checkbox'
    _whimsy_forms_checkradio args
  else
    _div "#{__method__}(#{args[:type]}) TODO: Error condition?"
  end
end
_whimsy_foot() click to toggle source

Emit simplistic copyright footer

# File lib/whimsy/asf/themes.rb, line 18
def _whimsy_foot
  _div.footer.container_fluid style: 'background-color: #f5f5f5; padding: 10px;' do
    _p.center do
      # © and ® don't work here for cgi scripts - see WHIMSY-146
      _{"Copyright \u00A9 #{Date.today.year}, the Apache Software Foundation. Licensed under the "}
      _a 'Apache License, Version 2.0', rel: 'license', href: 'http://www.apache.org/licenses/LICENSE-2.0'
      _ ' | '
      _a 'Privacy Policy', href: 'https://www.apache.org/foundation/policies/privacy'
      _br
      _{"Apache\u00AE, the names of Apache projects, and the multicolor feather logo are "}
      _a 'registered trademarks or trademarks', href: 'https://www.apache.org/foundation/marks/list/'
      _ ' of the Apache Software Foundation in the United States and/or other countries.'
    end
  end
end
_whimsy_forms_checkradio(**args) click to toggle source

Display a list of radio or checkbox controls @param name required string ID of control's label/id @param type required FORM_CHECKBOX|FORM_RADIO @param options required ['value'…] or {“value” => 'Label for value'} of all values @param selected optional 'value' or ['value'…] of all selected values

# File lib/whimsy/asf/forms.rb, line 145
def _whimsy_forms_checkradio(**args)
  return unless args[:name]
  return unless args[:type]
  return unless args[:options]
  args[:label] ||= 'Select value(s)'
  args[:id] = args[:name]
  args[:aria_describedby] = "#{args[:name]}_help" if args[:helptext]
  args[:selected] = [args[:selected]] if args[:selected].kind_of?(String)
  _whimsy_control_wrapper(args) do 
    # Construct list of all :options; mark any that are in :selected 
    if args[:options].kind_of?(Array)
      args[:options].each do |val|
        checked = true if args[:selected] && args[:selected].include?(val.to_s)
        _label class: "#{args[:type]}-inline" do
          _input! type: args[:type], name: args[:name], id: args[:id], value: val, class: args[:class], aria_describedby: args[:aria_describedby], checked: checked do
            _! val
          end
        end
      end
    elsif args[:options].kind_of?(Hash)
      args[:options].each do |val, disp|
        checked = true if args[:selected] && args[:selected].include?(val.to_s)
        _label class: "#{args[:type]}-inline" do
          _input! type: args[:type], name: args[:name], id: args[:id], value: val, class: args[:class], aria_describedby: args[:aria_describedby], checked: checked do
            _! disp
          end
        end
      end
    end
  end
end
_whimsy_forms_input(**args) click to toggle source

Display a single input control within a form; or if rows, then a textarea @param name required string ID of control's label/id

# File lib/whimsy/asf/forms.rb, line 74
def _whimsy_forms_input(**args)
  return unless args[:name]
  args[:label] ||= 'Enter string'
  args[:type] ||= 'text'
  args[:id] = args[:name]
  args[:aria_describedby] = "#{args[:name]}_help" if args[:helptext]
  _whimsy_control_wrapper(args) do
    args[:class] = 'form-control'
    if args[:rows]
      _textarea! type: args[:type], name: args[:name], id: args[:id], value: args[:value], class: args[:class], aria_describedby: args[:aria_describedby], rows: args[:rows] do
        _! args[:value]
      end
    else
      _input type: args[:type], name: args[:name], id: args[:id], value: args[:value], class: args[:class], aria_describedby: args[:aria_describedby]
    end
  end
end
_whimsy_forms_select(**args) click to toggle source

Display an optionlist control within a form @param name required string ID of control's label/id @param options required ['value'] or {“value” => 'Label for value'} of all selectable values @param values 'value' or ['value'] or {“value” => 'Label for value'} of all selected values @param placeholder Currently displayed text if passed (not selectable)

# File lib/whimsy/asf/forms.rb, line 97
def _whimsy_forms_select(**args)
  return unless args[:name]
  return unless args[:options]
  args[:label] ||= 'Select value(s)'
  args[:values] ||= []
  args[:id] = args[:name]
  args[:aria_describedby] = "#{args[:name]}_help" if args[:helptext]
  _whimsy_control_wrapper(args) do 
    if args[:multiple]
      args[:multiple] = 'true'
    end
    _select.form_control type: args[:type], name: args[:name], id: args[:id], value: args[:value], aria_describedby: args[:aria_describedby], multiple: args[:multiple] do
      if ''.eql?(args[:placeholder])
        _option '', value: '', selected: 'selected'
      else
        _option "#{args[:placeholder]}", value: '', selected: 'selected', disabled: 'disabled', hidden: 'hidden'
      end
      # Construct selectable list from values (first) then options
      if args[:values].kind_of?(Array)
        args[:values].each do |val|
          _option val, value: val, selected: true
        end
      elsif args[:values].kind_of?(Hash)
        args[:values].each do |val, disp|
          _option disp, value: val, selected: true
        end
      elsif args[:values] # Fallback for simple case of single string value
        _option "#{args[:values]}", value: "#{args[:values]}", selected: true
        args[:values] = [args[:values]] # Ensure supports .include? for options loop below
      end
      if args[:options].kind_of?(Array)
        args[:options].each do |val|
          _option val, value: val unless args[:values].include?(val)
        end
      elsif args[:options].kind_of?(Hash)
        args[:options].each do |val, disp|
          _option disp, value: val unless args[:values].include?(val)
        end
      end
    end
  end
end
_whimsy_forms_subhead(label: 'Form Section') click to toggle source

Display a subheader separator between sections of a form @param text string to display

# File lib/whimsy/asf/forms.rb, line 66
def _whimsy_forms_subhead(label: 'Form Section')
  _div.form_group do
    _label.col_sm_offset_3.col_sm_9.strong.text_left label
  end
end
_whimsy_nav() click to toggle source

Emit a bootstrap navbar with required ASF links

# File lib/whimsy/asf/themes.rb, line 66
def _whimsy_nav
  _nav.navbar.navbar_default do
    _div.container_fluid do
      _div.navbar_header do
        _button.navbar_toggle.collapsed type: "button", data_toggle: "collapse", data_target: "#navbar_collapse", aria_expanded: "false" do
          _span.sr_only "Toggle navigation"
          _span.icon_bar
          _span.icon_bar
        end
        _a.navbar_brand href: '/' do
          _img title: 'Whimsy project home', alt: 'Whimsy hat logo', src: '/whimsy.svg', height: 30
        end
      end
      _div.collapse.navbar_collapse id: "navbar_collapse" do
        _ul.nav.navbar_nav do
          _li do
            _a 'Code', href: 'https://github.com/apache/whimsy/'
          end
          _li do
            _a 'Questions', href: 'https://lists.apache.org/list.html?dev@whimsical.apache.org'
          end
          _li do
            _a 'About Whimsy', href: '/technology'
          end
        end
        _ul.nav.navbar_nav.navbar_right do
          _li.dropdown do
            _a.dropdown_toggle href: "#", data_toggle: "dropdown", role: "button", aria_haspopup: "true", aria_expanded: "false" do
              _img title: 'Apache Home', alt: 'Apache feather logo', src: 'https://www.apache.org/img/feather_glyph_notm.png', height: 30
              _ ' Apache'
              _span.caret
            end
            _ul.dropdown_menu do
              _li do
                _a 'License', href: 'http://www.apache.org/licenses/'
              end
              _li do
                _a 'Donate', href: 'http://www.apache.org/foundation/sponsorship.html'
              end
              _li do
                _a 'Thanks', href: 'http://www.apache.org/foundation/thanks.html'
              end
              _li do
                _a 'Security', href: 'http://www.apache.org/security/'
              end
              _li.divider role: 'separator'
              _li do
                _a 'About The ASF', href: 'http://www.apache.org/'
              end
            end
          end
        end
      end
    end
  end
end
_whimsy_panel(title, style: 'panel-primary', header: 'h3') { || ... } click to toggle source

Emit a panel with title and body content

# File lib/whimsy/asf/themes.rb, line 35
def _whimsy_panel(title, style: 'panel-primary', header: 'h3')
  _div.panel class: style do
    _div.panel_heading do 
      _.tag! header, class: 'panel-title' do
        _ title
      end
    end
    _div.panel_body do
      yield
    end
  end
end
_whimsy_panel_table(title: 'Table Title', style: 'panel-primary', header: 'h2', helpblock: nil) { || ... } click to toggle source

Emit a panel with helpblock and table getbootstrap.com/components/#panels-tables

# File lib/whimsy/asf/themes.rb, line 49
def _whimsy_panel_table(title: 'Table Title', style: 'panel-primary', header: 'h2', helpblock: nil)
  _div.panel class: style do
    _div.panel_heading do 
      _.tag! header, class: 'panel-title' do
        _ title
      end
    end
    if helpblock
      _div.panel_body do
        helpblock.call
      end
    end
    yield
  end
end
_whimsy_params2formdata(params) click to toggle source

Gather POST form data into submission Hash @returns {field: 'string', field2: ['array', 'only for', 'multivalue'] …}

# File lib/whimsy/asf/forms.rb, line 179
def _whimsy_params2formdata(params)
  formdata = {}
  params.each do |k,v|
    v && (v.length == 1) ? formdata[k] = v[0] : formdata[k] = v
  end
  return formdata
end