-
-
Save demimismo/3987282 to your computer and use it in GitHub Desktop.
Prevent AssetNotPrecompiledError before it occurs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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