Module: ContentHelper

Defined in:
lib/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_components(name) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/content_helper.rb', line 2

def render_components(name)
  querystring = "" # TODO

  env = {
    "rack.version" => [0, 1],
    "rack.input" => StringIO.new(""),
    "rack.errors" => $stderr,
    "rack.url_scheme" => "http",
    "rack.run_once" => false,
    "rack.multithread" => false,
    "rack.multiprocess" => false,
    "QUERY_STRING" => querystring,
    "REQUEST_METHOD" => "GET",
    "PATH_INFO" => name,
    "REQUEST_PATH" => name,
    "REQUEST_URI" => name
  }
  
  %w(SERVER_SOFTWARE HTTP_USER_AGENT HTTP_ACCEPT_ENCODING HTTP_ACCEPT_CHARSET
    HTTP_ACCEPT_LANGUAGE HTTP_KEEP_ALIVE HTTP_COOKIE HTTP_VERSION SERVER_PROTOCOL HTTP_HOST
    SERVER_NAME SERVER_PORT REMOTE_ADDR SCRIPT_NAME).each { |key| env[key] = request.env[key] }

  resp = ActionController::Dispatcher.new.call(env)
  raise "Error executing component '#{name}' - #{resp[0]}" unless resp[0] == 200
  resp[2].body
end