• Stars
    star
    2,003
  • Rank 22,143 (Top 0.5 %)
  • Language SCSS
  • License
    MIT License
  • Created over 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bootstrap rubygem for Rails / Sprockets / Hanami / etc

Bootstrap Ruby Gem CI Gem

Bootstrap 5 ruby gem for Ruby on Rails (Sprockets/Importmaps) and Hanami (formerly Lotus).

For Sass versions of Bootstrap 3 and 2 see bootstrap-sass instead.

Ruby on Rails Note: Newer releases of Rails have added additional ways for assets to be processed. The twbs/bootstrap-rubygem is for use with Importmaps or Sprockets, but not Webpack.

Installation

Please see the appropriate guide for your environment of choice:

a. Ruby on Rails

Add bootstrap to your Gemfile:

gem 'bootstrap', '~> 5.3.0.alpha3'

Ensure that sprockets-rails is at least v2.3.2.

bundle install and restart your server to make the files available through the pipeline.

Import Bootstrap styles in app/assets/stylesheets/application.scss:

// Custom bootstrap variables must be set or imported *before* bootstrap.
@import "bootstrap";

The available variables can be found here.

Make sure the file has .scss extension (or .sass for Sass syntax). If you have just generated a new Rails app, it may come with a .css file instead. If this file exists, it will be served instead of Sass, so rename it:

$ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss

Then, remove all the *= require and *= require_tree statements from the Sass file. Instead, use @import to import Sass files.

Do not use *= require in Sass or your other stylesheets will not be able to access the Bootstrap mixins and variables.

Bootstrap JavaScript can optionally use jQuery. If you're using Rails 5.1+, you can add the jquery-rails gem to your Gemfile:

gem 'jquery-rails'

Bootstrap tooltips and popovers depend on popper.js for positioning. The bootstrap gem already depends on the popper_js gem.

Importmaps

You can pin either bootstrap.js or bootstrap.min.js in config/importmap.rb as well as popper.js:

pin "bootstrap", to: "bootstrap.min.js", preload: true
pin "@popperjs/core", to: "popper.js", preload: true

Whichever files you pin will need to be added to config.assets.precompile:

# config/initializers/assets.rb
Rails.application.config.assets.precompile += %w(bootstrap.min.js popper.js)

Sprockets

Add Bootstrap dependencies and Bootstrap to your application.js:

//= require jquery3
//= require popper
//= require bootstrap-sprockets

While bootstrap-sprockets provides individual Bootstrap components for ease of debugging, you may alternatively require the concatenated bootstrap for faster compilation:

//= require jquery3
//= require popper
//= require bootstrap

b. Other Ruby frameworks

If your framework uses Sprockets or Hanami, the assets will be registered with Sprockets when the gem is required, and you can use them as per the Rails section of the guide.

Otherwise you may need to register the assets manually. Refer to your framework's documentation on the subject.

Configuration

Sass: Autoprefixer

Bootstrap requires the use of Autoprefixer. Autoprefixer adds vendor prefixes to CSS rules using values from Can I Use.

If you are using bootstrap with Rails, autoprefixer is set up for you automatically. Otherwise, please consult the Autoprefixer documentation.

Sass: Individual components

By default all of Bootstrap is imported.

You can also import components explicitly. To start with a full list of modules copy _bootstrap.scss file into your assets as _bootstrap-custom.scss. Then comment out components you do not want from _bootstrap-custom. In the application Sass file, replace @import 'bootstrap' with:

@import 'bootstrap-custom';

More Repositories

1

bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
JavaScript
167,231
star
2

ratchet

Build mobile apps with simple HTML, CSS, and JavaScript components.
CSS
14,583
star
3

bootstrap-sass

Official Sass port of Bootstrap 2 and 3.
SCSS
12,614
star
4

icons

Official open source SVG icon library for Bootstrap.
JavaScript
7,116
star
5

rfs

✩ Automates responsive resizing ✩
CSS
3,280
star
6

bootlint

HTML linter for Bootstrap projects
JavaScript
2,394
star
7

bootstrap-npm-starter

Starter template for new building with Bootstrap 4 in npm projects.
HTML
1,225
star
8

bootstrap-expo

Beautiful and inspiring uses of Bootstrap.
SCSS
476
star
9

examples

Functional examples of using Bootstrap in common JS frameworks like Webpack, Parcel, Vite, and more!
HTML
297
star
10

blog

Official blog for Bootstrap.
HTML
227
star
11

bootstrap-server

The node server that powers the bootstrap customize page (no longer maintained).
JavaScript
177
star
12

stylelint-config-twbs-bootstrap

Stylelint config for Bootstrap
JavaScript
139
star
13

no-carrier

Tool to auto-close old GitHub issues that were abandoned by their reporter
Scala
132
star
14

release

Bootstrap Release Working Group
111
star
15

rorschach

Bootstrap pull request sanity checker bot
Scala
105
star
16

mq4-hover-shim

A shim for the Media Queries Level 4 `hover` media feature
JavaScript
97
star
17

grunt-bootlint

A Grunt wrapper for Bootlint, the HTML linter for Bootstrap projects
JavaScript
64
star
18

savage

Service to safely run Travis CI tests with heightened permissions on pull requests
Scala
45
star
19

bootstrap-npm

Demo for how to include, customize, and compile Bootstrap's Sass/CSS with npm.
HTML
32
star
20

grunt-css-flip

UNMAINTAINED Grunt plugin for Twitter's css-flip.
JavaScript
23
star
21

gruntworker

Periodically grabs changes, runs build scripts, and pushes built changes back to the Bootstrap git repo
Python
19
star
22

bootlint-server

JavaScript
6
star
23

.github

6
star