class Wunderbar::HtmlMarkup

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 207
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 ) { || ... } 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
  )
  _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: "panel-info" 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

# File lib/whimsy/asf/forms.rb, line 23
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.input_group 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_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_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

# File lib/whimsy/asf/forms.rb, line 42
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! args do
        _! args[:value]
      end
    else
      _input args
    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 @param options required ['value'] or {“value” => 'Label for value'} of all selectable values @param values required '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 65
def _whimsy_forms_select(**args)
  return unless args[:name]
  return unless args[:values]
  args[:label] ||= 'Select value(s)'
  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 args 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_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