/[suikacvs]/test/html-webhacc/WebHACC/Output.pm
Suika

Diff of /test/html-webhacc/WebHACC/Output.pm

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

revision 1.9 by wakaba, Sun Jul 27 10:33:46 2008 UTC revision 1.11 by wakaba, Sun Aug 10 11:49:43 2008 UTC
# Line 16  my $htescape = sub ($) { Line 16  my $htescape = sub ($) {
16    return $s;    return $s;
17  };  };
18    
19    my $htescape_value = sub ($) {
20      my $s = $_[0];
21      $s =~ s/&/&/g;
22      $s =~ s/</&lt;/g;
23      $s =~ s/>/&gt;/g;
24      $s =~ s/"/&quot;/g;
25      return $s;
26    };
27    
28  sub new ($) {  sub new ($) {
29    require WebHACC::Input;    require WebHACC::Input;
30    return bless {nav => [], section_rank => 1,    return bless {nav => [], section_rank => 1,
# Line 75  sub url ($$%) { Line 84  sub url ($$%) {
84    
85  sub start_tag ($$%) {  sub start_tag ($$%) {
86    my ($self, $tag_name, %opt) = @_;    my ($self, $tag_name, %opt) = @_;
87    $self->html ('<' . $htescape->($tag_name)); # escape for safety    $self->html ('<' . $htescape_value->($tag_name)); # escape for safety
88    if (exists $opt{id}) {    if (exists $opt{id}) {
89      my $id = $self->input->id_prefix . $opt{id};      my $id = $self->input->id_prefix . $opt{id};
90      $self->html (' id="' . $htescape->($id) . '"');      $self->html (' id="' . $htescape_value->($id) . '"');
91      delete $opt{id};      delete $opt{id};
92    }    }
93    for (keys %opt) {    # for safety    for (keys %opt) {    # for safety
94      $self->html (' ' . $htescape->($_) . '="' . $htescape->($opt{$_}) . '"');      $self->html (' ' . $htescape_value->($_) . '="' .
95                     $htescape_value->($opt{$_}) . '"');
96    }    }
97    $self->html ('>');    $self->html ('>');
98  } # start_tag  } # start_tag
99    
100  sub end_tag ($$) {  sub end_tag ($$) {
101    shift->html ('</' . $htescape->(shift) . '>');    shift->html ('</' . $htescape_value->(shift) . '>');
102  } # end_tag  } # end_tag
103    
104  sub start_section ($%) {  sub start_section ($%) {
# Line 127  sub start_section ($%) { Line 137  sub start_section ($%) {
137    $self->html ('<div class=section');    $self->html ('<div class=section');
138    if (defined $opt{id}) {    if (defined $opt{id}) {
139      my $id = $self->input->id_prefix . $opt{id};      my $id = $self->input->id_prefix . $opt{id};
140      $self->html (' id="' . $htescape->($id) . '"');      $self->html (' id="' . $htescape->($id) . '">');
141      push @{$self->{nav}},      if ($self->{section_rank} == 2) {
142          [$id => $opt{short_title} || $opt{title} => $opt{text}]        my $st = $opt{short_title} || $opt{title};
143          if $self->{section_rank} == 2;        push @{$self->{nav}},
144              [$id => $st => $opt{text}];
145          
146          $self->start_tag ('script');
147          $self->html (qq[ addSectionLink ('] . $self->input->id_prefix .
148                         qq[$id', ']);
149          $self->nl_text ($st, text => $opt{text});
150          $self->html (q[') ]);
151          $self->end_tag ('script');
152        }
153      } else {
154        $self->html ('>');
155    }    }
156    my $section_rank = $self->{section_rank};    my $section_rank = $self->{section_rank};
157    $section_rank = 6 if $section_rank > 6;    $section_rank = 6 if $section_rank > 6;
158    $self->html ('><h' . $section_rank . '>');    $self->html ('<h' . $section_rank . '>');
159    $self->nl_text ($opt{title}, text => $opt{text});    $self->nl_text ($opt{title}, text => $opt{text});
160    $self->html ('</h' . $section_rank . '>');    $self->html ('</h' . $section_rank . '>');
161  } # start_section  } # start_section
# Line 296  my $get_node_path = sub ($) { Line 317  my $get_node_path = sub ($) {
317    return join '/', @r;    return join '/', @r;
318  }; # $get_node_path  }; # $get_node_path
319    
320    my $get_object_path = sub ($) {
321      my $node = shift;
322      my @r;
323      while (defined $node) {
324        my $ref = ref $node;
325        $ref =~ /([^:]+)$/;
326        my $rs = $1;
327        my $node_name = $node->node_name;
328        if (defined $node_name) {
329          $rs .= ' <code>' . $htescape->($node_name) . '</code>';
330        }
331        $node = undef;
332        unshift @r, $rs;
333      }
334      return join '/', @r;
335    }; # $get_object_path
336    
337  sub node_link ($$) {  sub node_link ($$) {
338    my ($self, $node) = @_;    my ($self, $node) = @_;
339    $self->xref ($get_node_path->($node), target => 'node-' . refaddr $node);    if ($node->isa ('Message::IF::Node')) {
340        $self->xref ($get_node_path->($node), target => 'node-' . refaddr $node);
341      } else {
342        $self->html ($get_object_path->($node));
343      }
344  } # node_link  } # node_link
345    
346  {  {
# Line 400  sub html_header ($) { Line 442  sub html_header ($) {
442  <link rel="stylesheet" href="../cc-style.css" type="text/css">  <link rel="stylesheet" href="../cc-style.css" type="text/css">
443  <script src="../cc-script.js"></script>  <script src="../cc-script.js"></script>
444  </head>  </head>
445  <body>  <body onclick=" return onbodyclick (event) " onload=" onbodyload () ">
446  <h1>]);  <h1>]);
447    $self->nl_text (q[WebHACC:Heading]);    $self->nl_text (q[WebHACC:Heading]);
448    $self->html ('</h1>');    $self->html (q[</h1><script> insertNavSections () </script>]);
449  } # html_header  } # html_header
450    
451  sub generate_input_section ($$) {  sub generate_input_section ($$) {
# Line 492  sub generate_input_section ($$) { Line 534  sub generate_input_section ($$) {
534    $out->start_section (id => 'input', title => 'Input');    $out->start_section (id => 'input', title => 'Input');
535    
536    $out->start_section (id => 'input-url', title => 'By URL');    $out->start_section (id => 'input-url', title => 'By URL');
537    $out->start_tag ('form', action => './', 'accept-charset' => 'utf-8',    $out->start_tag ('form', action => './#result-summary',
538                       'accept-charset' => 'utf-8',
539                     method => 'get');                     method => 'get');
540    $out->start_tag ('input', type => 'hidden', name => '_charset_');    $out->start_tag ('input', type => 'hidden', name => '_charset_');
541    
# Line 520  sub generate_input_section ($$) { Line 563  sub generate_input_section ($$) {
563    ## TODO: File upload    ## TODO: File upload
564    
565    $out->start_section (id => 'input-text', title => 'By direct input');    $out->start_section (id => 'input-text', title => 'By direct input');
566    $out->start_tag ('form', action => './', 'accept-charset' => 'utf-8',    $out->start_tag ('form', action => './#result-summary',
567                       'accept-charset' => 'utf-8',
568                     method => 'post');                     method => 'post');
569    $out->start_tag ('input', type => 'hidden', name => '_charset_');    $out->start_tag ('input', type => 'hidden', name => '_charset_');
570    
# Line 532  sub generate_input_section ($$) { Line 576  sub generate_input_section ($$) {
576    $out->start_tag ('textarea',    $out->start_tag ('textarea',
577                     name => 's');                     name => 's');
578    my $s = $cgi->get_parameter ('s');    my $s = $cgi->get_parameter ('s');
579    $out->text ($s) if defined $s;    $out->html ($htescape_value->($s)) if defined $s;
580    $out->end_tag ('textarea');    $out->end_tag ('textarea');
581    $out->end_tag ('label');    $out->end_tag ('label');
582    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.11

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24