Module: Bh::BootstrapHelpers
- Defined in:
- lib/bh/bootstrap_helpers.rb
Instance Method Summary collapse
- #card(tabs:, &block) ⇒ Object
- #column(header:, section:, **options, &block) ⇒ Object
-
#edit_link_to(path) ⇒ Object
Display a link with an emoji to edit a resource inside a table.
- #grid(item:, cached: true, &block) ⇒ Object
-
#grid_column(key, value) ⇒ Object
Renders key and value next to each other inside a grid row.
-
#grid_row(&block) ⇒ Object
Renders the block inside a grid row.
- #head_tags ⇒ Object
- #nav(pills:) ⇒ Object
- #nav_link_options_for(path) ⇒ Object
-
#nav_link_to(name, options, &block) ⇒ String
Wraps link_to into a nav-item tab.
- #navbar(options = {}, &block) ⇒ Object
- #navbar_brand(brand) ⇒ Object
- #navbar_collapsable(&block) ⇒ Object
- #navbar_collapse(&block) ⇒ Object
- #navbar_nav(&block) ⇒ Object
- #navbar_toggler ⇒ Object
- #script_tags ⇒ Object
- #table(items:, empty_label:, positioned: false, cached: true, pagy: nil, &block) ⇒ Object
-
#turbo_link_to(name, options, html_options = {}) ⇒ Object
Returns a link_to that opens the link outside of the current turbo frame.
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:, **, &block) case section when :header then tag.th(header, **.merge(scope: :col)) when :body then tag.td(**, &block) end end |
#edit_link_to(path) ⇒ Object
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_tags ⇒ Object
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.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'> #{} #{} <script async src="https://ga.jspm.io/npm:es-module-shims@1.8.2/dist/es-module-shims.js" data-turbo-track="reload"></script> #{} <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 |
#nav(pills:) ⇒ Object
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 |
#nav_link_options_for(path) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/bh/bootstrap_helpers.rb', line 64 def (path) if current_page?(path) # request.path.starts_with? path { class: 'nav-link active', aria: { current: :page } } else { class: 'nav-link' } end end |
#nav_link_to(name, options, &block) ⇒ String
Returns 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, , &block) .merge! () if block_given? tag.li(class: 'nav-item') { link_to name, , (), &block } end |
#navbar(options = {}, &block) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/bh/bootstrap_helpers.rb', line 32 def ( = {}, &block) tag.div class: 'mb-4 border-bottom shadow-sm' do tag.nav class: 'navbar navbar-expand-lg' do tag.div **, &block end end end |
#navbar_brand(brand) ⇒ Object
40 41 42 |
# File 'lib/bh/bootstrap_helpers.rb', line 40 def (brand) tag.div brand, class: 'navbar-brand', data: { controller: 'bh--theme', action: 'dblclick->bh--theme#toggle' } end |
#navbar_collapsable(&block) ⇒ Object
72 73 74 |
# File 'lib/bh/bootstrap_helpers.rb', line 72 def (&block) safe_join [, (&block)] end |
#navbar_collapse(&block) ⇒ Object
82 83 84 |
# File 'lib/bh/bootstrap_helpers.rb', line 82 def (&block) tag.div class: 'collapse navbar-collapse', id: 'navbarSupportedContent', &block end |
#navbar_nav(&block) ⇒ Object
54 55 56 |
# File 'lib/bh/bootstrap_helpers.rb', line 54 def (&block) tag.ul class: 'nav navbar-nav me-auto', &block end |
#navbar_toggler ⇒ Object
76 77 78 79 80 |
# File 'lib/bh/bootstrap_helpers.rb', line 76 def tag. 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_tags ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bh/bootstrap_helpers.rb', line 25 def <<~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 |
#turbo_link_to(name, options, html_options = {}) ⇒ Object
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, , = {}) link_to name, , .merge(data: { turbo_frame: '_top' }) end |