Class: Riddl::Utils::ERBServe

Inherits:
Implementation show all
Defined in:
lib/ruby/riddl/utils/erbserve.rb

Instance Method Summary collapse

Methods inherited from Implementation

#headers, #initialize, #status

Constructor Details

This class inherits a constructor from Riddl::Implementation

Instance Method Details

#responseObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby/riddl/utils/erbserve.rb', line 7

def response
  path = File.file?(@a[0]) ? @a[0] : "#{@a[0]}/#{@r[@match.length..-1].join('/')}".gsub(/\/+/,'/')
  input = @a[1]
  if File.directory?(path)
    @status = 404
    return []
  end
  if File.exists?(path)
    __ERB_FILE__ = path
    rval = ERB.new(File.read(path), 0, "%<>")
    return Riddl::Parameter::Complex.new("data",MIME::Types.type_for(path)[0].to_s,rval.result(binding))
  end
  @status = 404
  []
end