Skip to content

Commit

Permalink
TheRuck supported *path routing.
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed May 25, 2008
1 parent 293ff3d commit 2325fed
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
4 changes: 3 additions & 1 deletion gitalone.rb
Expand Up @@ -104,8 +104,10 @@ def gravatar(email, size=30)
body params.inspect
end

bind "repo/:name/tree/:head" do
bind "repo/:name/tree/:head/*path" do
repo = Grit::Repo.new(@opts.dir + params["name"] + ".git")
p params
stash[:path] = params["path"]
stash[:name] = params["name"]
stash[:head] = params["head"]
stash[:repo] = repo
Expand Down
24 changes: 22 additions & 2 deletions templates/tree.html
@@ -1,4 +1,4 @@
<% title = "#{name} / #{head} - GitAlone" %>
<% title = "#{name} - #{path} / #{head} - GitAlone" %>
<% layout %>

<dl class="repos-info">
Expand All @@ -14,7 +14,7 @@
<dd><%= repo.tags.empty?? "not tagged now" : repo.tags.map {|h| h.name } %></dd>
</dl>

<% repo.commits(head).each do |commit| info = commit.to_hash %>
<% repo.commits(head, 5).each do |commit| info = commit.to_hash %>
<div class="commit">
<div class="commit-info">
<dl>
Expand All @@ -41,3 +41,23 @@
-->
</div>
<% end %>


<table>
<thead>
<tr>
<th>name</th>
<th>age</th>
<th>message</th>
<th>author</th>
</tr>
</thead>
<tbody>
<% repo.tree(head).contents.each do |blob| %>
<tr>
<td><a href="/repo/<%= name %>/tree/<%= head %>/<%= blob.name %>"><%= blob.name %></a></td>
</tr>
<% end %>
</tbody>
</table>

16 changes: 10 additions & 6 deletions theruck.rb
Expand Up @@ -50,9 +50,13 @@ def route(str)
names = []
paths = str.to_s.split("/", -1)
regex = paths.empty?? %r|^/$| : Regexp.new(paths.inject("^") {|r,i|
if i[0] == ?:
case i[0]
when ?:
names << i.sub(":", "")
r << "/([^/]+)"
when ?*
names << i.sub("*", "")
r << "(?:/(.*))?"
else
r << "/#{i}"
end
Expand Down Expand Up @@ -148,12 +152,12 @@ def initialize(opts={})
extend @opts[:helper] if @opts[:helper]
end

def render(path, stash)
@@templates[path] ||= ::Erubis::EscapedEruby.new(File.read("#{@opts[:dir]}/#{path}.html"))
def render(_path, _stash)
@@templates[_path] ||= ::Erubis::EscapedEruby.new(File.read("#{@opts[:dir]}/#{_path}.html"))
head "Content-Type", "text/html"
b = binding
stash.each {|k,v| eval "#{k} = stash[:#{k}]", b }
body @layout.inject(@@templates[path].result(binding)) {|content,layout|
_binding = binding
_stash.each {|k,v| eval "#{k} = _stash[:#{k}]", _binding }
body @layout.inject(@@templates[_path].result(binding)) {|content,layout|
@@templates[layout].result(binding)
}
self
Expand Down

0 comments on commit 2325fed

Please sign in to comment.