Skip to content

Commit

Permalink
config file become JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed May 4, 2012
1 parent 6a11d73 commit d879895
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
8 changes: 6 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
0.02
0.03 (beta)
- config file become JSON.
- URL become more restful.
0.02 (beta)
- fixed blob, blog_plain, commitdiff, commitdiff_plain encoding bug
0.01

0.01 (beta)
- first beta release.
22 changes: 11 additions & 11 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,40 @@ Description

Config

You can set config in gitweblite.conf. Config is written by Perl data structure.
You can set config in gitweblite.conf. Config is written by JSON.

search_dirs => [$dir, ...]

search_dirs
Git repository searching directories.

Default:

search_dirs => ['/git/pub', '/home']
"search_dirs" : ["/git/pub", "/home"]

search_max_depth => $num
search_max_depth

Searching directory max depth.

Default:

search_max_depth => 10
"search_max_depth" : 10

git_bin => $path
git_bin

git command

Default:

git_bin => '/usr/local/bin/git'
"git_bin" : "/usr/local/bin/git"

hypnotoad => {$opt => $val, ...}
hypnotoad

Server configuration.

Default:

hypnotoad => {
listen => ['http://*:10010']
"hypnotoad" : {
"listen" => ["http://*:10010"]
}

See also gitweblite.conf.example.
5 changes: 3 additions & 2 deletions gitweblite.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
hypnotoad => {
listen => ['http://*:10010']
// Server config
"hypnotoad" : {
"listen" : ["http://*:10010"]
}
}
18 changes: 9 additions & 9 deletions gitweblite.conf.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
# Search directory
search_dirs => ['/git/pub', '/home'],
// Search directory
"search_dirs" : ["/git/pub", "/home"],

# Serach max depth
search_max_depth => 10,
// Serach max depth
"search_max_depth" : 10,

# Git command
git_bin => '/usr/local/bin/git',
// Git command
"git_bin" : "/usr/local/bin/git",

# Server config
hypnotoad => {
listen => ['http://*:10010']
// Server config
"hypnotoad" : {
"listen" : ["http://*:10010"]
}
}
9 changes: 6 additions & 3 deletions lib/Gitweblite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub startup {
my $self = shift;

# Config
my $conf = $self->plugin('Config');
my $conf = $self->plugin('JSONConfigLoose', {ext => 'conf'});
my $search_dirs = $conf->{search_dirs} || ['/git/pub', '/home'];
$self->config(search_dirs => $search_dirs);
my $search_max_depth = $conf->{search_max_depth} || 10;
Expand Down Expand Up @@ -105,10 +105,13 @@ sub startup {
->to('#blob', plain => 1)->name('blob_plain');

# Blob diff
$r->get('/blobdiff')->to('#blobdiff')->name('blobdiff');
$r->get('/blobdiff/(:diff)/(*file)',
[diff => qr/[a-zA-Z0-9]{40}\.\.[a-zA-Z0-9]{40}/])
->to('#blobdiff')->name('blobdiff');

# Blob diff plain
$r->get('/blobdiff_plain')
$r->get('/blobdiff_plain/(:diff)/(*file)',
[diff => qr/[a-zA-Z0-9]{40}\.\.[a-zA-Z0-9]{40}/])
->to('#blobdiff', plain => 1)->name('blobdiff_plain');

# Snapshot
Expand Down
21 changes: 21 additions & 0 deletions lib/Mojolicious/Plugin/JSONConfigLoose.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Mojolicious::Plugin::JSONConfigLoose;
use Mojo::Base 'Mojolicious::Plugin::JSONConfig';

sub load {
my ($self, $file, $conf, $app) = @_;
$app->log->debug(qq/Reading config file "$file"./);

# Slurp UTF-8 file
open my $handle, "<:encoding(UTF-8)", $file
or die qq/Couldn't open config file "$file": $!/;
my $content;
while (my $line = <$handle>) {
next if $line =~ m#^\s*//#;
$content .= $line;
}

# Process
return $self->parse($content, $file, $conf, $app);
}

1;
8 changes: 4 additions & 4 deletions templates/include/difftree.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
% } else {
<td class="link">
% }
<a href="<%= url_for('blobdiff',project => $project_ns)
->query(from_id => $from_id, id => $id, file => $file) %>">
<a href="<%= url_for('blobdiff',project => $project_ns,
diff => "$from_id..$id", file => $file) %>">
diff<%= $i + 1 %>
</a>
| </td>
Expand Down Expand Up @@ -157,8 +157,8 @@
</td>
<td class="link">
% if ($status ne 'A') {
<a href="<%= url_for('blobdiff', project => $project_ns)
->query(from_id => $from_id, id => $id, file => $file) %>">
<a href="<%= url_for('blobdiff', project => $project_ns,
diff => "$from_id..$id", file => $file) %>">
diff
</a>
|
Expand Down
4 changes: 2 additions & 2 deletions templates/main/blobdiff.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</div>
%= include '/include/page_navi', current => 'blobdiff', head_id => $id, project_ns => $project_ns;
<div class="page_nav">
<a href="<%= url_for('blobdiff_plain', project => $project_ns)
->query(from_id => $from_id, id => $id, file => $file) %>">
<a href="<%= url_for('blobdiff', project => $project_ns,
plain => 1, diff => "$from_id..$id", file => $file) %>">
Raw
</a>
|
Expand Down

0 comments on commit d879895

Please sign in to comment.