gitprep / lib / Gitprep.pm /
Newer Older
154 lines | 3.925kb
copy gitweblite soruce code
root authored on 2012-11-23
1
use 5.008007;
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
2
package Gitprep;
copy gitweblite soruce code
root authored on 2012-11-23
3

            
4
our $VERSION = '1.00';
5

            
6
use Mojo::Base 'Mojolicious';
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
7
use Gitprep::Git;
copy gitweblite soruce code
root authored on 2012-11-23
8

            
9
has 'git';
10

            
11
sub startup {
12
  my $self = shift;
13
  
14
  # Config
renamed githublite to gitpub
Yuki Kimoto authored on 2012-11-23
15
  my $conf_file = $ENV{GITPUB_CONFIG_FILE}
16
    || $self->home->rel_file('gitpub.conf');
copy gitweblite soruce code
root authored on 2012-11-23
17
  $self->plugin('JSONConfigLoose', {file => $conf_file}) if -f $conf_file;
18
  my $conf = $self->config;
19
  $conf->{search_dirs} ||= ['/git/pub', '/home'];
20
  $conf->{search_max_depth} ||= 10;
renamed githublite to gitpub
Yuki Kimoto authored on 2012-11-23
21
  $conf->{logo_link} ||= "https://github.com/yuki-kimoto/gitpub";
copy gitweblite soruce code
root authored on 2012-11-23
22
  $conf->{hypnotoad} ||= {listen => ["http://*:10010"]};
23
  $conf->{prevent_xss} ||= 0;
24
  $conf->{encoding} ||= 'UTF-8';
25
  $conf->{text_exts} ||= ['txt'];
26
  
27
  # Git
renamed gitpub to gitprep
Yuki Kimoto authored on 2012-11-26
28
  my $git = Gitprep::Git->new;
copy gitweblite soruce code
root authored on 2012-11-23
29
  my $git_bin = $conf->{git_bin} ? $conf->{git_bin} : $git->search_bin;
renamed githublite to gitpub
Yuki Kimoto authored on 2012-11-23
30
  die qq/Can't detect git command. set "git_bin" in gitpub.conf/
copy gitweblite soruce code
root authored on 2012-11-23
31
    unless $git_bin;
32
  $git->bin($git_bin);
33
  $git->search_dirs($conf->{search_dirs});
34
  $git->search_max_depth($conf->{search_max_depth});
35
  $git->encoding($conf->{encoding});
36
  $git->text_exts($conf->{text_exts});
37
  $self->git($git);
38

            
39
  # Helper
40
  {
41
    # Remove top slash
renamed githublite to gitpub
Yuki Kimoto authored on 2012-11-23
42
    $self->helper('gitpub_rel' => sub {
copy gitweblite soruce code
root authored on 2012-11-23
43
      my ($self, $path) = @_;
44
      
45
      $path =~ s/^\///;
46
      
47
      return $path;
48
    });
49
    
50
    # Get head commit id
renamed githublite to gitpub
Yuki Kimoto authored on 2012-11-23
51
    $self->helper('gitpub_get_head_id' => sub {
copy gitweblite soruce code
root authored on 2012-11-23
52
      my ($self, $project) = @_;
53
      
54
      my $head_commit = $self->app->git->parse_commit($project, "HEAD");
55
      my $head_id = $head_commit->{id};
56
      
57
      return $head_id;
58
    });
59
  }
60
  
61
  # Added user public and templates path
62
  unshift @{$self->static->paths}, $self->home->rel_file('user/public');
63
  unshift @{$self->renderer->paths}, $self->home->rel_file('user/templates');
64
  
65
  # Reverse proxy support
66
  $ENV{MOJO_REVERSE_PROXY} = 1;
67
  $self->hook('before_dispatch' => sub {
68
    my $self = shift;
69
    
70
    if ( $self->req->headers->header('X-Forwarded-Host')) {
71
        my $prefix = shift @{$self->req->url->path->parts};
72
        push @{$self->req->url->base->path->parts}, $prefix;
73
    }
74
  });
Dipslay users in home page
Yuki Kimoto authored on 2012-11-23
75
  
copy gitweblite soruce code
root authored on 2012-11-23
76
  # Route
77
  my $r = $self->routes->route->to('main#');
Dipslay users in home page
Yuki Kimoto authored on 2012-11-23
78

            
copy gitweblite soruce code
root authored on 2012-11-23
79
  # Home
80
  $r->get('/')->to('#home');
Fixed repositories page
Yuki Kimoto authored on 2012-11-23
81

            
improved repository page des...
Yuki Kimoto authored on 2012-11-23
82
  # Repositories
Fixed repositories page
Yuki Kimoto authored on 2012-11-23
83
  $r->get('/:user')->to('#repositories');
copy gitweblite soruce code
root authored on 2012-11-23
84
  
improved repository page des...
Yuki Kimoto authored on 2012-11-23
85
  # Repository
86
  $r->get('/:user/:repository')->to('#repository');
87

            
88
=pod  
copy gitweblite soruce code
root authored on 2012-11-23
89
  # Projects
90
  $r->get('/(*home)/projects')->to('#projects')->name('projects');
91
  
92
  # Project
93
  {
94
    my $r = $r->route('/(*project)', project => qr/.+?\.git/);
95
    
96
    # Summary
97
    $r->get('/summary')->to('#summary')->name('summary');
98
    
99
    # Short log
100
    $r->get('/shortlog/(*id)', {id => 'HEAD'})
101
      ->to('#log', short => 1)->name('shortlog');
102
    
103
    # Log
104
    $r->get('/log/(*id)', {id => 'HEAD'})->to('#log')->name('log');
105
    
106
    # Commit
107
    $r->get('/commit/(*id)')->to('#commit')->name('commit');
108
    
109
    # Commit diff
110
    $r->get('/commitdiff/(*diff)')->to('#commitdiff')->name('commitdiff');
111
    
112
    # Commit diff plain
113
    $r->get('/commitdiff-plain/(*diff)')
114
      ->to('#commitdiff', plain => 1)->name('commitdiff_plain');
115
    
116
    # Tags
117
    $r->get('/tags')->to('#tags')->name('tags');
118
    
119
    # Tag
120
    $r->get('/tag/(*id)')->to('#tag')->name('tag');
121
    
122
    # Heads
123
    $r->get('/heads')->to('#heads')->name('heads');
124
    
125
    # Tree
126
    $r->get('/tree/(*id_dir)', {id_dir => 'HEAD'})
127
      ->to('#tree')->name('tree');
128
    
129
    # Blob
130
    $r->get('/blob/(*id_file)')->to('#blob')->name('blob');
131
    
132
    # Blob plain
133
    $r->get('/blob-plain/(*id_file)')
134
      ->to('#blob', plain => 1)->name('blob_plain');
135
    
136
    # Blob diff
137
    $r->get('/blobdiff/(#diff)/(*file)')
138
      ->to('#blobdiff')->name('blobdiff');
139

            
140
    # Blob diff plain
141
    $r->get('/blobdiff-plain/(#diff)/(*file)')
142
      ->to('#blobdiff', plain => 1)->name('blobdiff_plain');
143
    
144
    # Snapshot
145
    $r->get('/snapshot/(:id)', {id => 'HEAD'})
146
      ->to('#snapshot')->name('snapshot');
147
  }
improved repository page des...
Yuki Kimoto authored on 2012-11-23
148
=cut
copy gitweblite soruce code
root authored on 2012-11-23
149
  
150
  # File cache
151
  $git->search_projects;
152
}
153

            
154
1;