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

Contents of /test/html-webhacc/WebHACC/Language/Base.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Mon Jul 21 08:39:12 2008 UTC (16 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +1 -3 lines
++ ChangeLog	21 Jul 2008 08:33:17 -0000
	* cc.cgi (print_table_section): Removed (now part of
	WebHACC::Language::DOM).

2008-07-21  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/Language/ChangeLog	21 Jul 2008 08:39:05 -0000
	* Base.pm (generate_source_string_section): Invoke
	|add_source_to_parse_error_list| method for generating a
	script fragment.

	* CSS.pm, CacheManifest.pm, DOM.pm, HTML.pm, WebIDL.pm,
	XML.pm: Use new methods for generating sections and error lists.

	* DOM.pm (generate_additional_sections, generate_table_section): New.

	* Default.pm: Pass |input| in place of |url| for unknown syntax
	error.

2008-07-21  Wakaba  <wakaba@suika.fam.cx>

++ html/WebHACC/ChangeLog	21 Jul 2008 08:36:01 -0000
	* Output.pm (start_section, end_section): "role" option
	implemented.  Automatical rank setting implemented.
	(start_error_list, end_error_list): New.
	(add_source_to_parse_error_list): New.

	* Result.pm: "Unknown location" message text changed.

2008-07-21  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 package WebHACC::Language::Base;
2     use strict;
3    
4     sub new ($) {
5     die "$0: No constructor is defined for " . ref $_[0];
6     } # new
7    
8 wakaba 1.2 ## NOTE:
9     ## Language ->input, ->output, ->result
10     ## Input
11     ## Output ->input
12     ## Result ->output
13    
14 wakaba 1.1 sub input ($;$) {
15     if (@_ > 1) {
16     if (defined $_[1]) {
17     $_[0]->{input} = $_[1];
18     } else {
19     delete $_[0]->{input};
20     }
21     }
22    
23     return $_[0]->{input};
24     } # input
25    
26     sub output ($;$) {
27     if (@_ > 1) {
28     if (defined $_[1]) {
29     $_[0]->{output} = $_[1];
30     } else {
31     delete $_[0]->{output};
32     }
33     }
34    
35     return $_[0]->{output};
36     } # output
37    
38     sub result ($;$) {
39     if (@_ > 1) {
40     if (defined $_[1]) {
41     $_[0]->{result} = $_[1];
42     } else {
43     delete $_[0]->{result};
44     }
45     }
46    
47     return $_[0]->{result};
48     } # result
49    
50     sub onsubdoc ($;$) {
51     if (@_ > 1) {
52     if (defined $_[1]) {
53     $_[0]->{onsubdoc} = $_[1];
54     } else {
55     delete $_[0]->{onsubdoc};
56     }
57     }
58    
59     return $_[0]->{onsubdoc} || sub { };
60     } # onsubdoc
61    
62     sub generate_syntax_error_section ($) {
63 wakaba 1.2 die "$0: Syntactical checking for " . (ref $_[0]) . " is not supported";
64 wakaba 1.1 } # generate_syntax_error_section
65    
66     sub generate_structure_dump_section ($) {
67     #
68     } # generate_structure_dump_section
69    
70     sub generate_structure_error_section ($) {
71     my $self = shift;
72    
73     my $out = $self->output;
74    
75     $out->start_section (id => 'document-errors', title => 'Document Errors');
76     $out->html ('<p>Not supported for this kind of contents.');
77     ## TODO: class="???"
78     $out->end_section;
79     } # generate_structure_error_section
80    
81     sub source_charset ($) {
82     return 'utf-8';
83     } # source_charset
84    
85     sub generate_source_string_section ($) {
86     my $self = shift;
87     my $input = $self->input;
88    
89     my $s;
90     unless ($input->{is_char_string}) {
91     open my $byte_stream, '<', \($input->{s});
92     require Message::Charset::Info;
93     my $charset = Message::Charset::Info->get_by_iana_name
94     ($self->source_charset);
95     my ($char_stream, $e_status) = $charset->get_decode_handle
96     ($byte_stream, allow_error_reporting => 1, allow_fallback => 1);
97     return unless $char_stream;
98    
99     $char_stream->onerror (sub {
100     my (undef, $type, %opt) = @_;
101     if ($opt{octets}) {
102     ${$opt{octets}} = "\x{FFFD}";
103     }
104     });
105    
106     my $t = '';
107     while (1) {
108     my $c = $char_stream->getc;
109     last unless defined $c;
110     $t .= $c;
111     }
112     $s = \$t;
113     ## TODO: Output for each line, don't concat all of lines.
114     } else {
115     $s = \($input->{s});
116     }
117    
118     my $out = $self->output;
119     my $i = 1;
120     $out->start_section (id => 'source-string', title => 'Document Source',
121     short_title => 'Source');
122     $out->start_tag ('ol', lang => '');
123    
124     if (length $$s) {
125     while ($$s =~ /\G([^\x0D\x0A]*?)(?>\x0D\x0A?|\x0A)/gc) {
126     $out->start_tag ('li', id => 'line-' . $i);
127     $out->text ($1);
128     $i++;
129     }
130     if ($$s =~ /\G([^\x0D\x0A]+)/gc) {
131     $out->start_tag ('li', id => 'line-' . $i);
132     $out->text ($1);
133     }
134     } else {
135     $out->start_tag ('li', id => 'line-1');
136     }
137     $out->end_tag ('ol');
138 wakaba 1.4 $out->add_source_to_parse_error_list ('parse-errors-list');
139 wakaba 1.1 $out->end_section
140     } # generate_source_string_section
141    
142     sub generate_additional_sections ($) {
143     my $self = shift;
144     $self->generate_url_section;
145     } # generate_additional_sections
146    
147     sub generate_url_section ($) {
148     my $self = shift;
149     my $urls = $self->{add_info}->{uri} || {};
150     return unless keys %$urls;
151    
152     ## NOTE: URIs contained in the DOM (i.e. in HTML or XML documents),
153     ## except for those in RDF triples.
154     ## TODO: URIs in CSS
155    
156     my $out = $self->output;
157     $out->start_section (id => 'urls', title => 'URLs');
158     $out->start_tag ('dl');
159    
160     my $input = $self->input;
161     my $result = $self->result;
162    
163     for my $url (sort {$a cmp $b} keys %$urls) {
164     $out->start_tag ('dt');
165     $out->url ($url);
166     $out->start_tag ('dd');
167 wakaba 1.2 $out->link_to_webhacc ('Check conformance of this document', url => $url);
168 wakaba 1.1 $out->html ('<dd>Found in: <ul>');
169     for my $entry (@{$urls->{$url}}) {
170 wakaba 1.3 $out->start_tag ('li');
171     $out->node_link ($entry->{node});
172 wakaba 1.1 if (keys %{$entry->{type} or {}}) {
173     $out->text (' (');
174     $out->text (join ', ', map {
175     {
176     hyperlink => 'Hyperlink',
177     resource => 'Link to an external resource',
178     namespace => 'Namespace URI',
179     cite => 'Citation or link to a long description',
180     embedded => 'Link to an embedded content',
181     base => 'Base URI',
182     action => 'Submission URI',
183     }->{$_}
184     or
185     $_
186     } keys %{$entry->{type}});
187     $out->text (')');
188     }
189     }
190     $out->end_tag ('ul');
191     }
192     $out->end_tag ('dl');
193     $out->end_section;
194     } # generate_url_section
195    
196     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24