13 |
# |
# |
14 |
# 04/26/09 21:12:28 CEST Dobrica Pavlinusic <dpavlin@rot13.org> |
# 04/26/09 21:12:28 CEST Dobrica Pavlinusic <dpavlin@rot13.org> |
15 |
|
|
16 |
my ( $database, $design ) = @ARGV; |
my ( $command, $database, $design ) = @ARGV; |
17 |
die "usage: $0 database design\n" unless $database && $design; |
die "usage: $0 [push|pull] database design\n" unless $database && $design; |
18 |
|
|
19 |
my $ua = LWP::UserAgent->new; |
my $ua = LWP::UserAgent->new; |
20 |
|
|
21 |
my $url = "http://llin.lan:5984/$database/_design/$design"; |
my $url = "http://llin.lan:5984/$database/_design/$design"; |
22 |
|
|
|
warn "# get $url\n"; |
|
|
my $response = $ua->get( $url ); |
|
|
|
|
|
die $response->status_line if $response->is_error; |
|
|
|
|
23 |
sub create_path { |
sub create_path { |
24 |
my $path = shift; |
my $path = shift; |
25 |
if ( $path =~ m{/} ) { |
if ( $path =~ m{/} ) { |
54 |
if ( $child eq '_attachments' ) { |
if ( $child eq '_attachments' ) { |
55 |
write_attachment $_ foreach keys %{ $tree->{$child} }; |
write_attachment $_ foreach keys %{ $tree->{$child} }; |
56 |
} else { |
} else { |
57 |
unroll( $tree->{$child}, "$path/$child" ); |
unroll( $tree->{$child}, $path ? "$path/$child" : $child ); |
58 |
} |
} |
59 |
} |
} |
60 |
} elsif ( $ref ) { |
} elsif ( $ref ) { |
62 |
write_file "$path.json", to_json $tree; |
write_file "$path.json", to_json $tree; |
63 |
} elsif ( $ref eq '' ) { |
} elsif ( $ref eq '' ) { |
64 |
|
|
65 |
if ( $tree =~ m[^\s*(function(.*){.*}|/\*|var)]is ) { |
if ( $tree =~ m[^\s*(function(.*){.*}|/\*|//|var)]is ) { |
66 |
$path .= '.js'; |
$path .= '.js'; |
67 |
} elsif ( $tree =~ m{<%=.*%>} ) { # couchapp template |
} elsif ( $tree =~ m{<%=.*%>} ) { # couchapp template |
68 |
$path .= '.html'; |
$path .= '.html'; |
69 |
} else { |
} else { |
70 |
warn "can't detect type of $path!"; |
warn "# can't detect type of $path\n"; |
71 |
} |
} |
72 |
|
|
73 |
write_file $path, $tree; |
write_file $path, $tree; |
75 |
|
|
76 |
} |
} |
77 |
|
|
78 |
my $json = $response->decoded_content; |
if ( $command eq 'pull' ) { |
79 |
write_file "../$database-$design.js", $json; |
|
80 |
|
warn "# get $url\n"; |
81 |
|
my $response = $ua->get( $url ); |
82 |
|
|
83 |
|
die $response->status_line if $response->is_error; |
84 |
|
|
85 |
|
my $json = $response->decoded_content; |
86 |
|
write_file "../$database-$design.js", $json; |
87 |
|
|
88 |
unroll( from_json $json, '' ); |
unroll( from_json $json, '' ); |
89 |
|
|
90 |
|
} elsif ( $command eq 'push' ) { |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
} else { |
95 |
|
die "$0: unknown command $command"; |
96 |
|
} |
97 |
|
|