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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Mon Jul 16 10:55:11 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +1 -1 lines
File MIME type: text/plain
++ ChangeLog	16 Jul 2007 10:55:08 -0000
	* cc.cgi (table stuff): Set |is_header| property
	of table cells explicitly since otherwise newer JSON.pm
	generates broken output.
	(get_text): Return the reduced type name as well.  Use
	it as fragment of detail document.

	* error-description-source.xml: More error descriptions
	are added.

	* mkdescription.pl: Remove |catalog| element from
	the result description document.

	* table.cgi: Set |is_header| property
        of table cells explicitly since otherwise newer JSON.pm
        generates broken output.

2007-07-16  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use encoding 'us-ascii', STDOUT => 'utf-8';
4    
5     use lib qw[/home/httpd/html/www/markup/html/whatpm
6     /home/wakaba/work/manakai/lib
7     /home/wakaba/public_html/-temp/wiki/lib];
8    
9     my $HTML_NS = q<http://www.w3.org/1999/xhtml>;
10     my $SRC_NS = q<http://suika.fam.cx/~wakaba/archive/2007/wdcc-desc/>;
11     my $XML_NS = q<http://www.w3.org/XML/1998/namespace>;
12    
13     require Message::DOM::DOMImplementation;
14 wakaba 1.2 my $dom = Message::DOM::DOMImplementation->new;
15 wakaba 1.1
16     my $doc;
17     {
18     my $source_file_name = shift or die "$0: No source file specified\n";
19     open my $source_file, '<', $source_file_name
20     or die "$0: $source_file_name: $!";
21     require Message::DOM::XMLParserTemp;
22     $doc = Message::DOM::XMLParserTemp->parse_byte_stream
23     ($source_file => $dom, undef, charset => 'utf-8');
24 wakaba 1.2 $doc->manakai_is_html (1);
25 wakaba 1.1 }
26    
27     my $target_lang = 'en';
28     my @node = (@{$doc->child_nodes});
29     while (@node) {
30     my $node = shift @node;
31     if ($node->node_type == $node->ELEMENT_NODE) {
32     if ($node->namespace_uri eq $HTML_NS) {
33     if ($node->manakai_local_name eq 'title') {
34     unless ($node->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
35     $node->parent_node->remove_child ($node);
36     }
37     } else {
38 wakaba 1.2 unshift @node, @{$node->child_nodes};
39 wakaba 1.1 }
40     } elsif ($node->namespace_uri eq $SRC_NS) {
41     if ($node->manakai_local_name eq 'item') {
42     my $message;
43     my $desc;
44     for (@{$node->child_nodes}) {
45     if ($_->node_type == $_->ELEMENT_NODE and
46     $_->namespace_uri eq $SRC_NS) {
47     if ($_->manakai_local_name eq 'desc') {
48     if ($_->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
49     $desc = $_;
50     next;
51     } else {
52     $desc ||= $_;
53     }
54     } elsif ($_->manakai_local_name eq 'message') {
55     if ($_->get_attribute_ns ($XML_NS, 'lang') eq $target_lang) {
56     $message = $_;
57     next;
58     } else {
59     $message ||= $_;
60     }
61     }
62     }
63     }
64    
65     my $name = $node->get_attribute_ns (undef, 'name');
66     $name =~ tr/ /-/;
67 wakaba 1.2 my $level = $node->get_attribute_ns (undef, 'level');
68     $name = $level . ':' . $name if defined $level;
69 wakaba 1.1 my $section = $doc->create_element_ns ($HTML_NS, 'div');
70     $section->set_attribute_ns
71     (undef, class => 'section ' .
72     $node->get_attribute_ns (undef, 'class'));
73     $section->set_attribute_ns (undef, id => $name);
74    
75     my @message_child = @{$message->child_nodes};
76     my $msg = $section->append_child
77     ($doc->create_element_ns ($HTML_NS, 'h3'));
78     $msg->append_child ($_) for @message_child;
79    
80 wakaba 1.2 if ($desc) {
81     my @desc_child = @{$desc->child_nodes};
82     $section->append_child ($_) for @desc_child;
83     }
84 wakaba 1.1
85     $node->parent_node->insert_before ($section, $node);
86     $node->parent_node->remove_child ($node); ## TODO: replace_child is not yet implemented
87 wakaba 1.2 } elsif ($node->manakai_local_name eq 'catalog') {
88 wakaba 1.3 $node->parent_node->remove_child ($node);
89 wakaba 1.1 } else {
90     warn "$0: ", $node->manakai_local_name, " is not supported\n";
91     }
92     }
93     }
94     }
95     $doc->document_element->set_attribute_ns (undef, lang => $target_lang);
96    
97 wakaba 1.2 print $doc->inner_html;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24