/[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.13 by wakaba, Thu Aug 14 09:16:52 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 ($%) {
105    my ($self, %opt) = @_;    my ($self, %opt) = @_;
106    
107      my $class = 'section';
108    if (defined $opt{role}) {    if (defined $opt{role}) {
109      if ($opt{role} eq 'parse-errors') {      if ($opt{role} eq 'parse-errors') {
110        $opt{id} ||= 'parse-errors';        $opt{id} ||= 'parse-errors';
# Line 120  sub start_section ($%) { Line 131  sub start_section ($%) {
131        $opt{title} ||= 'Document Structure';        $opt{title} ||= 'Document Structure';
132        $opt{short_title} ||= 'Structure';        $opt{short_title} ||= 'Structure';
133        delete $opt{role};        delete $opt{role};
134        } elsif ($opt{role} eq 'subdoc') {
135          $class .= ' subdoc';
136          delete $opt{role};
137      }      }
138    }    }
139    
140    $self->{section_rank}++;    $self->{section_rank}++;
141    $self->html ('<div class=section');    $self->html (qq[<div class="$class"]);
142    if (defined $opt{id}) {    if (defined $opt{id}) {
143      my $id = $self->input->id_prefix . $opt{id};      my $prefix = $self->input->id_prefix;
144      $self->html (' id="' . $htescape->($id) . '"');      $opt{parent_id} ||= $prefix;
145      push @{$self->{nav}},      my $id = $prefix . $opt{id};
146          [$id => $opt{short_title} || $opt{title} => $opt{text}]      $self->html (' id="' . $htescape->($id) . '">');
147          if $self->{section_rank} == 2;      if ($self->{section_rank} == 2 or length $opt{parent_id}) {
148          my $st = $opt{short_title} || $opt{title};
149          push @{$self->{nav}},
150              [$id => $st => $opt{text}];
151          
152          $self->start_tag ('script');
153          $self->html (qq[ addSectionLink ('$id', ']);
154          $self->nl_text ($st, text => $opt{text});
155          if (defined $opt{parent_id}) {
156            $self->html (q[', '] . $opt{parent_id});
157          }
158          $self->html (q[') ]);
159          $self->end_tag ('script');
160        }
161      } else {
162        $self->html ('>');
163    }    }
164    my $section_rank = $self->{section_rank};    my $section_rank = $self->{section_rank};
165    $section_rank = 6 if $section_rank > 6;    $section_rank = 6 if $section_rank > 6;
166    $self->html ('><h' . $section_rank . '>');    $self->html ('<h' . $section_rank . '>');
167    $self->nl_text ($opt{title}, text => $opt{text});    $self->nl_text ($opt{title}, text => $opt{text});
168    $self->html ('</h' . $section_rank . '>');    $self->html ('</h' . $section_rank . '>');
169  } # start_section  } # start_section
# Line 296  my $get_node_path = sub ($) { Line 325  my $get_node_path = sub ($) {
325    return join '/', @r;    return join '/', @r;
326  }; # $get_node_path  }; # $get_node_path
327    
328    my $get_object_path = sub ($) {
329      my $node = shift;
330      my @r;
331      while (defined $node) {
332        my $ref = ref $node;
333        $ref =~ /([^:]+)$/;
334        my $rs = $1;
335        my $node_name = $node->node_name;
336        if (defined $node_name) {
337          $rs .= ' <code>' . $htescape->($node_name) . '</code>';
338        }
339        $node = undef;
340        unshift @r, $rs;
341      }
342      return join '/', @r;
343    }; # $get_object_path
344    
345  sub node_link ($$) {  sub node_link ($$) {
346    my ($self, $node) = @_;    my ($self, $node) = @_;
347    $self->xref ($get_node_path->($node), target => 'node-' . refaddr $node);    if ($node->isa ('Message::IF::Node')) {
348        $self->xref ($get_node_path->($node), target => 'node-' . refaddr $node);
349      } else {
350        $self->html ($get_object_path->($node));
351      }
352  } # node_link  } # node_link
353    
354  {  {
# Line 400  sub html_header ($) { Line 450  sub html_header ($) {
450  <link rel="stylesheet" href="../cc-style.css" type="text/css">  <link rel="stylesheet" href="../cc-style.css" type="text/css">
451  <script src="../cc-script.js"></script>  <script src="../cc-script.js"></script>
452  </head>  </head>
453  <body>  <body onclick=" return onbodyclick (event) " onload=" onbodyload () ">
454  <h1>]);  <h1>]);
455    $self->nl_text (q[WebHACC:Heading]);    $self->nl_text (q[WebHACC:Heading]);
456    $self->html ('</h1>');    $self->html (q[</h1><script> insertNavSections () </script>]);
457  } # html_header  } # html_header
458    
459  sub generate_input_section ($$) {  sub generate_input_section ($$) {
# Line 412  sub generate_input_section ($$) { Line 462  sub generate_input_section ($$) {
462    my $options = sub ($) {    my $options = sub ($) {
463      my $context = shift;      my $context = shift;
464    
465      $out->html (q[<div class=details><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'none' ? 'block' : 'none'">]);      $out->html (q[<div class="details default"><p class=legend onclick="nextSibling.style.display = nextSibling.style.display == 'block' ? 'none' : 'block'; parentNode.className = nextSibling.style.display == 'none' ? 'details' : 'details open'">]);
466      $out->nl_text (q[Options]);      $out->nl_text (q[Options]);
467      $out->start_tag ('div');      $out->start_tag ('div');
468    
# Line 490  sub generate_input_section ($$) { Line 540  sub generate_input_section ($$) {
540    }; # $options    }; # $options
541    
542    $out->start_section (id => 'input', title => 'Input');    $out->start_section (id => 'input', title => 'Input');
543      $out->html (q[<script> insertNavSections ('input') </script>]);
544    
545    $out->start_section (id => 'input-url', title => 'By URL');    $out->start_section (id => 'input-url', title => 'By URL',
546    $out->start_tag ('form', action => './', 'accept-charset' => 'utf-8',                         parent_id => 'input');
547      $out->start_tag ('form', action => './#result-summary',
548                       'accept-charset' => 'utf-8',
549                     method => 'get');                     method => 'get');
550    $out->start_tag ('input', type => 'hidden', name => '_charset_');    $out->start_tag ('input', type => 'hidden', name => '_charset_');
551    
# Line 506  sub generate_input_section ($$) { Line 559  sub generate_input_section ($$) {
559                     value => $cgi->get_parameter ('uri'));                     value => $cgi->get_parameter ('uri'));
560    $out->end_tag ('label');    $out->end_tag ('label');
561    
   $options->('url');  
   
562    $out->start_tag ('p');    $out->start_tag ('p');
563    $out->start_tag ('button', type => 'submit');    $out->start_tag ('button', type => 'submit');
564    $out->nl_text ('Check');    $out->nl_text ('Check');
565      $out->end_tag ('button');
566    
567      $options->('url');
568    
569    $out->end_tag ('form');    $out->end_tag ('form');
570    $out->end_section;    $out->end_section;
# Line 519  sub generate_input_section ($$) { Line 573  sub generate_input_section ($$) {
573    
574    ## TODO: File upload    ## TODO: File upload
575    
576    $out->start_section (id => 'input-text', title => 'By direct input');    $out->start_section (id => 'input-text', title => 'By direct input',
577    $out->start_tag ('form', action => './', 'accept-charset' => 'utf-8',                         parent_id => 'input');
578      $out->start_tag ('form', action => './#result-summary',
579                       'accept-charset' => 'utf-8',
580                     method => 'post');                     method => 'post');
581    $out->start_tag ('input', type => 'hidden', name => '_charset_');    $out->start_tag ('input', type => 'hidden', name => '_charset_');
582    
# Line 532  sub generate_input_section ($$) { Line 588  sub generate_input_section ($$) {
588    $out->start_tag ('textarea',    $out->start_tag ('textarea',
589                     name => 's');                     name => 's');
590    my $s = $cgi->get_parameter ('s');    my $s = $cgi->get_parameter ('s');
591    $out->text ($s) if defined $s;    $out->html ($htescape_value->($s)) if defined $s;
592    $out->end_tag ('textarea');    $out->end_tag ('textarea');
593    $out->end_tag ('label');    $out->end_tag ('label');
594    
   $options->('text');  
   
595    $out->start_tag ('p');    $out->start_tag ('p');
596    $out->start_tag ('button', type => 'submit',    $out->start_tag ('button', type => 'submit',
597                     onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"');                     onclick => 'form.method = form.s.value.length > 512 ? "post" : "get"');
598    $out->nl_text ('Check');    $out->nl_text ('Check');
599    $out->end_tag ('button');    $out->end_tag ('button');
600    
601      $options->('text');
602    
603    $out->end_tag ('form');    $out->end_tag ('form');
604    $out->end_section;    $out->end_section;
605    
606      $out->script (q[
607        if (!document.webhaccNavigated &&
608            document.getElementsByTagName ('textarea')[0].value.length > 0) {
609          showTab ('input-text');
610          document.webhaccNavigated = false;
611        }
612      ]);
613    
614    $out->end_section;    $out->end_section;
615  } # generate_input_section  } # generate_input_section
616    

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24