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
Source
# File lib/whimsy/asf/themes.rb, line 216 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
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
Source
# File lib/whimsy/asf/themes.rb, line 134 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
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
Source
# File lib/whimsy/asf/themes.rb, line 9 def _whimsy_content colstyle='col-lg-11' _div.content.container_fluid do _div.row do _div class: colstyle do yield end end end end
DEPRECATED Wrap content with nicer fluid margins
Source
# 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
Utility function for divs around form controls, including help Note: passes :groupclass thru to input-group control for styling
Source
# 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
Emit a form control based on a hash of options with a type:
Source
# File lib/whimsy/asf/themes.rb, line 20 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.html' _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
Emit simplistic copyright footer
Source
# File lib/whimsy/asf/forms.rb, line 149 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]&.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]&.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
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
Source
# File lib/whimsy/asf/forms.rb, line 27 def _whimsy_forms_iconlink(**args) if args[:iconlink] _div.input_group_btn do _a.btn.btn_default type: 'button', aria_label: iconlabel, href: args[:iconlink], target: 'whimsy_help' do _span.glyphicon class: args[:icon], aria_label: args[:iconlabel] end end elsif args[:icon] _span.input_group_addon do _span.glyphicon class: args[:icon], aria_label: args[:iconlabel] end elsif ['radio', 'checkbox'].include?(args[:type]) # No-op: do not include blank addon for these controls else _span.input_group_addon # HACK: include blank addon to ensure consistent sizing end end
Utility function to add icons after form controls
Source
# 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] readonly = args[:readonly] || false _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], readonly: readonly 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], readonly: readonly end end end
Display a single input control within a form; or if rows, then a textarea @param name required string ID of control’s label/id
Source
# File lib/whimsy/asf/forms.rb, line 100 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
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)
Source
# 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
Display a subheader separator between sections of a form @param text string to display
Source
# File lib/whimsy/asf/forms.rb, line 183 def _whimsy_forms_submit(value: 'submit') _div.col_sm_offset_3.col_sm_9 do _input.btn.btn_default type: 'submit', value: value end end
Source
# File lib/whimsy/asf/themes.rb, line 37 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
Emit a panel with title and body content
Source
# File lib/whimsy/asf/themes.rb, line 51 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
Emit a panel with helpblock and table getbootstrap.com/components/#panels-tables
Source
# File lib/whimsy/asf/forms.rb, line 191 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
Gather POST form data into submission Hash @returns {field: ‘string’, field2: [‘array’, ‘only for’, ‘multivalue’] …}