Contents
Methods
Constants
RADIUS = 3
Attributes
[RW] action_name The name of the currently executing action.
[RW] context The context.
[RW] controller The current controller class.
[RW] out The output buffer. The output of a script/action is accumulated in this buffer.
Public Class methods
new(context)

Initialize the render.

context
A parent render/controller acts as the context.
    # File lib/raw/controller/render.rb, line 53
53:   def initialize(context)
54:     @context = context
55:     @out = context.output_buffer
56:   end
Public Instance methods
build() {|XmlBuilder.new(@out)| ...}

Access the programmatic renderer (builder).

    # File lib/raw/view/builder.rb, line 9
 9:   def build(&block)
10:     if block.arity == 1
11:       yield XmlBuilder.new(@out)
12:     else
13:       XmlBuilder.new(@out).instance_eval(&block)
14:     end
15:   end
builder()

Return a programmatic renderer that targets the output buffer.

    # File lib/raw/view/builder.rb, line 20
20:   def builder
21:     XmlBuilder.new(@out)
22:   end
Public Instance methods
answer(force = false, status = 303)

Returns from a call by poping the callstack. Use force = false to make this mechanism more flexible.

    # File lib/raw/controller/call.rb, line 29
29:   def answer(force = false, status = 303)
30:     if stack = session[:CALL_STACK] and not stack.empty?
31:       redirect(stack.pop, :status => status)
32:     else
33:       if force
34:         raise "Cannot answer, call stack is empty"
35:       else
36:         redirect_to_home
37:       end
38:     end
39:   end
call(*args)

Call redirects to the given URI but push the original URI in a callstack, so that the target can return by executing answer.

    # File lib/raw/controller/call.rb, line 18
18:   def call(*args)
19:     (session[:CALL_STACK] ||= []).push(request.uri)
20:     redirect(*args)
21:   end
send_file(fname = nil, fullpath = false)

Send a file download to the client.

Like render and redirect, the action is exited upon calling

fname
That name of the file
path
Specifying true mean fname contains the full path.
    The default, false, uses Server.public_root as the path.
return
true on success, false on failure

Examples

require "raw/render/send_file"

class MyController < Nitro:Controller

  def download(fname)
    send_file(fname)
  end

end

class MyController < Nitro:Controller

  def download
    send_file("/etc/password", true)
  end

end

This method is also aliased as sendfile
    # File lib/raw/controller/send_file.rb, line 33
33:   def send_file(fname = nil, fullpath = false)
34:     fname = fullpath ? fname : "#{@context.application.public_dir}/#{fname}"
35:     f = File.open(fname, "rb")
36:     @context.response_headers["Cache-control"] = "private"
37:     @context.response_headers["Content-Length"] = "#{File.size?(f) || 0}"
38:     @context.response_headers["Content-Type"] = "application/force-download"
39:     @context.output_buffer = f
40:     raise RenderExit
41:   end
sendfile(fname = nil, fullpath = false)

Alias for #send_file

stream(io = nil) {|| ...}

Enable streaming mode for the current HTTP Response. You can optionally provide an existing IO object for streaming.

    # File lib/raw/controller/stream.rb, line 15
15:   def stream(io = nil)
16:     if io
17:       # Reuse an existing IO if it exists.
18:       @context.output_buffer = io
19:     else  
20:       r, w = IO.pipe
21:       
22:       @context.output_buffer = r
23:       @out = w
24:       r.sync = true    
25:       w.class.send(:define_method, :empty?) { false }
26:   
27:       Thread.new do 
28:         begin
29:           yield
30:         ensure
31:           w.close
32:         end
33:       end
34:     end
35:   end