Showing 4 changed files with 435 additions and 427 deletions
+1 -1
lib/Gitprep.pm
... ...
@@ -310,7 +310,7 @@ sub startup {
310 310
             });
311 311
             
312 312
             # Home
313
-            $r->get('/' => template '/project');
313
+            $r->get('/' => template '/tree');
314 314
             
315 315
             # Commit
316 316
             $r->get('/commit/*diff' => template '/commit');
+188 -188
templates/include/branch_select.html.ep
... ...
@@ -1,189 +1,189 @@
1
-<%
2
-  my $api = gitprep_api;
3
-  
4
-  my $display = stash('display') || '';
5
-  my $rev = stash('rev');
6
-  $rev = '' unless defined $rev;
7
-  my $branches = stash('branches');
8
-  my $project_page = stash('project_page');
9
-
10
-  my $logined = $api->logined;
11
-%>
12
-
13
-%= javascript begin
14
-  $(document).ready(function () {
15
-  
16
-    % if ($display eq 'files' || $display eq 'commits') {
17
-      % my $type = $display eq 'files' ? 'tree' : 'commits';
18
-      
19
-      // Switch branches and tags
20
-      var revs_init = false;
21
-      $('#rev-btn').on('click', function () {
22
-        
23
-        if (!revs_init) {
24
-          $.get('<%= url_for("/$user/$project/api/revs") %>', function (result) {
25
-            var branch_names = result.branch_names;
26
-            var tag_names = result.tag_names;
27
-            var style = 'style="border-top-left-radius:0px;border-top-right-radius:0px;"';
28
-            
29
-            if (branch_names.length === 0) {
30
-              $('#branch-names-list').append(
31
-                '<li><a ' + style + ' href="#">No branches</a></li>'
32
-              );
33
-            }
34
-            else {
35
-              for (var i = 0; i < branch_names.length; i++) {
36
-                var branch_name = branch_names[i];
37
-                $('#branch-names-list').append(
38
-                  '<li><a ' + style + ' href="<%= url_for("/$user/$project/$type/") %>' + branch_name + '">' + branch_name + '</a></li>'
39
-                );
40
-              }
41
-            }
42
-            
43
-            if (tag_names.length === 0) {
44
-              $('#tag-names-list').append(
45
-                '<li><a ' + style + ' href="#">No tags</a></li>'
46
-              );
47
-            }
48
-            else {
49
-              for (var i = 0; i < tag_names.length; i++) {
50
-                var tag_name = tag_names[i];
51
-                $('#tag-names-list').append(
52
-                  '<li><a ' + style + ' href="<%= url_for("/$user/$project/$type/") %>' + tag_name + '">' + tag_name + '</a></li>'
53
-                );
54
-              }
55
-            }
56
-            $('#rev-popup')
57
-              .css('display', 'block')
58
-              .css('top', '5px')
59
-              .css('left', '0px')
60
-            ;
61
-          });
62
-          revs_init = true;
63
-        }
64
-        else {
65
-          $('#rev-popup')
66
-            .css('display', 'block')
67
-            .css('top', '5px')
68
-            .css('left', '0px')
69
-          ;
70
-        }
71
-      });
72
-
73
-      $('#revs-tab a').click(function (e) {
74
-        e.preventDefault();
75
-        $(this).tab('show');
76
-      })
77
-      
78
-      $('#rev-close').on('click', function () {
79
-        $('#rev-popup').css('display', 'none');
80
-      });
81
-    % } elsif ($display eq 'branches') {
82
-      $('#rev-btn').on('click', function () {
83
-        $('#rev-popup')
84
-          .css('display', 'block')
85
-          .css('top', '5px')
86
-          .css('left', '0px')
87
-        ;
88
-        $('#rev-close').on('click', function () {
89
-          $('#rev-popup').css('display', 'none');
90
-        });
91
-      });
92
-    % }
93
-  });
94
-% end
95
-
96
-
97
-<div class="row">
98
-  % if ($display eq 'files' || $display eq 'commits' || $display eq 'branches') {
99
-    <%
100
-      my $title;
101
-      my $rev_short;
102
-      if (defined $rev && length $rev == 40) {
103
-        $title = 'tree';
104
-        $rev_short = substr($rev, 0, 10);
105
-      }
106
-      else {
107
-        $title = 'branch';
108
-        $rev_short = $rev;
109
-      }
110
-    %>
111
-    <div class="span2">
112
-      <button id="rev-btn" class="btn" style="font-size:13px;padding:2px 10px;margin-right:6px">
113
-        <i class="icon-share-alt"></i><span class="muted"><%= $title %>:</span> <b><%= $rev_short %></b>
114
-      </button>
115
-    </div>
116
-  % }
117
-  % if ($project_page) {
118
-    <div class="span10" style="text-algin:right;overflow:hidden">
119
-      <a class="btn" style="margin-left:5px;float:right;font-size:12px;font-weight:bold;color:#333;padding:3px 6px" href="<%= url_for("/$user/$project/archive/$rev.zip") %>">
120
-        Download ZIP
121
-      </a>
122
-      <div class="input-append" style="float:right">
123
-        <div class="btn-group" data-toggle="buttons-radio">
124
-          <button class="btn" id="btn_http" style="margin-left:5px;padding:3px 6px;border-top-right-radius:0px; border-bottom-right-radius:0px"><%= $self->req->is_secure ? 'HTTPS' : 'HTTP' %></button>
125
-          % if ($logined) {
126
-            <button class="btn" id="btn_ssh" style="padding:3px 7px;border-radius:0">SSH</button>
127
-          % }
128
-        </div>
129
-        <input id="rep_url" type="text" style="width:550px;border-radius:0;padding:3px 7px;border-top-right-radius:3px;border-bottom-right-radius:3px">
130
-      </div>
131
-    </div>
132
-  % }
133
-</div>
134
-
135
-<div style="position:relative">
136
-  % if ($display eq 'files' || $display eq 'commits') {
137
-    <div id="rev-popup" style="display:none;width:330px;position:absolute">
138
-      <div class="radius-top border-gray" style="background:#E6E6FA;padding:10px">
139
-        <div class="row">
140
-          <div class="span3">
141
-            <b>Switch branches/tags</b>
142
-          </div>
143
-          <div class="text-right">
144
-            <i id="rev-close" class="icon-remove-circle"></i>
145
-          </div>
146
-        </div>
147
-      </div>
148
-      <ul class="nav nav-tabs" id="revs-tab" style="background:#F5F5F5;margin-bottom:0">
149
-        <li class="active"><a href="#branches">Branches</a></li>
150
-        <li><a href="#tags">Tags</a></li>
151
-      </ul>
152
-      <div class="tab-content">
153
-        <div class="tab-pane active" id="branches" style="background:white;max-height:300px;overflow:auto;margin-top:0">
154
-          <ul id="branch-names-list" class="nav nav-tabs nav-stacked">
155
-          </ul>
156
-        </div>
157
-        <div class="tab-pane" id="tags" style="background:white;max-height:300px;overflow:auto;margin-top:0">
158
-          <ul id="tag-names-list" class="nav nav-tabs nav-stacked">
159
-          </ul>
160
-        </div>
161
-      </div>
162
-    </div>
163
-  % } else {
164
-    <div id="rev-popup" style="display:none;width:330px;position:absolute">
165
-      <div class="radius-top border-gray" style="background:#E6E6FA;padding:10px">
166
-        <div class="row">
167
-          <div class="span3">
168
-            <b>Switch branches</b>
169
-          </div>
170
-          <div class="text-right">
171
-            <i id="rev-close" class="icon-remove-circle"></i>
172
-          </div>
173
-        </div>
174
-      </div>
175
-      <ul class="nav nav-tabs" style="background:#F5F5F5;margin-bottom:0">
176
-        <li class="active"><a href="#branches">Branches</a></li>
177
-      </ul>
178
-      <ul id="rev-names-list" class="nav nav-tabs nav-stacked" style="background:white">
179
-        % for my $branch (@$branches) {
180
-          <li>
181
-            <a style="border-top-left-radius:0px;border-top-right-radius:0px;" href="<%= url_for("/$user/$project/branches/$branch->{name}") %>">
182
-              <%= $branch->{name} %>
183
-            </a>
184
-          </li>
185
-        % }
186
-      </ul>
187
-    </div>
188
-  % }
1
+<%
2
+  my $api = gitprep_api;
3
+  
4
+  my $display = stash('display') || '';
5
+  my $rev = stash('rev');
6
+  $rev = '' unless defined $rev;
7
+  my $branches = stash('branches');
8
+  my $tree_top= stash('tree_top');
9
+
10
+  my $logined = $api->logined;
11
+%>
12
+
13
+%= javascript begin
14
+  $(document).ready(function () {
15
+  
16
+    % if ($display eq 'files' || $display eq 'commits') {
17
+      % my $type = $display eq 'files' ? 'tree' : 'commits';
18
+      
19
+      // Switch branches and tags
20
+      var revs_init = false;
21
+      $('#rev-btn').on('click', function () {
22
+        
23
+        if (!revs_init) {
24
+          $.get('<%= url_for("/$user/$project/api/revs") %>', function (result) {
25
+            var branch_names = result.branch_names;
26
+            var tag_names = result.tag_names;
27
+            var style = 'style="border-top-left-radius:0px;border-top-right-radius:0px;"';
28
+            
29
+            if (branch_names.length === 0) {
30
+              $('#branch-names-list').append(
31
+                '<li><a ' + style + ' href="#">No branches</a></li>'
32
+              );
33
+            }
34
+            else {
35
+              for (var i = 0; i < branch_names.length; i++) {
36
+                var branch_name = branch_names[i];
37
+                $('#branch-names-list').append(
38
+                  '<li><a ' + style + ' href="<%= url_for("/$user/$project/$type/") %>' + branch_name + '">' + branch_name + '</a></li>'
39
+                );
40
+              }
41
+            }
42
+            
43
+            if (tag_names.length === 0) {
44
+              $('#tag-names-list').append(
45
+                '<li><a ' + style + ' href="#">No tags</a></li>'
46
+              );
47
+            }
48
+            else {
49
+              for (var i = 0; i < tag_names.length; i++) {
50
+                var tag_name = tag_names[i];
51
+                $('#tag-names-list').append(
52
+                  '<li><a ' + style + ' href="<%= url_for("/$user/$project/$type/") %>' + tag_name + '">' + tag_name + '</a></li>'
53
+                );
54
+              }
55
+            }
56
+            $('#rev-popup')
57
+              .css('display', 'block')
58
+              .css('top', '5px')
59
+              .css('left', '0px')
60
+            ;
61
+          });
62
+          revs_init = true;
63
+        }
64
+        else {
65
+          $('#rev-popup')
66
+            .css('display', 'block')
67
+            .css('top', '5px')
68
+            .css('left', '0px')
69
+          ;
70
+        }
71
+      });
72
+
73
+      $('#revs-tab a').click(function (e) {
74
+        e.preventDefault();
75
+        $(this).tab('show');
76
+      })
77
+      
78
+      $('#rev-close').on('click', function () {
79
+        $('#rev-popup').css('display', 'none');
80
+      });
81
+    % } elsif ($display eq 'branches') {
82
+      $('#rev-btn').on('click', function () {
83
+        $('#rev-popup')
84
+          .css('display', 'block')
85
+          .css('top', '5px')
86
+          .css('left', '0px')
87
+        ;
88
+        $('#rev-close').on('click', function () {
89
+          $('#rev-popup').css('display', 'none');
90
+        });
91
+      });
92
+    % }
93
+  });
94
+% end
95
+
96
+
97
+<div class="row">
98
+  % if ($display eq 'files' || $display eq 'commits' || $display eq 'branches') {
99
+    <%
100
+      my $title;
101
+      my $rev_short;
102
+      if (defined $rev && length $rev == 40) {
103
+        $title = 'tree';
104
+        $rev_short = substr($rev, 0, 10);
105
+      }
106
+      else {
107
+        $title = 'branch';
108
+        $rev_short = $rev;
109
+      }
110
+    %>
111
+    <div class="span2">
112
+      <button id="rev-btn" class="btn" style="font-size:13px;padding:2px 10px;margin-right:6px">
113
+        <i class="icon-share-alt"></i><span class="muted"><%= $title %>:</span> <b><%= $rev_short %></b>
114
+      </button>
115
+    </div>
116
+  % }
117
+  % if ($tree_top) {
118
+    <div class="span10" style="text-algin:right;overflow:hidden">
119
+      <a class="btn" style="margin-left:5px;float:right;font-size:12px;font-weight:bold;color:#333;padding:3px 6px" href="<%= url_for("/$user/$project/archive/$rev.zip") %>">
120
+        Download ZIP
121
+      </a>
122
+      <div class="input-append" style="float:right">
123
+        <div class="btn-group" data-toggle="buttons-radio">
124
+          <button class="btn" id="btn_http" style="margin-left:5px;padding:3px 6px;border-top-right-radius:0px; border-bottom-right-radius:0px"><%= $self->req->is_secure ? 'HTTPS' : 'HTTP' %></button>
125
+          % if ($logined) {
126
+            <button class="btn" id="btn_ssh" style="padding:3px 7px;border-radius:0">SSH</button>
127
+          % }
128
+        </div>
129
+        <input id="rep_url" type="text" style="width:550px;border-radius:0;padding:3px 7px;border-top-right-radius:3px;border-bottom-right-radius:3px">
130
+      </div>
131
+    </div>
132
+  % }
133
+</div>
134
+
135
+<div style="position:relative">
136
+  % if ($display eq 'files' || $display eq 'commits') {
137
+    <div id="rev-popup" style="display:none;width:330px;position:absolute">
138
+      <div class="radius-top border-gray" style="background:#E6E6FA;padding:10px">
139
+        <div class="row">
140
+          <div class="span3">
141
+            <b>Switch branches/tags</b>
142
+          </div>
143
+          <div class="text-right">
144
+            <i id="rev-close" class="icon-remove-circle"></i>
145
+          </div>
146
+        </div>
147
+      </div>
148
+      <ul class="nav nav-tabs" id="revs-tab" style="background:#F5F5F5;margin-bottom:0">
149
+        <li class="active"><a href="#branches">Branches</a></li>
150
+        <li><a href="#tags">Tags</a></li>
151
+      </ul>
152
+      <div class="tab-content">
153
+        <div class="tab-pane active" id="branches" style="background:white;max-height:300px;overflow:auto;margin-top:0">
154
+          <ul id="branch-names-list" class="nav nav-tabs nav-stacked">
155
+          </ul>
156
+        </div>
157
+        <div class="tab-pane" id="tags" style="background:white;max-height:300px;overflow:auto;margin-top:0">
158
+          <ul id="tag-names-list" class="nav nav-tabs nav-stacked">
159
+          </ul>
160
+        </div>
161
+      </div>
162
+    </div>
163
+  % } else {
164
+    <div id="rev-popup" style="display:none;width:330px;position:absolute">
165
+      <div class="radius-top border-gray" style="background:#E6E6FA;padding:10px">
166
+        <div class="row">
167
+          <div class="span3">
168
+            <b>Switch branches</b>
169
+          </div>
170
+          <div class="text-right">
171
+            <i id="rev-close" class="icon-remove-circle"></i>
172
+          </div>
173
+        </div>
174
+      </div>
175
+      <ul class="nav nav-tabs" style="background:#F5F5F5;margin-bottom:0">
176
+        <li class="active"><a href="#branches">Branches</a></li>
177
+      </ul>
178
+      <ul id="rev-names-list" class="nav nav-tabs nav-stacked" style="background:white">
179
+        % for my $branch (@$branches) {
180
+          <li>
181
+            <a style="border-top-left-radius:0px;border-top-right-radius:0px;" href="<%= url_for("/$user/$project/branches/$branch->{name}") %>">
182
+              <%= $branch->{name} %>
183
+            </a>
184
+          </li>
185
+        % }
186
+      </ul>
187
+    </div>
188
+  % }
189 189
 </div>
-209
templates/project.html.ep
... ...
@@ -1,209 +0,0 @@
1
-<%
2
-  use Text::Markdown::Hoedown;
3
-
4
-  my $state;
5
-
6
-  # API
7
-  my $api = gitprep_api;
8
-
9
-  # Git
10
-  my $git = app->git;
11
-  
12
-  # Parameters
13
-  my $user = param('user');
14
-  my $project = param('project');
15
-  my $rev = app->manager->default_branch($user, $project);
16
-  
17
-  unless (app->manager->exists_project($user, $project)) {
18
-    $self->render_not_found;
19
-    return;
20
-  }
21
-
22
-  # Repository description
23
-  my $desc = $git->description($user, $project);
24
-  
25
-  # Check exsitence
26
-  my $commits_number;
27
-  if ($git->exists_branch($user, $project)) {
28
-    # Commit
29
-    my $commit = $git->get_commit($user, $project, $rev);
30
-    
31
-    # Tree
32
-    my $trees = $git->trees($user, $project, $rev);
33
-    
34
-    # Commits number
35
-    $commits_number = $git->commits_number($user, $project, $rev);
36
-    
37
-    # Variable for included template
38
-    stash(
39
-      commit => $commit,
40
-      trees => $trees,
41
-      rev => $rev,
42
-      title => "$user/$project",
43
-    );
44
-    
45
-    $state = 'display';
46
-  }
47
-  else { $state = 'init' }
48
-
49
-  my $url = url_for->to_abs;
50
-  $url->base(undef);
51
-  my $ssh_port = config->{basic}{ssh_port};
52
-  my $rep_home = app->git->rep_home;
53
-  my $execute_user = getpwuid($>);
54
-  my $ssh_rep_url_base = defined app->config->{basic}{'ssh_rep_url_base'}
55
-    ? app->config->{basic}{'ssh_rep_url_base'} : $rep_home;
56
-  my $ssh_rep_url = "ssh://$execute_user\@" . $url->host
57
-    . ($ssh_port ? ":$ssh_port" : '') . "$ssh_rep_url_base/$user/$project.git";
58
-
59
-  my $branches = stash('branches');
60
-  my $branches_count = app->git->branches_count($user, $project);
61
-  my $default_branch_name = app->manager->default_branch($user, $project);
62
-  my $tags_count = app->git->tags_count($user, $project);
63
-  my $display = 'files';
64
-  
65
-  my $logined = $api->logined;
66
-  
67
-  layout 'common', title => "$user/$project";
68
-%>
69
-
70
-  %= javascript begin
71
-    $(document).ready(function () {
72
-      var http_rep_url = '<%= url_for("$user/$project.git")->to_abs %>';
73
-      % my $rep = $git->rep($user, $project);
74
-      % my $ssh_port = config->{basic}{ssh_port} || '';
75
-      
76
-      var logined = <%= $logined ? 'true' : 'false' %>;
77
-      var ssh_rep_url = '';
78
-      if (logined) {
79
-        ssh_rep_url = '<%= $ssh_rep_url %>';
80
-      }
81
-      
82
-      // Click HTTP button
83
-      $('#btn_http').on('click', function () {
84
-        $('#rep_url').val(http_rep_url);
85
-        $('#access').text('Read-write');
86
-      });
87
-
88
-      // Click SSH(old) button
89
-      $('#btn_ssh').on('click', function () {
90
-        $('#rep_url').val(ssh_rep_url);
91
-        $('#access').text('Read-write');
92
-      });
93
-
94
-      // Initialize
95
-      $('#btn_http').trigger('click');
96
-      
97
-      // URL is automatically selected
98
-      var url_selected_count = 0;
99
-      $('#rep_url').on('mouseup', function () {
100
-        if (url_selected_count == 0) {
101
-          $(this).select();
102
-        }
103
-        url_selected_count += 1;
104
-      });
105
-      $('#rep_url').on('blur', function () {
106
-        url_selected_count = 0;
107
-      });
108
-    });
109
-  % end
110
-  
111
-  %= include '/include/header';
112
-  
113
-  <div class="container">
114
-    %= include '/include/message', message => flash('message');
115
-    
116
-    <h3 style="font-weight:normal;color:#666;margin:20px 0px 20px 0;font-size:16px;line-height:0">
117
-      <%= $desc %>
118
-    </h3>
119
-    % if ($state eq 'display') {
120
-      <ul class="nav nav-tabs" style="margin-bottom:20px">
121
-        <li class="<%= $display eq 'commits' ? 'active' : '' %>">
122
-          % if (length $rev) {
123
-            <a href="<%= url_for("/$user/$project/commits/$rev") %>">
124
-              <%= $commits_number %> commits
125
-            </a>
126
-          % } else {
127
-            <a href="<%= url_for("/$user/$project/commits/$default_branch_name") %>">
128
-              <%= $commits_number %> Commits
129
-            </a>
130
-          % }
131
-        </li>
132
-        <li class="<%= $display eq 'branches' ? 'active' : '' %>">
133
-          <a href="<%= url_for("/$user/$project/branches") %>">
134
-            <%= $branches_count %> branches
135
-          </a>
136
-        </li>
137
-        <li class="<%= $display eq 'tags' ? 'active' : '' %>">
138
-          <a href="<%= url_for("/$user/$project/tags") %>">
139
-            <%= $tags_count %> releases
140
-          </a>
141
-        </li>
142
-      </ul>
143
-
144
-      <div style="margin-bottom:5px;">
145
-        %= include '/include/branch_select', display => 'files', project_page => 1;
146
-      </div>
147
-      
148
-      <div style="margin-bottom:30px">
149
-        %= include '/include/tree';
150
-      </div>
151
-      
152
-      %= include '/include/readme';
153
-      
154
-    % } elsif ($state eq 'init' && $api->logined($user)) {
155
-      
156
-      <h4>SSH</h4>
157
-      
158
-      <div class="text-center" style="margin-bottom:10px">
159
-        <b>Create a new repository on the command line via ssh</b>
160
-      </div>
161
-      
162
-      <pre style="margin-bottom:30px">
163
-touch README
164
-git init
165
-git add README
166
-git commit -m "first commit"
167
-git remote add origin <%= $ssh_rep_url %>
168
-git push -u origin master</pre>
169
-      
170
-      <div class="text-center" style="margin-bottom:10px">
171
-        <b>Push an existing repository from the command line via ssh</b>
172
-      </div>
173
-      
174
-      <pre style="margin-bottom:30px">
175
-git remote add origin <%= $ssh_rep_url %>
176
-git push -u origin master</pre>
177
-
178
-      <hr>
179
-
180
-      % my $http_rep_url = url_for("$user/$project.git")->to_abs;
181
-      <h4><%= uc url_for->to_abs->scheme %></h4>
182
-
183
-      <div class="text-center" style="margin-bottom:10px">
184
-        <b>Create a new repository on the command line via <%= url_for->to_abs->scheme %></b>
185
-      </div>
186
-      
187
-      <pre style="margin-bottom:30px">
188
-touch README
189
-git init
190
-git add README
191
-git commit -m "first commit"
192
-git remote add origin <%= $http_rep_url %>
193
-git push -u origin master</pre>
194
-      
195
-      <div class="text-center" style="margin-bottom:10px">
196
-        <b>Push an existing repository from the command line via <%= url_for->to_abs->scheme %></b>
197
-      </div>
198
-      
199
-      <pre style="margin-bottom:30px">
200
-git remote add origin <%= $http_rep_url %>
201
-git push -u origin master</pre>
202
-    % } else {
203
-      <div class="well text-center muted" style="background:white;margin-bottom:30px">
204
-        <b>Repository is not yet created.</b>
205
-      </div>
206
-    % }
207
-  </div>
208
-  
209
-  %= include '/include/footer';
+246 -29
templates/tree.html.ep
... ...
@@ -1,4 +1,8 @@
1 1
 <%
2
+  use Text::Markdown::Hoedown;
3
+
4
+  my $state;
5
+
2 6
   # API
3 7
   my $api = gitprep_api;
4 8
 
... ...
@@ -8,42 +12,255 @@
8 12
   # Parameters
9 13
   my $user = param('user');
10 14
   my $project = param('project');
15
+  
16
+  my $rev;
17
+  my $dir;
11 18
   my $rev_dir = param('rev_dir');
12
-  my ($rev, $dir) = $git->parse_rev_path($user, $project, $rev_dir);
13
-  
14
-  # Tree id
15
-  my $commit = $git->get_commit($user, $project, $rev);
16
-  my $top;
17
-  $top = 1 unless defined $dir && $dir ne '';
18
-
19
-  # Tree
20
-  my $trees = $git->trees($user, $project, $rev, $dir);
21
-  
22
-  # Commits number
23
-  my $commits_number = $git->commits_number($user, $project, $rev);
24
-  
25
-  # Variable for included templates
26
-  stash(
27
-    commit => $commit,
28
-    trees => $trees,
29
-    rev => $rev,
30
-    dir => $dir
31
-  );
19
+  if (defined $rev_dir) {
20
+    ($rev, $dir) = $git->parse_rev_path($user, $project, $rev_dir);
21
+  }
22
+  else {
23
+    $rev = app->manager->default_branch($user, $project);
24
+  }
25
+  
26
+  unless (app->manager->exists_project($user, $project)) {
27
+    $self->render_not_found;
28
+    return;
29
+  }
30
+
31
+  # Repository description
32
+  my $desc = $git->description($user, $project);
33
+  
34
+  # Check exsitence
35
+  my $commits_number;
36
+  if ($git->exists_branch($user, $project)) {
37
+    # Commit
38
+    my $commit = $git->get_commit($user, $project, $rev);
39
+    
40
+    # Tree
41
+    my $trees = $git->trees($user, $project, $rev);
42
+    
43
+    # Commits number
44
+    $commits_number = $git->commits_number($user, $project, $rev);
45
+    
46
+    # Variable for included template
47
+    stash(
48
+      commit => $commit,
49
+      trees => $trees,
50
+      rev => $rev,
51
+      title => "$user/$project",
52
+    );
53
+    
54
+    $state = 'display';
55
+  }
56
+  else { $state = 'init' }
57
+
58
+  my $url = url_for->to_abs;
59
+  $url->base(undef);
60
+  my $ssh_port = config->{basic}{ssh_port};
61
+  my $rep_home = app->git->rep_home;
62
+  my $execute_user = getpwuid($>);
63
+  my $ssh_rep_url_base = defined app->config->{basic}{'ssh_rep_url_base'}
64
+    ? app->config->{basic}{'ssh_rep_url_base'} : $rep_home;
65
+  my $ssh_rep_url = "ssh://$execute_user\@" . $url->host
66
+    . ($ssh_port ? ":$ssh_port" : '') . "$ssh_rep_url_base/$user/$project.git";
67
+
68
+  my $branches = stash('branches');
69
+  my $branches_count = app->git->branches_count($user, $project);
70
+  my $default_branch_name = app->manager->default_branch($user, $project);
71
+  my $tags_count = app->git->tags_count($user, $project);
72
+  my $display = 'files';
73
+  
74
+  my $logined = $api->logined;
75
+  
76
+  layout 'common', title => "$user/$project";
32 77
 %>
33 78
 
34
-% layout 'common', title => "$project/$dir at $rev \x{30fb} $user/$project";
79
+  %= javascript begin
80
+    $(document).ready(function () {
81
+      var http_rep_url = '<%= url_for("$user/$project.git")->to_abs %>';
82
+      % my $rep = $git->rep($user, $project);
83
+      % my $ssh_port = config->{basic}{ssh_port} || '';
84
+      
85
+      var logined = <%= $logined ? 'true' : 'false' %>;
86
+      var ssh_rep_url = '';
87
+      if (logined) {
88
+        ssh_rep_url = '<%= $ssh_rep_url %>';
89
+      }
90
+      
91
+      // Click HTTP button
92
+      $('#btn_http').on('click', function () {
93
+        $('#rep_url').val(http_rep_url);
94
+        $('#access').text('Read-write');
95
+      });
96
+
97
+      // Click SSH(old) button
98
+      $('#btn_ssh').on('click', function () {
99
+        $('#rep_url').val(ssh_rep_url);
100
+        $('#access').text('Read-write');
101
+      });
102
+
103
+      // Initialize
104
+      $('#btn_http').trigger('click');
105
+      
106
+      // URL is automatically selected
107
+      var url_selected_count = 0;
108
+      $('#rep_url').on('mouseup', function () {
109
+        if (url_selected_count == 0) {
110
+          $(this).select();
111
+        }
112
+        url_selected_count += 1;
113
+      });
114
+      $('#rep_url').on('blur', function () {
115
+        url_selected_count = 0;
116
+      });
117
+    });
118
+  % end
35 119
   
36 120
   %= include '/include/header';
37
-
121
+  
38 122
   <div class="container">
39
-    <div style="margin-bottom:20px;">
40
-      %= include '/include/branch_select', display => 'files';
41
-    </div>
42
-    %= include '/include/page_path', type => 'tree', Path => $dir;
43
-    %= include '/include/tree';
123
+    %= include '/include/message', message => flash('message');
44 124
     
45
-    %= include '/include/readme', dir => $dir;
125
+    % if (!(defined $dir && length $dir)) {
126
+      <h3 style="font-weight:normal;color:#666;margin:20px 0px 20px 0;font-size:16px;line-height:0">
127
+        <%= $desc %>
128
+      </h3>
129
+    % }
130
+    % if ($state eq 'display') {
131
+      % if (!(defined $dir && length $dir)) {
132
+        %= stylesheet begin
133
+          .commits-count {
134
+            margin:0;
135
+            border-radius: 3px 3px 0 0;
136
+            border: 1px solid #ddd;
137
+            border-bottom:none;
138
+          }
139
+          
140
+          .commits-count li {
141
+            display:inline-block;
142
+            width:25%;
143
+            margin-left:0px;
144
+            list-style-type: none;
145
+            padding:0;
146
+            text-align:center;
147
+          }
148
+          .commits-count li a {
149
+            width:100%;
150
+            display:block;
151
+            padding:10px 0;
152
+            color:#767676;
153
+          }
154
+          .commits-count li a:hover {
155
+            color:#4078c0;
156
+            text-decoration:none;
157
+          }
158
+        % end
159
+        
160
+        <ul class="commits-count">
161
+          <li>
162
+            % my $commits_url = "/$user/$project/commits/" . ((defined $rev && length $rev) ? $rev : $default_branch_name);
163
+            <a href="<%= url_for($commits_url) %>">
164
+              <span class="commits-count-number">
165
+                <i class="icon-repeat"></i>
166
+                <%= $commits_number %>
167
+              </span>
168
+              <span class="commits-count-type">
169
+                commits
170
+              </span>
171
+            </a>
172
+          </li>
173
+          <li>
174
+            <a href="<%= url_for("/$user/$project/branches") %>">
175
+              <span class="commits-count-number">
176
+                <i class="icon-indent-left"></i>
177
+                <%= $branches_count %>
178
+              </span>
179
+              <span class="commits-count-type">
180
+                branches
181
+              </span>
182
+            </a>
183
+          </li>
184
+          <li>
185
+            <a href="<%= url_for("/$user/$project/tags") %>">
186
+              <span class="commits-count-number">
187
+                <i class="icon-tags"></i>
188
+                <%= $tags_count %>
189
+              </span>
190
+              <span class="commits-count-type">
191
+                releases
192
+              </span>
193
+            </a>
194
+          </li>
195
+        </ul>
196
+        <div style="border-radius:0 0 3px 3px;border: 1px solid #ddd;min-height:8px;border-top:none;margin-bottom:15px;background:#0298c3">
197
+          
198
+        </div>
199
+      % }
200
+
201
+      <div style="margin-bottom:5px;">
202
+        %= include '/include/branch_select', display => 'files', ((defined $dir && length $dir) ? () : (tree_top => 1));
203
+      </div>
204
+      
205
+      <div style="margin-bottom:30px">
206
+        %= include '/include/tree';
207
+      </div>
208
+      
209
+      %= include '/include/readme';
210
+      
211
+    % } elsif ($state eq 'init' && $api->logined($user)) {
212
+      
213
+      <h4>SSH</h4>
214
+      
215
+      <div class="text-center" style="margin-bottom:10px">
216
+        <b>Create a new repository on the command line via ssh</b>
217
+      </div>
218
+      
219
+      <pre style="margin-bottom:30px">
220
+touch README
221
+git init
222
+git add README
223
+git commit -m "first commit"
224
+git remote add origin <%= $ssh_rep_url %>
225
+git push -u origin master</pre>
226
+      
227
+      <div class="text-center" style="margin-bottom:10px">
228
+        <b>Push an existing repository from the command line via ssh</b>
229
+      </div>
230
+      
231
+      <pre style="margin-bottom:30px">
232
+git remote add origin <%= $ssh_rep_url %>
233
+git push -u origin master</pre>
234
+
235
+      <hr>
236
+
237
+      % my $http_rep_url = url_for("$user/$project.git")->to_abs;
238
+      <h4><%= uc url_for->to_abs->scheme %></h4>
239
+
240
+      <div class="text-center" style="margin-bottom:10px">
241
+        <b>Create a new repository on the command line via <%= url_for->to_abs->scheme %></b>
242
+      </div>
243
+      
244
+      <pre style="margin-bottom:30px">
245
+touch README
246
+git init
247
+git add README
248
+git commit -m "first commit"
249
+git remote add origin <%= $http_rep_url %>
250
+git push -u origin master</pre>
251
+      
252
+      <div class="text-center" style="margin-bottom:10px">
253
+        <b>Push an existing repository from the command line via <%= url_for->to_abs->scheme %></b>
254
+      </div>
255
+      
256
+      <pre style="margin-bottom:30px">
257
+git remote add origin <%= $http_rep_url %>
258
+git push -u origin master</pre>
259
+    % } else {
260
+      <div class="well text-center muted" style="background:white;margin-bottom:30px">
261
+        <b>Repository is not yet created.</b>
262
+      </div>
263
+    % }
46 264
   </div>
47 265
   
48 266
   %= include '/include/footer';
49
-