/[suikacvs]/test/html-webhacc/mkdescription.pl
Suika

Diff of /test/html-webhacc/mkdescription.pl

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

revision 1.2 by wakaba, Mon Jul 16 08:38:48 2007 UTC revision 1.6 by wakaba, Sat Aug 16 13:09:08 2008 UTC
# Line 3  use strict; Line 3  use strict;
3  use encoding 'us-ascii', STDOUT => 'utf-8';  use encoding 'us-ascii', STDOUT => 'utf-8';
4    
5  use lib qw[/home/httpd/html/www/markup/html/whatpm  use lib qw[/home/httpd/html/www/markup/html/whatpm
6             /home/wakaba/work/manakai/lib             /home/wakaba/work/manakai2/lib];
            /home/wakaba/public_html/-temp/wiki/lib];  
7    
8  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;  my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
9  my $SRC_NS = q<http://suika.fam.cx/~wakaba/archive/2007/wdcc-desc/>;  my $SRC_NS = q<http://suika.fam.cx/~wakaba/archive/2007/wdcc-desc/>;
# Line 24  my $doc; Line 23  my $doc;
23    $doc->manakai_is_html (1);    $doc->manakai_is_html (1);
24  }  }
25    
26  my $target_lang = 'en';  my $target_lang = shift || 'en';
27    
28  my @node = (@{$doc->child_nodes});  my @node = (@{$doc->child_nodes});
29  while (@node) {  while (@node) {
30    my $node = shift @node;    my $node = shift @node;
# Line 38  while (@node) { Line 38  while (@node) {
38          unshift @node, @{$node->child_nodes};          unshift @node, @{$node->child_nodes};
39        }        }
40      } elsif ($node->namespace_uri eq $SRC_NS) {      } elsif ($node->namespace_uri eq $SRC_NS) {
41        if ($node->manakai_local_name eq 'item') {        my $ln = $node->manakai_local_name;
42          if ($ln eq 'item' or $ln eq 'cat') {
43          my $message;          my $message;
44          my $desc;          my $desc;
45            my $text;
46          for (@{$node->child_nodes}) {          for (@{$node->child_nodes}) {
47            if ($_->node_type == $_->ELEMENT_NODE and            if ($_->node_type == $_->ELEMENT_NODE and
48                $_->namespace_uri eq $SRC_NS) {                $_->namespace_uri eq $SRC_NS) {
# Line 58  while (@node) { Line 60  while (@node) {
60                } else {                } else {
61                  $message ||= $_;                  $message ||= $_;
62                }                }
63                } elsif ($_->manakai_local_name eq 'text') {
64                  if ($_->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
65                    $text = $_;
66                    next;
67                  } else {
68                    $text ||= $_;
69                  }
70              }              }
71            }            }
72          }          }
73    
74          my $name = $node->get_attribute_ns (undef, 'name');          if ($ln eq 'item' or $desc) {
75          $name =~ tr/ /-/;            my $name = $node->get_attribute_ns (undef, 'name');
76          my $level = $node->get_attribute_ns (undef, 'level');            $name =~ tr/ /-/;
77          $name = $level . ':' . $name if defined $level;            
78          my $section = $doc->create_element_ns ($HTML_NS, 'div');            my $section = $doc->create_element_ns ($HTML_NS, 'div');
79          $section->set_attribute_ns            $section->set_attribute_ns (undef, class => 'section');
80              (undef, class => 'section ' .            $section->set_attribute_ns (undef, id => $name);
81                   $node->get_attribute_ns (undef, 'class'));            
82          $section->set_attribute_ns (undef, id => $name);            my $msg = $section->append_child
83                  ($doc->create_element_ns ($HTML_NS, 'h3'));
84          my @message_child = @{$message->child_nodes};            if ($ln eq 'item' and $message) {
85          my $msg = $section->append_child              my @message_child = @{$message->child_nodes};
86              ($doc->create_element_ns ($HTML_NS, 'h3'));              $msg->append_child ($_) for @message_child;
87          $msg->append_child ($_) for @message_child;            } elsif ($ln eq 'cat' and $text) {
88                $msg->append_child ($_) for @{$text->child_nodes};
89          if ($desc) {            }
90            my @desc_child = @{$desc->child_nodes};            
91            $section->append_child ($_) for @desc_child;            if ($desc) {
92                my @desc_child = @{$desc->child_nodes};
93                $section->append_child ($_) for @desc_child;
94              }
95              
96              $node->parent_node->insert_before ($section, $node);
97          }          }
98            $node->parent_node->remove_child ($node);
         $node->parent_node->insert_before ($section, $node);  
         $node->parent_node->remove_child ($node); ## TODO: replace_child is not yet implemented  
       } elsif ($node->manakai_local_name eq 'catalog') {  
         #  
99        } else {        } else {
100          warn "$0: ", $node->manakai_local_name, " is not supported\n";          warn "$0: ", $node->manakai_local_name, " is not supported\n";
101        }        }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24