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!
|
2012-05-06 19:11:47 +01:00
|
|
|
if compass? && asset_pipeline?
|
|
|
|
register_compass_extension
|
2012-05-11 14:39:47 +01:00
|
|
|
register_rails_engine
|
2012-05-06 19:11:47 +01:00
|
|
|
elsif compass?
|
|
|
|
# Only require compass extension if a standalone project
|
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?
|
|
|
|
require 'sass-rails' # See: https://github.com/thomas-mcdonald/bootstrap-sass/pull/4
|
2012-05-11 14:39:47 +01:00
|
|
|
register_rails_engine
|
|
|
|
require 'bootstrap-sass/rails_functions'
|
2012-02-06 13:38:26 +00:00
|
|
|
else
|
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
|
|
|
|
end
|
2012-02-06 13:38:26 +00:00
|
|
|
|
|
|
|
private
|
2012-04-08 20:00:11 +01:00
|
|
|
def self.asset_pipeline?
|
2012-04-04 17:54:49 +08:00
|
|
|
defined?(::Rails) && ::Rails.version >= '3.1.0'
|
2012-02-06 13:38:26 +00:00
|
|
|
end
|
|
|
|
|
2012-05-11 14:39:47 +01:00
|
|
|
def self.compass?
|
|
|
|
defined?(::Compass)
|
|
|
|
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')
|
|
|
|
::Compass::Frameworks.register('bootstrap', :stylesheets_directory => styles, :templates_directory => templates)
|
|
|
|
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!
|