Class: Gitgo::Controller
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Gitgo::Controller
show all
- Defined in:
- lib/gitgo/controller.rb
Constant Summary
collapse
- ROOT =
File.expand_path(File.dirname(__FILE__) + "/../..")
- HEAD =
'gitgo.head'
- MOUNT =
'gitgo.mount'
Instance Method Summary
collapse
Constructor Details
#initialize(app = nil, repo = nil) ⇒ Controller
Returns a new instance of Controller.
32
33
34
35
|
# File 'lib/gitgo/controller.rb', line 32
def initialize(app=nil, repo=nil)
super(app)
@repo = repo
end
|
Instance Method Details
#call(env) ⇒ Object
48
49
50
51
|
# File 'lib/gitgo/controller.rb', line 48
def call(env)
env[Repo::REPO] ||= @repo
Repo.with_env(env) { super(env) }
end
|
81
82
83
|
# File 'lib/gitgo/controller.rb', line 81
def form
@form ||= Helper::Form.new(self)
end
|
77
78
79
|
# File 'lib/gitgo/controller.rb', line 77
def format
@format ||= Helper::Format.new(self)
end
|
#html ⇒ Object
85
86
87
|
# File 'lib/gitgo/controller.rb', line 85
def html
Helper::Html
end
|
#mount_point ⇒ Object
69
70
71
|
# File 'lib/gitgo/controller.rb', line 69
def mount_point
@mount_point ||= (env[MOUNT] || '/')
end
|
#path(path) ⇒ Object
Returns the path expanded relative to the Gitgo::ROOT directory. Paths often need to be expanded like this so that they will be correct when Gitgo is running as a gem.
40
41
42
|
# File 'lib/gitgo/controller.rb', line 40
def path(path)
File.expand_path(path, ROOT)
end
|
#repo ⇒ Object
44
45
46
|
# File 'lib/gitgo/controller.rb', line 44
def repo
@repo ||= Repo.current
end
|
#session_head ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/gitgo/controller.rb', line 53
def session_head
@session_head ||= begin
if session.has_key?(HEAD)
session[HEAD]
else
grit = repo.git.grit
session[HEAD] = grit.head ? grit.head.name : nil
end
end
end
|
#session_head=(input) ⇒ Object
65
66
67
|
# File 'lib/gitgo/controller.rb', line 65
def session_head=(input)
@session_head = session[HEAD] = input
end
|
#url(paths) ⇒ Object
73
74
75
|
# File 'lib/gitgo/controller.rb', line 73
def url(paths)
File.join(mount_point, *paths)
end
|