├── .DS_Store ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── jekyll-bootstrap-sass.gemspec ├── lib ├── bootstrap │ └── bootstrap.rb ├── jekyll-bootstrap-sass.rb └── jekyll-bootstrap-sass │ └── version.rb ├── script ├── bootstrap └── cibuild └── spec ├── fixtures └── style.scss ├── jekyll_bootstrap_sass_spec.rb └── spec_helper.rb /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benbalter/jekyll-bootstrap-sass/d8cf4cf0bf43be1c41f3ab63adbd5ab1497f4430/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | .sass-cache 11 | *.gem 12 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | Style/AlignHash: 2 | EnforcedHashRocketStyle: table 3 | EnforcedColonStyle: table 4 | 5 | Style/Documentation: 6 | Enabled: false 7 | 8 | Lint/EndAlignment: 9 | AlignWith: variable 10 | AutoCorrect: true 11 | 12 | Style/FileName: 13 | Enabled: false 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.3.0 4 | before_install: gem install bundler -v 1.11.2 5 | cache: bundler 6 | sudo: false 7 | script: script/cibuild 8 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in jekyll-bootstrap-sass.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ben Balter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jekyll Bootstrap Sass 2 | 3 | *A plugin to add the [Twitter Bootstrap](https://github.com/twbs/bootstrap) framework to your Jekyll site.* 4 | 5 | [![Build Status](https://travis-ci.org/benbalter/jekyll-bootstrap-sass.svg)](https://travis-ci.org/benbalter/jekyll-bootstrap-sass) 6 | 7 | ## Installation 8 | 9 | Add the following to your site's `Gemfile`: 10 | 11 | ```ruby 12 | gem 'jekyll-bootstrap-sass' 13 | ``` 14 | 15 | And add the following to your site's `_config.yml` file: 16 | 17 | ```yaml 18 | gems: 19 | - jekyll-bootstrap-sass 20 | ``` 21 | 22 | ## Usage 23 | 24 | Create a `.scss` file (e.g., `assets/style.scss`), with the following: 25 | 26 | ```scss 27 | --- 28 | --- 29 | 30 | @import 'bootstrap'; 31 | 32 | // (Your custom CSS Here) 33 | ``` 34 | 35 | When your site is built, Jekyll will automatically add the Bootstrap framework before it renders your site's css. In the above example, the resulting file would be `assets/style.css` with Bootstrap's CSS followed by your own. 36 | 37 | ## Assets 38 | 39 | By default, Jekyll Bootstrap SaSS will simply make the `@import 'bootstrap';` directive available to your custom stylesheets so that you can more easily include Bootstrap's CSS. 40 | 41 | If you would like to use Bootstrap's static assets (e.g., fonts, javascripts), you'll need to add the following to your site's `_config.yml`: 42 | 43 | ```yml 44 | bootstrap: 45 | assets: true 46 | ``` 47 | 48 | This will create `/assets/fonts/bootstrap` and `assets/javascripts/bootstrap` folders in the generated site, which you can include in your site's header as you would any other javascript file or font. 49 | 50 | If font's aren't loading properly, you may need to add the following before the `import` directive: 51 | 52 | ```scss 53 | $icon-font-path: "{{ site.github.url }}/assets/fonts/bootstrap"; 54 | ``` 55 | 56 | ## Specifying the Bootstrap version 57 | 58 | Jekyll-bootstrap-sass relies on official [`bootstrap-sass` Ruby gem](https://github.com/twbs/bootstrap-sass). To specify the version of Bootstrap used, simply specify the `bootstrap-sass` gem version in your Gemfile. 59 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task default: :spec 7 | -------------------------------------------------------------------------------- /jekyll-bootstrap-sass.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'jekyll-bootstrap-sass/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'jekyll-bootstrap-sass' 8 | spec.version = Jekyll::BootstrapSass::VERSION 9 | spec.authors = ['Ben Balter'] 10 | spec.email = ['ben.balter@github.com'] 11 | 12 | spec.summary = 'A plugin to add Twitter Bootstrap to your Jekyll site' 13 | spec.homepage = 'https://github.com/benbalter/jekyll-bootstrap-sass' 14 | spec.license = 'MIT' 15 | 16 | spec.files = `git ls-files -z`.split("\x0").reject do |file| 17 | file.match(%r{^(test|spec|features)/}) 18 | end 19 | spec.require_paths = ['lib'] 20 | 21 | spec.add_dependency 'jekyll', '>= 2.5' 22 | spec.add_dependency 'bootstrap', '~> 4.0.0.alpha6' 23 | 24 | spec.add_development_dependency 'bundler', '~> 1.11' 25 | spec.add_development_dependency 'rake', '~> 10.0' 26 | spec.add_development_dependency 'rspec', '~> 3.0' 27 | spec.add_development_dependency 'rubocop' 28 | end 29 | -------------------------------------------------------------------------------- /lib/bootstrap/bootstrap.rb: -------------------------------------------------------------------------------- 1 | module Bootstrap 2 | class << self 3 | # Monkey patch out a whole bunch of stuff we don't want 4 | def load! 5 | configure_sass 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/jekyll-bootstrap-sass.rb: -------------------------------------------------------------------------------- 1 | require 'jekyll-bootstrap-sass/version' 2 | require 'find' 3 | 4 | # Require bootstrap to add bootstrap to SaSS's load path 5 | require 'bootstrap' 6 | 7 | module Jekyll 8 | module Bootstrap 9 | class Generator < Jekyll::Generator 10 | def generate(site) 11 | @site = site 12 | 13 | # Add our static files to Jekyll's native static file support 14 | @site.static_files.concat static_files if assets_enabled? 15 | end 16 | 17 | private 18 | 19 | # Has the user explictly disabled asset support by adding 20 | # The following to their `_config.yml` file: 21 | # 22 | # bootstrap 23 | # assets: false 24 | def assets_enabled? 25 | return false if @site.config['bootstrap'].nil? 26 | @site.config['bootstrap']['assets'] == true 27 | end 28 | 29 | # Returns an array of Jekyll::StaticFile instances for each file 30 | # in asset_files. Files are prefixed with an `assets/` directory 31 | def static_files 32 | source = File.dirname(assets_path) 33 | asset_files.map do |file| 34 | dir = File.dirname(file) 35 | file_name = File.basename(file) 36 | Jekyll::StaticFile.new @site, source, dir, file_name 37 | end 38 | end 39 | 40 | # Return an array of paths to static files that should be included 41 | # in the generated site. 42 | # 43 | # Note: All paths are relative to the assets_path directory 44 | def asset_files 45 | asset_files = [] 46 | Find.find(assets_path).each do |path| 47 | next if File.directory?(path) 48 | next if path.include?(stylesheets_path) || path.include?(images_path) 49 | asset_files << path.sub(assets_path, 'assets') 50 | end 51 | asset_files 52 | end 53 | 54 | # Absolute path to bootstrap's vendored static assets 55 | def assets_path 56 | @assets_path ||= Bootstrap.assets_path 57 | end 58 | 59 | # Absolute path to bootstrap-sass's images directory 60 | # Which should be excluded because it's empty 61 | def images_path 62 | @imags_path ||= File.expand_path 'images/', assets_path 63 | end 64 | 65 | # Absolute path to bootstrap-sass's stylesheets directory 66 | # Which should be excluded because it's processed by SaSS 67 | def stylesheets_path 68 | @stylesheets_path ||= File.expand_path 'stylesheets/', assets_path 69 | end 70 | end 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /lib/jekyll-bootstrap-sass/version.rb: -------------------------------------------------------------------------------- 1 | module Jekyll 2 | module BootstrapSass 3 | VERSION = '0.1.0' 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /script/bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | bundle install 6 | -------------------------------------------------------------------------------- /script/cibuild: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | bundle exec rake spec 6 | bundle exec rubocop 7 | bundle exec gem build jekyll-bootstrap-sass.gemspec 8 | -------------------------------------------------------------------------------- /spec/fixtures/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import 'bootstrap'; 5 | 6 | body { color: red; } 7 | -------------------------------------------------------------------------------- /spec/jekyll_bootstrap_sass_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Jekyll::Bootstrap do 4 | let(:config) { {} } 5 | before(:each) do 6 | init_source_and_dest 7 | add_fixture_to_source 'style.scss' 8 | site(config).process 9 | end 10 | 11 | let(:stylesheet) { dest_dir('style.css') } 12 | let(:output) { File.open(stylesheet).read } 13 | 14 | it 'has a version number' do 15 | puts Bootstrap::VERSION 16 | expect(Jekyll::BootstrapSass::VERSION).not_to be nil 17 | end 18 | 19 | it 'outputs the stylesheet' do 20 | expect(File.exist?(stylesheet)).to eql(true) 21 | end 22 | 23 | # Confirm bootstrap made it into SaSS's load path 24 | it 'renders bootstrap' do 25 | regex = /Bootstrap v#{Regexp.escape(Bootstrap::VERSION)}/ 26 | expect(output).to match(regex) 27 | end 28 | 29 | context 'rendering assets' do 30 | context 'with no config' do 31 | it "doesn't render assets" do 32 | expect(assets_rendered?).to_not eql(true) 33 | end 34 | end 35 | 36 | context 'with a config' do 37 | context 'with assets enabled' do 38 | let(:config) { { 'bootstrap' => { 'assets' => true } } } 39 | 40 | it 'renders assets' do 41 | expect(assets_rendered?).to eql(true) 42 | end 43 | end 44 | 45 | context 'with assets disabled' do 46 | let(:config) { { 'bootstrap' => { 'assets' => false } } } 47 | 48 | it "doesn't render assets" do 49 | expect(assets_rendered?).to_not eql(true) 50 | end 51 | end 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | 3 | require 'jekyll' 4 | require 'fileutils' 5 | require 'jekyll-bootstrap-sass' 6 | require 'bootstrap/bootstrap' 7 | 8 | TEST_DIR = File.dirname(__FILE__) 9 | TMP_DIR = File.expand_path('../tmp', TEST_DIR) 10 | 11 | def tmp_dir(*files) 12 | File.join(TMP_DIR, *files) 13 | end 14 | 15 | def source_dir(*files) 16 | tmp_dir('source', *files) 17 | end 18 | 19 | def dest_dir(*files) 20 | tmp_dir('dest', *files) 21 | end 22 | 23 | def fixtures_dir 24 | File.expand_path './fixtures', TEST_DIR 25 | end 26 | 27 | def fixture_path(fixture) 28 | File.expand_path fixture, fixtures_dir 29 | end 30 | 31 | def add_fixture_to_source(fixture) 32 | FileUtils.cp fixture_path(fixture), source_dir(fixture) 33 | end 34 | 35 | def init_source_and_dest 36 | FileUtils.mkdir_p source_dir 37 | FileUtils.rm_rf dest_dir 38 | end 39 | 40 | def site(opts = {}) 41 | defaults = Jekyll::Configuration::DEFAULTS 42 | opts = opts.merge( 43 | 'source' => source_dir, 44 | 'destination' => dest_dir, 45 | 'gems' => ['jekyll-bootstrap-sass'] 46 | ) 47 | conf = Jekyll::Utils.deep_merge_hashes(defaults, opts) 48 | Jekyll::Site.new(conf) 49 | end 50 | 51 | def assets_rendered? 52 | js = dest_dir('assets/javascripts/bootstrap.js') 53 | font = dest_dir('assets/fonts/bootstrap/glyphicons-halflings-regular.ttf') 54 | File.exist?(js) && File.exist?(font) 55 | end 56 | --------------------------------------------------------------------------------