module Roda::RodaPlugins::Sprockets::RequestMethods

Public Instance Methods

sprockets() click to toggle source
# File lib/roda/plugins/sprockets.rb, line 127
def sprockets
  get self.roda_class.sprockets_regexp do |path|
    options                    = scope.sprockets_options
    env_sprockets              = scope.request.env.dup
    env_sprockets['PATH_INFO'] = path

    status, headers, response = options[:sprockets].call env_sprockets

    scope.response.status = status
    scope.response.headers.merge! headers

    case response
    when nil, []
      # Empty response happens for example when 304 Not Modified happens.
      # We want to return nil in this case.
      # (See: https://github.com/hmdne/roda-sprockets/issues/1)
      nil
    when Array
      response.join
    else
      response.to_s
    end
  end
end