/[pub]/suikawiki/script/bin/mkplugin2.pl
Suika

Diff of /suikawiki/script/bin/mkplugin2.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by wakaba, Tue Nov 25 12:47:19 2003 UTC revision 1.8 by wakaba, Mon Dec 1 07:46:42 2003 UTC
# Line 75  sub quoted_string ($) { Line 75  sub quoted_string ($) {
75    $s =~ s/([\\"])/\\$1/g;    $s =~ s/([\\"])/\\$1/g;
76    '"'.$s.'"';    '"'.$s.'"';
77  }  }
78    sub line ($;%) {
79      my ($Info, %opt) = @_;
80      
81      unless ($opt{file}) {
82        if ($opt{reset}) {
83          $opt{file} = sprintf '(WikiPlugin module %s, chunk %d)',
84                               $Info->{Name},
85                               ++$Info->{chunk_count};
86        } elsif ($opt{realfile}) {
87          $opt{file} = sprintf '(WikiPlugin module %s, chunk from %s)',
88                               $Info->{Name},
89                               $opt{realfile};
90        } else {
91          $opt{file} = sprintf '(WikiPlugin module source %s, block %s)',
92                               $Info->{source_file},
93                               $opt{node_path};
94        }
95      }
96      
97      $opt{file} =~ s/"/''/g;
98      sprintf '%s#line %d "%s"%s', "\n", $opt{line_no} || 1, $opt{file}, "\n";
99    }
100    
101  my $parser = Message::Markup::SuikaWikiConfig20::Parser->new;  my $parser = Message::Markup::SuikaWikiConfig20::Parser->new;
102  my $plugins = $parser->parse_text ($src);  my $plugins = $parser->parse_text ($src);
# Line 82  my $meta = $plugins->get_attribute ('Plu Line 104  my $meta = $plugins->get_attribute ('Plu
104            or die "$0: Required 'Plugin' section not found";            or die "$0: Required 'Plugin' section not found";
105  my %Info = (provide => {},  my %Info = (provide => {},
106              Name => n11n $meta->get_attribute ('Name')->value);              Name => n11n $meta->get_attribute ('Name')->value);
107    $Info{source_file} = $srcfile;
108  $Info{name_literal} = literal $Info{Name};  $Info{name_literal} = literal $Info{Name};
109  my @date = gmtime;  my @date = gmtime;
110  $Info{LastModified} = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00',  $Info{LastModified} = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00',
# Line 133  print qq{\$Info{$Info{name_literal}}->{A Line 156  print qq{\$Info{$Info{name_literal}}->{A
156  my $use = $meta->get_attribute ('Use');  my $use = $meta->get_attribute ('Use');
157  if (ref $use) {  if (ref $use) {
158    print change_package \%Info, $Info{module_name};    print change_package \%Info, $Info{module_name};
159    print $use->inner_text;    print line \%Info, node_path => 'Plugin/Use';
160      print $use->inner_text, "\n";
161      print line \%Info, reset => 1;
162  }  }
163    
164  for (@{$plugins->child_nodes}) {  for (@{$plugins->child_nodes}) {
# Line 181  sub make_format ($$) { Line 206  sub make_format ($$) {
206      $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n};      $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n};
207    }    }
208        
209    $r .= <<'EOH';    my $convert = line $Info, line_no => __LINE__ + 2, realfile => __FILE__;
210      $convert .= <<'EOH';
211  our $Converter;  our $Converter;
212  sub convert ($$;%) {  sub convert ($$;%) {
213    my ($self, $source, %opt) = @_;    my ($self, $source, %opt) = @_;
# Line 201  EOH Line 227  EOH
227        
228    for (@{$src->child_nodes}) {    for (@{$src->child_nodes}) {
229      if ($_->local_name eq 'Converter') {      if ($_->local_name eq 'Converter') {
230          if ($convert) {
231            $r .= $convert;
232            $r .= line $Info, reset => 1;
233            undef $convert;
234          }
235        $r .= make_format_converter ($_, $Info);        $r .= make_format_converter ($_, $Info);
236      } elsif ($_->local_name eq 'Use') {      } elsif ($_->local_name eq 'Use') {
237          $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use);
238        $r .= $_->inner_text;        $r .= $_->inner_text;
239      }      }
240    }    }
     
241    $r;    $r;
242  }  }
243    
# Line 237  sub make_format_converter ($$) { Line 268  sub make_format_converter ($$) {
268      if $src->get_attribute_value ('IsPlaceholder');      if $src->get_attribute_value ('IsPlaceholder');
269        
270    $def{Main} = $src->get_attribute_value ('Main');    $def{Main} = $src->get_attribute_value ('Main');
271    $def{Main} = 'my $r;'.$def{Main}.'$r' if $def{Main} =~ /\$r\b/;    $def{Main} = line ($Info, node_path => '//Converter/Main')
272                 . $def{Main}
273                 . line ($Info, reset => 1);
274      if ($def{Main} =~ /\$r\b/) {
275        $def{Main} = 'my $r;'."\n".$def{Main}."\n".'$r';
276      }
277    $def{Main} = barecode code $Info,    $def{Main} = barecode code $Info,
278                 'sub {my ($self, $source, $opt) = @_;'                 'sub {my ($self, $source, $opt) = @_;'
279               . $def{Main} . '}';               . $def{Main} . '}';
# Line 257  sub make_format_converter ($$) { Line 293  sub make_format_converter ($$) {
293  sub make_function ($$) {  sub make_function ($$) {
294    my ($src, $Info) = @_;    my ($src, $Info) = @_;
295    ## TODO: support of ARGV property    ## TODO: support of ARGV property
296      my $name;
297    my $r = <<EOH;    my $r = <<EOH;
298  @{[change_package $Info, $Info->{module_name}]}  @{[change_package $Info, $Info->{module_name}]}
299  sub @{[$src->get_attribute_value ('Name')]} {  sub @{[$name = $src->get_attribute_value ('Name')]} {
300    @{[code $Info, $src->get_attribute_value ('Main')]}  @{[line $Info, node_path => "Function[Name='$name']/Main"]}@{[
301      code $Info, $src->get_attribute_value ('Main')
302    ]}@{[line $Info, reset => 1]}
303  }  }
304  EOH  EOH
305  }  }
# Line 321  sub make_viewdef ($$) { Line 360  sub make_viewdef ($$) {
360    my ($src, $Info) = @_;    my ($src, $Info) = @_;
361    my $ViewProp = {};    my $ViewProp = {};
362    my $r = '';    my $r = '';
363    $ViewProp->{Name} = n11n $src->get_attribute ('Mode')->value;    $ViewProp->{Name} = n11n $src->get_attribute_value ('Mode');
364    $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name});    $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name});
365        
366    $ViewProp->{condition_stringified} = hash    $ViewProp->{condition_stringified} = hash
# Line 339  our \@ISA = q#SuikaWiki::View::template# Line 378  our \@ISA = q#SuikaWiki::View::template#
378  EOH  EOH
379    for (@{$src->child_nodes}) {    for (@{$src->child_nodes}) {
380      if ($_->local_name eq 'template') {      if ($_->local_name eq 'template') {
381        $r .= make_view_template_method ($_, $Info);        $r .= make_view_template_method ($_, $Info, $ViewProp);
382      } elsif ($_->local_name eq 'method') {      } elsif ($_->local_name eq 'method') {
383          my $method_name = $_->get_attribute_value ('Name');
384        $r .= ({        $r .= ({
385                main => q(sub main ($$) {)."\n".q(my ($self, $opt) = @_;)."\n",                main => q(sub main ($$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",
386                main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",                main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",
387                main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",                                    main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",                    
388               }->{$_->get_attribute ('Name')->value}               }->{$method_name}
389               ||qq(sub @{[$_->get_attribute ('Name')->value]} {\n))               ||qq(sub @{[$method_name]} {\n))
390             . line ($Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/method[Name='$method_name']")
391           . code ($Info, $_->value)           . code ($Info, $_->value)
392           . qq(\n}\n);           . line ($Info, reset => 1)
393             . qq(}\n);
394      }      }
395    }    }
396    my $prop = {Name => $ViewProp->{Name},    my $prop = {Name => $ViewProp->{Name},
# Line 358  EOH Line 400  EOH
400  }  }
401    
402  sub make_view_template_method ($$) {  sub make_view_template_method ($$) {
403    my ($src, $info) = @_;    my ($src, $Info, $ViewProp) = @_;
404    my $r = <<EOH;    my $r = <<EOH;
405    
406  sub main (\$\$\$) {  sub main (\$\$\$) {
# Line 377  sub main (\$\$\$) { Line 419  sub main (\$\$\$) {
419                       ## Compatible options for SuikaWiki 2 WikiPlugin interface                       ## Compatible options for SuikaWiki 2 WikiPlugin interface
420                         param => \\\%main::form,                         param => \\\%main::form,
421                         page => \$main::form{mypage},                         page => \$main::form{mypage},
422                         toc => [],                         #toc => [],
423                         #magic                         #magic
424                         #content                         #content
425                         #use_anchor_name                         #use_anchor_name
# Line 398  sub main (\$\$\$) { Line 440  sub main (\$\$\$) {
440    @{[do{my $x=$src->get_attribute('http-status-code',make_new_node=>1)->inner_text;    @{[do{my $x=$src->get_attribute('http-status-code',make_new_node=>1)->inner_text;
441       $x?q{$opt2->{output}->{status_code} = }.(0 + $x).q{;}:q{}}]}       $x?q{$opt2->{output}->{status_code} = }.(0 + $x).q{;}:q{}}]}
442    @{[do{my $x=$src->get_attribute('http-status-phrase',make_new_node=>1)->inner_text;    @{[do{my $x=$src->get_attribute('http-status-phrase',make_new_node=>1)->inner_text;
443       $x?q{$opt2->{output}->{reason_phrase} = }.literal($x).q{;}:q{}}]}       $x?q{$opt2->{output}->{status_phrase} = }.literal($x).q{;}:q{}}]}
444    \$opt2->{output}->{entity}->{media_type} = @{[literal    \$opt2->{output}->{entity}->{media_type} = @{[literal
445                             $src->get_attribute ('media-type',make_new_node=>1)                             $src->get_attribute ('media-type',make_new_node=>1)
446                                 ->inner_text || 'application/octet-stream']};                                 ->inner_text || 'application/octet-stream']};
# Line 417  sub main (\$\$\$) { Line 459  sub main (\$\$\$) {
459    \$self->{view}->{wiki}->init_db;    \$self->{view}->{wiki}->init_db;
460    \$self->main_pre (\$opt, \$opt2);    \$self->main_pre (\$opt, \$opt2);
461        
462    my \$fmt = SuikaWiki::Plugin->formatter ('view');    use Message::Util::Error;
463    \$opt2->{output}->{entity}->{body}    try {
464      = \$fmt->replace (\$opt2->{template}, param => \$opt2->{o});      \$opt2->{output}->{entity}->{body}
465          = SuikaWiki::Plugin->formatter ('view')
466            ->replace (\$opt2->{template}, param => \$opt2->{o});
467      } \$self->{view}->{wiki}->{config}->{catch}->{ @{[
468           $ViewProp->{Name} eq '-error' ? 'formatter_view_error'
469                                         : 'formatter_view' ]} };
470    \$opt2->{output}->output (output => 'http-cgi');    \$opt2->{output}->output (output => 'http-cgi');
471        
472    \$self->main_post (\$opt, \$opt2);    \$self->main_post (\$opt, \$opt2);
# Line 432  sub make_rule ($$) { Line 479  sub make_rule ($$) {
479    my $type = $src->get_attribute ('Category', make_new_node => 1)->value || [];    my $type = $src->get_attribute ('Category', make_new_node => 1)->value || [];
480    my $name = $src->get_attribute ('Name', make_new_node => 1)->value;    my $name = $src->get_attribute ('Name', make_new_node => 1)->value;
481    $name =~ s/(?<=.)-/_/g;    $name =~ s/(?<=.)-/_/g;
482    my $main = code $Info, $src->get_attribute_value ('Formatting');    my $main = line ($Info, node_path => "FormattingRule[name()='@{[list $type]}/$name']/Formatting")
483               . code ($Info, $src->get_attribute_value ('Formatting'))
484               . line ($Info, reset => 1);
485        
486    my $reg_block;    my $reg_block;
487    $reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/;    $reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.8

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24