Module: Roda::RodaPlugins::Sprockets::RequestMethods

Defined in:
lib/roda/plugins/sprockets.rb

Instance Method Summary collapse

Instance Method Details

#sprocketsObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# 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