Skip to content

Instantly share code, notes, and snippets.

@demimismo
Forked from snikch/gist:2582549
Created October 31, 2012 14:20
Show Gist options
  • Save demimismo/3987282 to your computer and use it in GitHub Desktop.
Save demimismo/3987282 to your computer and use it in GitHub Desktop.
Prevent AssetNotPrecompiledError before it occurs.
##
# Checks that the precompile list contains this file or raises an error, in dev only
# Note: You will need to move config.assets.precompile to application.rb from production.rb
def javascript_include_tag *sources
raise_on_asset_absence sources
super *sources
end
def stylesheet_link_tag *sources
raise_on_asset_absence sources
super *sources
end
def raise_on_asset_absence *sources
sources.each do |source|
CartoDB::Logger.info "SOURCE #{source}"
next if source == {:media => "all"}
raise "Hey, #{source} is not in the precompile list. This will fall apart in production." unless Rails.application.config.assets.precompile.any? do |matcher|
if matcher.is_a? Proc
matcher.call(source)
elsif matcher.is_a? Regexp
matcher.match(source)
else
rx = /(\.css)|(\.js)/
[source].flatten.each do |s|
matcher.to_s.gsub(rx,'') == s.to_s.gsub(rx,'')
end
end
end
end if Rails.env.development?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment