module Gotta::Run::Ruby::Loader::Component
Public Class Methods
load_handler()
click to toggle source
# File lib/gotta/run/ruby/loader/component.rb, line 32 def self.load_handler module_eval("require 'handler'") end
require(req)
click to toggle source
Calls superclass method
# File lib/gotta/run/ruby/loader/component.rb, line 23 def self.require(req) file = "#{req}.rb" if File.file?(file) module_eval(File.read(file), file) else super(req) end end
Public Instance Methods
redirect_to(location = nil, function: nil, url: nil, status: 303)
click to toggle source
# File lib/gotta/run/ruby/loader/component.rb, line 40 def redirect_to(location = nil, function: nil, url: nil, status: 303) headers = { 'Location' => location || function || url } Runtime::Response.new(body: nil, status: status, headers: headers) end
render(js: nil, body: nil, inline: nil, html: nil, json: nil, yaml: nil, text: nil, data: nil, png: nil, jpeg: nil, gif: nil, icon: nil, svg: nil, css: nil, status: 200, headers: {}, content_type: nil)
click to toggle source
# File lib/gotta/run/ruby/loader/component.rb, line 45 def render(js: nil, body: nil, inline: nil, html: nil, json: nil, yaml: nil, text: nil, data: nil, png: nil, jpeg: nil, gif: nil, icon: nil, svg: nil, css: nil, status: 200, headers: {}, content_type: nil) headers['Content-Type'] = content_type if content_type content_type, resp_body = case when json ['application/json', json.is_a?(String) ? json : Oj.dump(json)] when text ['text/plain', text] when yaml ['text/yaml', yaml.is_a?(String) ? yaml : yaml.to_yaml] when html, inline ['text/html', html || inline] when body ['application/octet-stream', Base64.urlsafe_encode64(body, padding: false)] when data ['application/octet-stream', Base64.urlsafe_encode64(data, padding: false)] when js ['text/javascript', js] when png ['image/png', Base64.urlsafe_encode64(File.binread(png), padding: false)] when svg ['image/svg+xml', svg] when jpeg ['image/jpeg', Base64.urlsafe_encode64(File.binread(jpeg), padding: false)] when gif ['image/gif', Base64.urlsafe_encode64(File.binread(gif), padding: false)] when icon ['image/x-icon', Base64.urlsafe_encode64(File.binread(icon), padding: false)] when css ['text/css', css] else headers.delete('Content-Type') return Runtime::Response.new(nil, status, headers) end headers['Content-Type'] ||= content_type Runtime::Response.new(resp_body, status, headers) end
render_nothing(status: 200, headers: {})
click to toggle source
# File lib/gotta/run/ruby/loader/component.rb, line 113 def render_nothing(status: 200, headers: {}) Runtime::Response.new(nil, status, headers) end
render_template(template_path, status: 200, headers: {}, variables: {})
click to toggle source
# File lib/gotta/run/ruby/loader/component.rb, line 117 def render_template(template_path, status: 200, headers: {}, variables: {}) headers['Content-Type'] ||= 'text/html' template = Runtime::Template.new(variables: variables).render(template_path) Runtime::Response.new(template, status, headers) end
respond_with(body, status: 200, headers: {})
click to toggle source
# File lib/gotta/run/ruby/loader/component.rb, line 36 def respond_with(body, status: 200, headers: {}) Runtime::Response.new(body: body, status: status, headers: headers) end