Class: ActionFramework::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/actionframework/controller.rb

Direct Known Subclasses

ErrorHandler

Constant Summary collapse

@@run_before =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, req, res, url) ⇒ Controller

Returns a new instance of Controller.



10
11
12
13
14
15
# File 'lib/actionframework/controller.rb', line 10

def initialize env,req,res,url
	@req = req
	@res = res
	@url = url
	@env = env
end

Class Method Details

.run_before(*args) ⇒ Object



71
72
73
74
75
# File 'lib/actionframework/controller.rb', line 71

def self.run_before(*args)
	args.each do |methodname|
			@@run_before << methodname
	end
end

Instance Method Details

#envObject



17
18
19
# File 'lib/actionframework/controller.rb', line 17

def env
	@env
end

#erb(template) ⇒ Object



37
38
39
40
41
# File 'lib/actionframework/controller.rb', line 37

def erb template
    		renderer = Tilt::ERBTemplate.new("views/layout.html.erb")
    		output = renderer.render(self){ Tilt::ERBTemplate.new("views/"+template.to_s+".html.erb").render(self) }
    		return output
end

#erb_text(erb_text) ⇒ Object



43
44
45
46
47
# File 'lib/actionframework/controller.rb', line 43

def erb_text erb_text
	renderer = Tilt::ERBTemplate.new("views/layout.html.erb")
    		output = renderer.render(self){ erb_text }
    		return output
end

#error_erb(code) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/actionframework/controller.rb', line 49

def error_erb code
	if(Dir.exists? "views/errors")
		renderer = Tilt::ERBTemplate.new("views/layout.html.erb")
     		output = renderer.render(self){ Tilt::ERBTemplate.new("views/errors/#{code}.html.erb").render(self) }
     		return output
    		else
    			root = ActionFramework::Gem.root
    			libdir = root.resources.to_s
    			renderer = Tilt::ERBTemplate.new(libdir+"/views/errors/layout.html.erb")
     		output = renderer.render(self){ Tilt::ERBTemplate.new(libdir+"/views/errors/#{code}.html.erb").render(self) }
    		end
end

#execute_run_beforeObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/actionframework/controller.rb', line 77

def execute_run_before
	output = nil
	@@run_before.each do |methodname|
		returns = self.send(methodname)

		if(returns.class.to_s == "String")
			output = returns
			break
		end
		
	end

	return output
end

#paramsObject



29
30
31
# File 'lib/actionframework/controller.rb', line 29

def params
	@req.params
end

#redirect(path) ⇒ Object



66
67
68
69
# File 'lib/actionframework/controller.rb', line 66

def redirect path
	response.redirect path
	""
end

#requestObject



21
22
23
# File 'lib/actionframework/controller.rb', line 21

def request
	@req
end

#responseObject



25
26
27
# File 'lib/actionframework/controller.rb', line 25

def response
	@res
end

#sessionObject



62
63
64
# File 'lib/actionframework/controller.rb', line 62

def session
	@req.session
end

#urlObject



33
34
35
# File 'lib/actionframework/controller.rb', line 33

def url
	@url
end