Module: Bh::BootstrapHelpers

Defined in:
lib/bh/bootstrap_helpers.rb

Instance Method Summary collapse

Instance Method Details

#card(tabs:, &block) ⇒ Object



44
45
46
47
48
# File 'lib/bh/bootstrap_helpers.rb', line 44

def card(tabs:, &block)
  tag.div class: 'card' do
    safe_join [card_header(tabs: tabs), card_body(&block)]
  end
end

#column(header:, section:, **options, &block) ⇒ Object



90
91
92
93
94
95
# File 'lib/bh/bootstrap_helpers.rb', line 90

def column(header:, section:, **options, &block)
  case section
    when :header then tag.th(header, **options.merge(scope: :col))
    when :body then tag.td(**options, &block)
  end
end

Display a link with an emoji to edit a resource inside a table.



120
121
122
# File 'lib/bh/bootstrap_helpers.rb', line 120

def edit_link_to(path)
  turbo_link_to '➡️', path, class: 'text-decoration-none'
end

#grid(item:, cached: true, &block) ⇒ Object



109
110
111
# File 'lib/bh/bootstrap_helpers.rb', line 109

def grid(item:, cached: true, &block)
  render 'bh/grid', item: item, cached: cached, &block
end

#grid_column(key, value) ⇒ Object

Renders key and value next to each other inside a grid row.



103
104
105
106
107
# File 'lib/bh/bootstrap_helpers.rb', line 103

def grid_column(key, value)
  left = tag.div key, class: 'col-3 p-2 fst-italic'
  right = tag.div value, class: 'col p-2'
  safe_join [ left, right ]
end

#grid_row(&block) ⇒ Object

Renders the block inside a grid row.



98
99
100
# File 'lib/bh/bootstrap_helpers.rb', line 98

def grid_row(&block)
  tag.div class: 'row p-2 border-bottom border-subtle', &block
end

#head_tagsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bh/bootstrap_helpers.rb', line 3

def head_tags
  <<~HEAD.html_safe
    <meta name='viewport' content='width=device-width,initial-scale=1'>
    <meta name='view-transition' content='same-origin'>
    <meta name='turbo-refresh-method' content='morph'>
    <meta name='turbo-refresh-scroll' content='preserve'>
    <meta name='apple-mobile-web-app-capable' content='yes'>
    <meta name='mobile-web-app-capable' content='yes'>
    <meta name='color-scheme' content='light dark'>
    #{csrf_meta_tags}
    #{csp_meta_tag}
    <script async src="https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js" data-turbo-track="reload"></script>
    #{javascript_importmap_tags}
    <link rel='icon' href="/favicon#{'-dev' if Rails.env.development?}.png" type='image/png'>
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
    <link href='https://assets.houseaccount.com/css/bootstrap.min.css' rel='stylesheet'>
    <!-- once it's live: <link href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-VuYVTUAUbEW1A1EgqVmiLTxfqmvVgsV8yG3KeYZmz8aLednYx2pzlYdT4NS041oo" crossorigin="anonymous"> -->
    #{stylesheet_link_tag :app, 'data-turbo-track': 'reload'}
    #{stylesheet_link_tag :bh, 'data-turbo-track': 'reload'}
  HEAD
end


50
51
52
# File 'lib/bh/bootstrap_helpers.rb', line 50

def nav(pills:)
  tag.ul pills, class:'nav nav-pills border-bottom pb-3 mb-3'
end


64
65
66
67
68
69
70
# File 'lib/bh/bootstrap_helpers.rb', line 64

def nav_link_options_for(path)
  if current_page?(path) # request.path.starts_with? path
    { class: 'nav-link active', aria: { current: :page } }
  else
    { class: 'nav-link' }
  end
end

Returns wraps link_to into a nav-item tab.

Returns:

  • (String)

    wraps link_to into a nav-item tab.



59
60
61
62
# File 'lib/bh/bootstrap_helpers.rb', line 59

def nav_link_to(name, options, &block)
  options.merge! nav_link_options_for(options) if block_given?
  tag.li(class: 'nav-item') { link_to name, options, nav_link_options_for(options), &block }
end


32
33
34
35
36
37
38
# File 'lib/bh/bootstrap_helpers.rb', line 32

def navbar(options = {}, &block)
  tag.div class: 'mb-4 border-bottom shadow-sm' do
    tag.nav class: 'navbar navbar-expand-lg' do
      tag.div **options, &block
    end
  end
end


40
41
42
# File 'lib/bh/bootstrap_helpers.rb', line 40

def navbar_brand(brand)
  tag.div brand, class: 'navbar-brand', data: { controller: 'bh--theme', action: 'dblclick->bh--theme#toggle' }
end


72
73
74
# File 'lib/bh/bootstrap_helpers.rb', line 72

def navbar_collapsable(&block)
  safe_join [navbar_toggler, navbar_collapse(&block)]
end


82
83
84
# File 'lib/bh/bootstrap_helpers.rb', line 82

def navbar_collapse(&block)
  tag.div class: 'collapse navbar-collapse', id: 'navbarSupportedContent', &block
end


54
55
56
# File 'lib/bh/bootstrap_helpers.rb', line 54

def navbar_nav(&block)
  tag.ul class: 'nav navbar-nav me-auto', &block
end


76
77
78
79
80
# File 'lib/bh/bootstrap_helpers.rb', line 76

def navbar_toggler
  tag.button class: 'navbar-toggler', type: 'button', data: {'bs-toggle': 'collapse', 'bs-target': '#navbarSupportedContent'}, aria: {controls: 'navbarSupportedContent', expanded: 'false', label: 'Toggle navigation'} do
    tag.span nil, class: 'navbar-toggler-icon'
  end
end

#script_tagsObject



25
26
27
28
29
30
# File 'lib/bh/bootstrap_helpers.rb', line 25

def script_tags
  <<~SCRIPTS.html_safe
    <script src='https://assets.houseaccount.com/js/bootstrap.bundle.min.js'></script>
    <!-- once it's live: <script src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-kBqjI9J+3T2+popvAtxRzS3v5xO7BkyKlAyF/GZgnB0kZ2HoQdx6V1I/EX8ljPWj" crossorigin="anonymous"></script> -->
  SCRIPTS
end

#table(items:, empty_label:, positioned: false, cached: true, pagy: nil, &block) ⇒ Object



86
87
88
# File 'lib/bh/bootstrap_helpers.rb', line 86

def table(items:, empty_label:, positioned: false, cached: true, pagy: nil, &block)
  render 'bh/table', items: items, empty_label: empty_label, positioned: positioned, cached: cached, headers: headers, pagy: pagy, &block
end
Note:

Helpful for links within an administered/table that uses +turbo_action: :advance+.

Returns a link_to that opens the link outside of the current turbo frame.



115
116
117
# File 'lib/bh/bootstrap_helpers.rb', line 115

def turbo_link_to(name, options, html_options = {})
  link_to name, options, html_options.merge(data: { turbo_frame: '_top' })
end