Module: Twitter::Bootstrap::Rails

Defined in:
lib/twitter-bootstrap-rails.rb,
lib/twitter/bootstrap/rails/config.rb,
lib/twitter/bootstrap/rails/engine.rb,
lib/twitter/bootstrap/rails/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VALID_ASSET_MODES =

How the host app loads Bootstrap's assets. rails g bootstrap:install cdn writes an initializer setting this to :cdn; bootstrap:layout reads it to pick its default. Defaults to :static so the layout generator works whether or not that initializer exists.

[:static, :cdn].freeze
VERSION =
"5.4.0"
BOOTSTRAP_VERSION =

The Bootstrap release this gem vendors and links to. The gem version no longer tracks it; this constant is the authoritative statement.

"5.3.8"
POPPER_VERSION =
"2.11.8"
BOOTSTRAP_CDN =

URLs and Subresource Integrity hashes exactly as published on https://getbootstrap.com/docs/5.3/getting-started/introduction/ Bumping Bootstrap means editing this hash and re-vendoring the dist files.

{
  :css => {
    :url => "https://cdn.jsdelivr.net/npm/bootstrap@#{BOOTSTRAP_VERSION}/dist/css/bootstrap.min.css",
    :integrity => "sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB"
  },
  :bundle => {
    :url => "https://cdn.jsdelivr.net/npm/bootstrap@#{BOOTSTRAP_VERSION}/dist/js/bootstrap.bundle.min.js",
    :integrity => "sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI"
  },
  :js => {
    :url => "https://cdn.jsdelivr.net/npm/bootstrap@#{BOOTSTRAP_VERSION}/dist/js/bootstrap.min.js",
    :integrity => "sha384-G/EV+4j2dNv+tEPo3++6LCgdCROaejBqfUeNjuKAiuXbjrxilcCdDz6ZAVfHWe1Y"
  },
  :popper => {
    :url => "https://cdn.jsdelivr.net/npm/@popperjs/core@#{POPPER_VERSION}/dist/umd/popper.min.js",
    :integrity => "sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
  }
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.asset_modeObject

Returns the value of attribute asset_mode.



15
16
17
# File 'lib/twitter/bootstrap/rails/config.rb', line 15

def asset_mode
  @asset_mode
end

.asset_pipelineObject

Which asset pipeline the host app runs. Propshaft (the Rails 8 default) has no Sprockets directives: a //= require line in a manifest is an inert comment there, so assets have to be linked explicitly instead.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/twitter/bootstrap/rails/config.rb', line 33

def asset_pipeline
  return @asset_pipeline if defined?(@asset_pipeline) && @asset_pipeline

  if defined?(::Propshaft)
    :propshaft
  elsif defined?(::Sprockets)
    :sprockets
  else
    :unknown
  end
end

Class Method Details

.cdn?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/twitter/bootstrap/rails/config.rb', line 26

def cdn?
  asset_mode == :cdn
end

.propshaft?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/twitter/bootstrap/rails/config.rb', line 48

def propshaft?
  asset_pipeline == :propshaft
end