asset pipeline - Sprockets/Rails: Find all files Sprockets knows how to compile -
for konacha, rails engine testing rails apps, need way find files sprockets can compile javascript.
right use like
dir['spec/javascripts/**/*_spec.*']
but picks .bak
, .orig
, , other backup files.
can sprockets tell somehow whether knows how compile file, backup files automatically excluded?
content_type_of
doesn't help:
rails.application.assets.content_type_of('test/javascripts/foo.js.bak') => "application/javascript"
you can iterate through files in sprockets::environment
's load path using each_file
method:
rails.application.assets.each_file { |pathname| ... }
the block invoked pathname
instance expanded path of each file in load path.
each_file
returns enumerator
, can skip block , array to_a
, or call include?
on it. example, check whether file in load path:
assets = rails.application.assets pathname1 = pathname.new("test/javascripts/foo.js").expand_path pathname2 = pathname.new("test/javascripts/foo.js.bak").expand_path assets.each_file.include?(pathname1) # => true assets.each_file.include?(pathname2) # => false
Comments
Post a Comment