2011-09-06 20:08:31 +01:00
|
|
|
module Bootstrap
|
2012-02-06 13:38:26 +00:00
|
|
|
class FrameworkNotFound < StandardError; end
|
2011-12-22 22:25:20 -05:00
|
|
|
|
2012-02-06 13:38:26 +00:00
|
|
|
# Inspired by Kaminari
|
|
|
|
def self.load!
|
2013-03-21 11:26:25 -04:00
|
|
|
if compass?
|
2012-05-11 14:39:47 +01:00
|
|
|
require 'bootstrap-sass/compass_functions'
|
2012-05-06 19:11:47 +01:00
|
|
|
register_compass_extension
|
2012-05-06 19:04:49 +01:00
|
|
|
elsif asset_pipeline?
|
2013-03-21 11:26:25 -04:00
|
|
|
require 'bootstrap-sass/sass_functions'
|
|
|
|
end
|
|
|
|
|
|
|
|
if rails?
|
|
|
|
require 'sass-rails'
|
2012-05-11 14:39:47 +01:00
|
|
|
register_rails_engine
|
2013-03-21 11:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if !(rails? || compass?)
|
2012-05-02 14:29:01 +01:00
|
|
|
raise Bootstrap::FrameworkNotFound, "bootstrap-sass requires either Rails > 3.1 or Compass, neither of which are loaded"
|
2011-09-06 20:08:31 +01:00
|
|
|
end
|
2013-03-21 11:26:25 -04:00
|
|
|
|
2012-11-19 14:26:32 -05:00
|
|
|
stylesheets = File.expand_path(File.join("..", 'vendor', 'assets', 'stylesheets'))
|
2013-02-15 19:42:23 -05:00
|
|
|
::Sass.load_paths << stylesheets
|
2011-09-06 20:08:31 +01:00
|
|
|
end
|
2012-02-06 13:38:26 +00:00
|
|
|
|
|
|
|
private
|
2012-04-08 20:00:11 +01:00
|
|
|
def self.asset_pipeline?
|
2013-01-29 12:07:41 +04:00
|
|
|
defined?(::Sprockets)
|
2012-02-06 13:38:26 +00:00
|
|
|
end
|
|
|
|
|
2012-05-11 14:39:47 +01:00
|
|
|
def self.compass?
|
|
|
|
defined?(::Compass)
|
|
|
|
end
|
|
|
|
|
2013-03-21 11:26:25 -04:00
|
|
|
def self.rails?
|
|
|
|
defined?(::Rails)
|
|
|
|
end
|
|
|
|
|
2012-05-06 19:11:47 +01:00
|
|
|
def self.register_compass_extension
|
|
|
|
base = File.join(File.dirname(__FILE__), '..')
|
|
|
|
styles = File.join(base, 'vendor', 'assets', 'stylesheets')
|
|
|
|
templates = File.join(base, 'templates')
|
2013-02-19 02:26:45 +08:00
|
|
|
::Compass::Frameworks.register('bootstrap', :path => base, :stylesheets_directory => styles, :templates_directory => templates)
|
2012-05-06 19:11:47 +01:00
|
|
|
end
|
|
|
|
|
2012-05-11 14:39:47 +01:00
|
|
|
def self.register_rails_engine
|
|
|
|
require 'bootstrap-sass/engine'
|
2012-02-06 13:38:26 +00:00
|
|
|
end
|
2011-09-06 20:08:31 +01:00
|
|
|
end
|
|
|
|
|
2012-02-06 13:38:26 +00:00
|
|
|
Bootstrap.load!
|