/[socialtext-import]/tamtam/tamtam2socialtext.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /tamtam/tamtam2socialtext.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (hide annotations)
Wed Dec 12 12:12:21 2007 UTC (16 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 1593 byte(s)
beginning of wiki convertor for tamtam, less known but good
wiki written in python
1 dpavlin 5 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use XML::Simple;
7     use File::Find;
8     use Regexp::Common qw/balanced/;
9     use Socialtext::Resting;
10     use Encode;
11     use Data::Dump qw/dump/;
12    
13     my $page;
14    
15     find({
16     wanted => sub {
17     my $path = $File::Find::name;
18     return unless -f $path;
19     warn "# $path\n";
20     my $ref = XMLin( $path ) || die "can't open $path: $!";
21     $page->{ $ref->{name} } = $ref->{widgets}->{widget}->{data};
22     warn dump( $ref->{widgets}->{widget}->{data} );
23     },
24     }, shift @ARGV || '.');
25    
26    
27     warn "found following pages: ", join(", ", keys %$page),"\n";
28    
29     my $Rester = Socialtext::Resting->new(
30     username => 'tamtam',
31     password => 'import',
32     server => 'http://saturn.ffzg.hr/',
33     );
34     $Rester->workspace('razmjenavjestina');
35     $Rester->put_workspacetag('TamTam');
36    
37     sub header {
38     my $h = shift;
39     if ( $h =~ m/^(=+)\s+(.+?)\s+\1$/ ) {
40     my $level = length($1);
41     return "\n" . ( '^' x $level ) . " $2\n";
42     } else {
43     die "can't parse header: $h";
44     }
45     }
46    
47     sub surround {
48     my ( $with, $what ) = @_;
49     return $with . $what . $with;
50     }
51    
52     foreach my $name ( keys %$page ) {
53     my $body = $page->{$name} || die "no content for page $name";
54    
55     $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;
56     $body =~ s/\Q[[BR]]\E/\n/gs;
57     $body =~ s/$RE{balanced}{-begin => "= |== |=== |==== |===== |===== "}{-end => " =| ==| ===| ====| ====="}{-keep}/header($1)/gse;
58     $body =~ s/''''(.+?)''''/surround('`',$1)/gse;
59     $body =~ s/'''(.+?)'''/surround('*',$1)/gse;
60     $body =~ s/''(.+?)''/surround('_',$1)/gse;
61    
62     Encode::_utf8_off( $body );
63    
64     $Rester->put_page( $name, $body );
65     $Rester->put_pagetag( $name, 'TamTam' );
66    
67     print "+ $name\n";
68     }
69    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26