Showing 2 changed files with 66 additions and 33 deletions
+23 -27
lib/Gitprep.pm
... ...
@@ -113,6 +113,12 @@ sub startup {
113 113
   
114 114
 
115 115
   # Routes
116
+  sub template {
117
+    my $template = shift;
118
+    
119
+    return (cb => sub { shift->render($template, , 'mojo.maybe' => 1)});
120
+  }
121
+  
116 122
   {
117 123
     my $r = $self->routes;
118 124
 
... ...
@@ -154,10 +160,10 @@ sub startup {
154 160
       my $r = $r->route('/:user');
155 161
       {
156 162
         # Home
157
-        $r->get('/')->name('user');
163
+        $r->get('/')->to(template '/user');
158 164
         
159 165
         # Settings
160
-        $r->get('/_settings')->name('user-settings');
166
+        $r->get('/_settings')->to(template '/user-settings');
161 167
       }
162 168
       
163 169
       # Project
... ...
@@ -165,50 +171,50 @@ sub startup {
165 171
         my $r = $r->route('/:project');
166 172
         
167 173
         # Home
168
-        $r->get('/')->name('project');
174
+        $r->get('/')->to(template '/project');
169 175
         
170 176
         # Commit
171
-        $r->get('/commit/*diff')->name('commit');
177
+        $r->get('/commit/*diff')->to(template '/commit');
172 178
         
173 179
         # Commits
174
-        $r->get('/commits/*rev_file', {file => undef})->name('commits');
180
+        $r->get('/commits/*rev_file', {file => undef})->to(template '/commits');
175 181
         
176 182
         # Branches
177
-        $r->any('/branches/*base_branch', {base_branch => undef})->name('branches');
183
+        $r->any('/branches/*base_branch', {base_branch => undef})->to(template '/branches');
178 184
 
179 185
         # Tags
180 186
         $r->get('/tags');
181 187
 
182 188
         # Tree
183
-        $r->get('/tree/*rev_dir', {dir => undef})->name('tree');
189
+        $r->get('/tree/*rev_dir', {dir => undef})->to(template '/tree');
184 190
         
185 191
         # Blob
186
-        $r->get('/blob/*rev_file', {file => undef})->name('blob');
192
+        $r->get('/blob/*rev_file', {file => undef})->to(template '/blob');
187 193
         
188 194
         # Raw
189
-        $r->get('/raw/*rev_file', {file => undef})->name('raw');
195
+        $r->get('/raw/*rev_file', {file => undef})->to(template '/raw');
190 196
         
191 197
         # Archive
192
-        $r->get('/archive/(*rev).tar.gz')->to(archive_type => 'tar')->name('archive');
193
-        $r->get('/archive/(*rev).zip')->to(archive_type => 'zip')->name('archive');
198
+        $r->get('/archive/(*rev).tar.gz')->to(archive_type => 'tar')->to(template '/archive');
199
+        $r->get('/archive/(*rev).zip')->to(archive_type => 'zip')->to(template '/archive');
194 200
         
195 201
         # Compare
196
-        $r->get('/compare/(*rev1)...(*rev2)')->name('compare');
202
+        $r->get('/compare/(*rev1)...(*rev2)')->to(template '/compare');
197 203
         
198 204
         # Settings
199
-        $r->any('/settings');
205
+        $r->any('/settings')->to(template '/settings');
200 206
         
201 207
         # Fork
202
-        $r->any('/fork');
208
+        $r->any('/fork')->to(template '/fork');
203 209
 
204 210
         # Network
205
-        $r->get('/network');
211
+        $r->get('/network')->to(template '/network');
206 212
 
207 213
         # Network Graph
208
-        $r->get('/network/graph/(*rev1)...(*rev2_abs)')->name('network/graph');
214
+        $r->get('/network/graph/(*rev1)...(*rev2_abs)')->to(template '/network/graph');
209 215
         
210 216
         # Get branches and tags
211
-        $r->get('/api/revs')->name('api/revs');
217
+        $r->get('/api/revs')->to(template '/api/revs');
212 218
       }
213 219
     }
214 220
   }
... ...
@@ -217,16 +223,6 @@ sub startup {
217 223
   {
218 224
     # API
219 225
     $self->helper(gitprep_api => sub { Gitprep::API->new(shift) });
220
-    
221
-    # Finish rendering
222
-    $self->helper(finish_rendering => sub {
223
-      my $self = shift;
224
-      
225
-      $self->stash->{'mojo.routed'} = 1;
226
-      $self->rendered;
227
-      
228
-      return $self;
229
-    });
230 226
   }
231 227
   
232 228
   # Reverse proxy support
+43 -6
mojo/lib/Mojolicious/Plugin/AutoRoute.pm
... ...
@@ -1,7 +1,7 @@
1 1
 package Mojolicious::Plugin::AutoRoute;
2 2
 use Mojo::Base 'Mojolicious::Plugin';
3 3
 
4
-our $VERSION = '0.08';
4
+our $VERSION = '0.09';
5 5
 
6 6
 sub register {
7 7
   my ($self, $app, $conf) = @_;
... ...
@@ -38,7 +38,7 @@ sub register {
38 38
   # Index
39 39
   $r->route('/')
40 40
     ->over($condition_name)
41
-    ->to(cb => sub { shift->render("/$top_dir/index") });
41
+    ->to(cb => sub { shift->render("/$top_dir/index", 'mojo.maybe' => 1) });
42 42
   
43 43
   # Route
44 44
   $r->route('/(*__auto_route_plugin_path)')
... ...
@@ -48,8 +48,18 @@ sub register {
48 48
       
49 49
       my $path = $c->stash('__auto_route_plugin_path');
50 50
       
51
-      $c->render("/$top_dir/$path");
51
+      $c->render("/$top_dir/$path", 'mojo.maybe' => 1);
52 52
     });
53
+  
54
+  # Finish rendering Helper
55
+  $app->helper(finish_rendering => sub {
56
+    my $self = shift;
57
+    
58
+    $self->stash->{'mojo.routed'} = 1;
59
+    $self->rendered;
60
+    
61
+    return $self;
62
+  });
53 63
 }
54 64
 
55 65
 1;
... ...
@@ -88,7 +98,7 @@ You only put file into C<auto> directory.
88 98
 
89 99
 =head1 OPTIONS
90 100
 
91
-=head2 C<route>
101
+=head2 route
92 102
 
93 103
   route => $route;
94 104
 
... ...
@@ -96,7 +106,7 @@ You can set parent route if you need.
96 106
 This is L<Mojolicious::Routes> object.
97 107
 Default is C<$app->routes>.
98 108
 
99
-=head2 C<top_dir>
109
+=head2 top_dir
100 110
 
101 111
   top_dir => 'myauto'
102 112
 
... ...
@@ -107,7 +117,34 @@ Top directory. default is C<auto>.
107 117
 L<Mojolicious::Plugin::AutoRoute> inherits all methods from
108 118
 L<Mojolicious::Plugin> and implements the following new ones.
109 119
 
110
-=head2 C<register>
120
+=head1 HELPER
121
+
122
+=head2 finish_rendering
123
+
124
+You can render data, json, not found and exeption from template
125
+using C<finish_rendering> helper.
126
+
127
+  @@ index.html.ep
128
+  $self->render(data => 'foo');
129
+  $self->finish_rendering;
130
+  return;
131
+
132
+  @@ index.html.ep
133
+  $self->render(json => {foo => 1});
134
+  $self->finish_rendering;
135
+  return;
136
+
137
+  @@ index.html.ep
138
+  $self->render_not_found;
139
+  $self->finish_rendering;
140
+  return;
141
+
142
+  @@ index.html.ep
143
+  $self->render_exception;
144
+  $self->finish_rendering;
145
+  return;
146
+
147
+=head2 register
111 148
 
112 149
   $plugin->register($app);
113 150