fix brandable_css so it works when rails is not loaded

this will fix our gulp guard


test plan:
check out code
run `bundle exec guard`
hit enter
it should not throw an error

Change-Id: I01e5c82783039e542dfdb6f76f70a5a3232ee793
Reviewed-on: https://gerrit.instructure.com/57897
Tested-by: Jenkins
Reviewed-by: Chris Hart <chart@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Ryan Shaw 2015-07-07 16:08:27 -06:00
parent 00f8b93534
commit 99f5d21cbb
1 changed files with 13 additions and 9 deletions

View File

@ -1,9 +1,11 @@
module BrandableCSS
require 'rails'
CONFIG = YAML.load_file(Rails.root.join('config/brandable_css.yml')).freeze
BRANDABLE_VARIABLES = JSON.parse(File.read(Rails.root.join(CONFIG['paths']['brandable_variables_json']))).freeze
SASS_STYLE = ENV['SASS_STYLE'] || (Rails.env.production? ? 'compressed' : 'nested')
require 'pathname'
require 'yaml'
module BrandableCSS
APP_ROOT = defined?(Rails) && Rails.root || Pathname.pwd
CONFIG = YAML.load_file(APP_ROOT.join('config/brandable_css.yml')).freeze
BRANDABLE_VARIABLES = JSON.parse(File.read(APP_ROOT.join(CONFIG['paths']['brandable_variables_json']))).freeze
SASS_STYLE = (ENV['SASS_STYLE'] || ((defined?(Rails) && Rails.env.production?) ? 'compressed' : 'nested')).freeze
class << self
def variables_map
@ -35,13 +37,15 @@ module BrandableCSS
end
def combined_checksums
return @combined_checksums if ActionController::Base.perform_caching && defined? @combined_checksums
file = Rails.root.join(CONFIG['paths']['bundles_with_deps'] + SASS_STYLE)
if defined?(ActionController) && ActionController::Base.perform_caching && defined?(@combined_checksums)
return @combined_checksums
end
file = APP_ROOT.join(CONFIG['paths']['bundles_with_deps'] + SASS_STYLE)
if file.exist?
@combined_checksums = JSON.parse(file.read).each_with_object({}) do |(k, v), memo|
memo[k] = v['combinedChecksum']
end.freeze
elsif Rails.env.production?
elsif defined?(Rails) && Rails.env.production?
raise "you need to run #{cli} before you can serve css."
else
# for dev/test there might be cases where you don't want it to raise an exception
@ -88,7 +92,7 @@ module BrandableCSS
command = [cli].push(*args).shelljoin + ' 2>&1'
msg = "running BrandableCSS CLI: #{command}"
Rails.logger.try(:debug, msg)
Rails.logger.try(:debug, msg) if defined?(Rails)
raise "Error: #{msg}" unless system(command)
end
end