forked from twbs/bootstrap-rubygem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.rb
75 lines (60 loc) · 1.57 KB
/
bootstrap.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true
require 'bootstrap/version'
require 'popper_js'
module Bootstrap
class << self
# Inspired by Kaminari
def load!
if rails?
register_rails_engine
elsif hanami?
register_hanami
elsif sprockets?
register_sprockets
elsif defined?(::Sass) && ::Sass.respond_to?(:load_paths)
# The deprecated `sass` gem:
::Sass.load_paths << stylesheets_path
end
if defined?(::Sass::Script::Value::Number)
# Set precision to 6 as per:
# https://github.com/twbs/bootstrap/blob/da717b03e6e72d7a61c007acb9223b9626ae5ee5/package.json#L28
::Sass::Script::Value::Number.precision = [6, ::Sass::Script::Value::Number.precision].max
end
end
# Paths
def gem_path
@gem_path ||= File.expand_path '..', File.dirname(__FILE__)
end
def stylesheets_path
File.join assets_path, 'stylesheets'
end
def javascripts_path
File.join assets_path, 'javascripts'
end
def assets_path
@assets_path ||= File.join gem_path, 'assets'
end
# Environment detection helpers
def sprockets?
defined?(::Sprockets)
end
def rails?
defined?(::Rails)
end
def hanami?
defined?(::Hanami)
end
private
def register_rails_engine
require 'bootstrap/engine'
end
def register_sprockets
Sprockets.append_path(stylesheets_path)
Sprockets.append_path(javascripts_path)
end
def register_hanami
Hanami::Assets.sources << assets_path
end
end
end
Bootstrap.load!