UNPKG

1.57 kBPlain TextView Raw
1require 'bootstrap-sass/version'
2module Bootstrap
3 class << self
4 # Inspired by Kaminari
5 def load!
6 register_compass_extension if compass?
7 register_rails_engine if rails?
8 configure_sass
9 end
10
11 # Paths
12 def gem_path
13 @gem_path ||= File.expand_path '..', File.dirname(__FILE__)
14 end
15
16 def stylesheets_path
17 File.join assets_path, 'stylesheets'
18 end
19
20 def fonts_path
21 File.join assets_path, 'fonts'
22 end
23
24 def javascripts_path
25 File.join assets_path, 'javascripts'
26 end
27
28 def assets_path
29 @assets_path ||= File.join gem_path, 'assets'
30 end
31
32 # Environment detection helpers
33 def asset_pipeline?
34 defined?(::Sprockets)
35 end
36
37 def compass?
38 defined?(::Compass)
39 end
40
41 def rails?
42 defined?(::Rails)
43 end
44
45 private
46
47 def configure_sass
48 require 'sass'
49
50 ::Sass.load_paths << stylesheets_path
51
52 # bootstrap requires minimum precision of 10, see https://github.com/twbs/bootstrap-sass/issues/409
53 ::Sass::Script::Number.precision = [10, ::Sass::Script::Number.precision].max
54 end
55
56 def register_compass_extension
57 ::Compass::Frameworks.register(
58 'bootstrap',
59 :version => Bootstrap::VERSION,
60 :path => gem_path,
61 :stylesheets_directory => stylesheets_path,
62 :templates_directory => File.join(gem_path, 'templates')
63 )
64 end
65
66 def register_rails_engine
67 require 'bootstrap-sass/engine'
68 end
69 end
70end
71
72Bootstrap.load!