Class: Motor::AssetsController

Inherits:
ActionController::Metal
  • Object
show all
Defined in:
app/controllers/motor/assets_controller.rb

Constant Summary collapse

CACHE_STORE =
ActiveSupport::Cache::MemoryStore.new
GZIP_TYPES =
[
  'application/javascript',
  'text/css',
  'image/svg+xml'
].freeze
MIME_TYPES =
{
  '.js' => 'application/javascript',
  '.css' => 'text/css',
  '.svg' => 'image/svg+xml',
  '.woff2' => 'font/woff2'
}.freeze

Instance Method Summary collapse

Instance Method Details

#showObject


20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/motor/assets_controller.rb', line 20

def show
  filename = params[:filename]

  return [404, {}, ''] unless Motor::Assets.manifest.value?(filename)

  assign_headers(filename)

  self.response_body = CACHE_STORE.fetch(filename) do
    Motor::Assets.load_asset(filename, gzip: headers['Content-Encoding'] == 'gzip')
  end
end