Module: Templet::Mixins::HtmlPresenters

Includes:
Constants
Included in:
Templet::Mixins, Bs::Lists
Defined in:
app/helpers/templet/mixins/html_presenters.rb,
lib/generators/templet/templates/core/templet/mixins/html_presenters.rb

Overview

Helper methods for rendering HTML tables, forms and lists

Constant Summary

Constants included from Constants

Constants::BS_BUTTON, Constants::BS_BUTTON_BLOCK, Constants::BS_BUTTON_DROPDOWN, Constants::BS_BUTTON_GROUP, Constants::BS_BUTTON_GROUP_JUSTIFIED, Constants::BS_BUTTON_GROUP_VERTICAL, Constants::BS_BUTTON_SIZE, Constants::BS_BUTTON_SUBMIT, Constants::BS_BUTTON_SUBMIT_SEARCH, Constants::BS_BUTTON_TOOLBAR, Constants::BS_BUTTON_TYPE, Constants::BS_COL, Constants::BS_COL_OFFSET, Constants::BS_FORM, Constants::BS_FORM_INLINE, Constants::BS_LIST_GROUP, Constants::BS_LIST_GROUP_ITEM, Constants::BS_LIST_INLINE, Constants::BS_LIST_UNSTYLED, Constants::BS_NAV, Constants::BS_NAV_PILLS, Constants::BS_NAV_PILLS_STACKED, Constants::BS_NAV_TABS, Constants::BS_PANEL, Constants::BS_PANEL_BODY, Constants::BS_PANEL_HEADING, Constants::BS_PANEL_TITLE, Constants::BS_SELECTED, Constants::BS_TABLE, Constants::BS_TOOLBAR

Instance Method Summary collapse

Instance Method Details

#default_list_classObject



72
73
74
# File 'app/helpers/templet/mixins/html_presenters.rb', line 72

def default_list_class
  BS_LIST_INLINE
end

#default_table_classObject



19
20
21
# File 'app/helpers/templet/mixins/html_presenters.rb', line 19

def default_table_class
  BS_TABLE
end

#get_list_class(html_class) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/templet/mixins/html_presenters.rb', line 60

def get_list_class(html_class)
  case html_class
  when nil, :default, :inline
    default_list_class
  when true, :stacked
    stacked_list_class
  when false, :none
  else
    html_class
  end
end

#html_definition_list(renderer, controls, record = nil) ⇒ Object

controls

A Hash of field name by Proc which is paassed a model



47
48
49
50
# File 'app/helpers/templet/mixins/html_presenters.rb', line 47

def html_definition_list(renderer, controls, record=nil)
  Templet::Html::DefinitionList.new(renderer)
    .(controls, record, html_class: 'dl-horizontal')
end

#html_form(renderer, form_opts, **group_opts) ⇒ Object

Renders the outside of an HTML form. Usually you feed it a block to specify the various fields.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/templet/mixins/html_presenters.rb', line 25

def html_form(renderer, form_opts, **group_opts)
  if not form_opts.key?(:remote) and respond_to?(:remote?) and remote?
    form_opts[:remote] = true
  end

  height = form_opts.delete(:height) || group_opts[:height]
  group_opts[:height] = height

  Forms::BsForm.new(renderer).(**form_opts) do |renderer|
    field, group = Forms::BsForm.(renderer, model, **group_opts)

    if block_given?
      yield field, group
    else
      form_inputs(field, group) << field.submit
    end
  end
end

#html_list(renderer, items, html_class: nil, item_class: nil) ⇒ Object

items is an Array of (literal) list elements



53
54
55
56
57
58
# File 'app/helpers/templet/mixins/html_presenters.rb', line 53

def html_list(renderer, items, html_class: nil, item_class: nil)
  html_class = get_list_class(html_class)

  Templet::Html::List.new(renderer).(items, html_class: html_class,
                                            item_class: item_class)
end

#html_table(renderer, controls, records, **options) ⇒ Object

controls

Is a Hash of field name by Proc which is passed a record



11
12
13
14
15
16
17
# File 'app/helpers/templet/mixins/html_presenters.rb', line 11

def html_table(renderer, controls, records, **options)
  unless options.key? :html_class
    options[:html_class] = default_table_class
  end

  Templet::Html::Table.new(renderer).(controls, records, **options)
end

#stacked_list_classObject



76
77
78
# File 'app/helpers/templet/mixins/html_presenters.rb', line 76

def stacked_list_class
  BS_LIST_UNSTYLED
end