Changeset 27120 for lang/perl/Data-XMind
- Timestamp:
- 12/20/08 15:56:50 (4 years ago)
- Location:
- lang/perl/Data-XMind/trunk
- Files:
-
- 4 added
- 2 modified
-
eg/generate-xmind-from-text.pl (added)
-
lib/Data/XMind.pm (modified) (4 diffs)
-
lib/Data/XMind/Content.pm (modified) (2 diffs)
-
lib/Data/XMind/Sheet.pm (added)
-
t/10_simple.t (added)
-
t/TestDataXMind.pm (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Data-XMind/trunk/lib/Data/XMind.pm
r25900 r27120 9 9 use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); 10 10 11 use Data::XMind::Sheet; 11 12 use Data::XMind::Content; 12 13 use Data::XMind::Util qw(newid); … … 22 23 $self->{id} ||= newid; 23 24 24 my $content = Data::XMind::Content->new( 25 title => $self->{title}, 26 ); 27 $content->{parent} = $self; 28 29 $self->{depth} = 0; 30 $self->{content} = $content; 31 $self->{last_content} = $self->{content}; 32 $self->{parent} = undef; 25 unless ($self->{sheets}) { 26 $self->new_sheet; 27 } 33 28 34 29 $self; 35 30 } 36 31 37 sub title{32 sub new_sheet { 38 33 my $self = shift; 39 34 40 if (scalar(@_)) { 41 $self->{content}->{title} = shift; 35 my $sheet = Data::XMind::Sheet->new; 36 if ($_[0]) { 37 $sheet->title($_[0]); 42 38 } 43 39 44 $self->{content}->{title};40 push(@{ $self->{sheets} }, $sheet); 45 41 } 46 42 47 sub add {48 my $self = shift;49 my $opt = ref($_[0]) ? $_[0] : {@_};50 43 51 die unless defined($opt->{depth}) && $opt->{depth} > 0; 52 die unless defined($opt->{title}) && length($opt->{title}); 44 sub last_sheet { shift->{sheets}->[-1] }; 53 45 54 my $opt_depth = $opt->{depth}; 55 my $last_depth = $self->{last_content}->{depth}; 46 # proxy 47 sub title { shift->last_sheet->title(@_); } 48 sub add { shift->last_sheet->add(@_); } 49 sub add_note { shift->last_sheet->add_note(@_); } 56 50 57 die if ($opt_depth == 0);58 59 my $content = Data::XMind::Content->new(60 title => $opt->{title},61 );62 63 if ($opt_depth < $last_depth) {64 my $done = 0;65 my $last_content = $self->{last_content};66 my $parent;67 while ($parent = $last_content->{parent}) {68 if ($opt_depth == $parent->{depth}) {69 $self->{last_content} = $parent;70 $last_depth = $self->{last_content}->{depth};71 $done++;72 last;73 }74 $last_content = $parent;75 }76 die unless $done;77 }78 79 if ($opt_depth == $last_depth) {80 $self->{last_content} = $self->{last_content}->{parent}->add($content);81 }82 elsif ($opt_depth == ($last_depth + 1)) {83 $self->{last_content} = $self->{last_content}->add($content);84 }85 86 $self->{last_content};87 }88 89 sub add_note {90 my $self = shift;91 my $str = shift;92 93 my $content = $self->{last_content};94 $content->add_note($str);95 }96 51 97 52 my $template = << '__TMPL__'; 98 53 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 99 54 <xmap-content xmlns="urn:xmind:xmap:xmlns:content:2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" version="2.0"> 100 <sheet id="[% id %]"> 101 <title>[% title %]</title> 102 [%- content -%] 103 </sheet> 55 [% FOR sheet IN sheets %] 56 [% sheet %] 57 [% END %] 104 58 </xmap-content> 105 59 __TMPL__ … … 108 62 my $self = shift; 109 63 64 my @sheets; 65 for my $sheet (@{ $self->{sheets} }) { 66 push @sheets, $sheet->as_xml, 67 } 68 110 69 my $vars = { 111 id => $self->{id}, 112 title => $self->{title}, 113 content => $self->{content}->as_xml, 70 sheets => \@sheets, 114 71 }; 115 72 … … 140 97 unless ($zip->writeToFileNamed($name) == AZ_OK) { 141 98 die 'write error'; 99 } 100 } 101 102 sub _parse_private { 103 my ($self, $text) = @_; 104 105 my @lines = split(/\r?\n/, $text); 106 107 $self->title(shift(@lines)); 108 109 for my $line (@lines) { 110 if ($line =~ /^\#/) { 111 next; 112 } 113 elsif ($line =~ /^\%\s*(.*)$/) { 114 $self->new_sheet($1); 115 } 116 elsif ($line =~ /^(\*+)\s*(.*)$/) { 117 $self->add( 118 depth => length($1), 119 title => $2, 120 ); 121 } 122 elsif ($line =~ /^\!\s+([^=]+)=\"(.*?)\"$/) { 123 $self->{sheets}->[-1]->{last_content}->{attr}->{$1} = $2; 124 } 125 else { 126 $self->add_note($line); 127 } 142 128 } 143 129 } -
lang/perl/Data-XMind/trunk/lib/Data/XMind/Content.pm
r25898 r27120 54 54 55 55 my $template = << '__TMPL__'; 56 <topic id="[% id %]" >56 <topic id="[% id %]"[% attr %]> 57 57 <title>[% title %]</title> 58 58 … … 82 82 my $self = shift; 83 83 84 my $attr; 85 if (defined($self->{attr})) { 86 while (my ($key, $val) = each(%{ $self->{attr} })) { 87 $attr .= sprintf(q{ %s="%s"}, $key, $val); 88 } 89 } 90 84 91 my $vars = { 85 92 id => $self->{id}, 86 93 title => $self->{title}, 94 ($attr ? (attr => $attr) : ()), 87 95 (scalar(@{ $self->{notes} }) ? (notes => $self->{notes}) : ()), 88 96 };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)