/[suikacvs]/www/test/uri/data/test.cgi
Suika

Contents of /www/test/uri/data/test.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sun Jun 1 10:49:15 2008 UTC (17 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.1: +58 -4 lines
More data and tagging system

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     my $file_name = 'data-uris.txt';
5    
6     my @item;
7     {
8     open my $file, '<', $file_name;
9     local $/ = undef;
10     @item = split /\n\n#/, <$file>;
11     }
12    
13     sub htescape ($) {
14     my $s = shift;
15     $s =~ s/&/&amp;/g;
16     $s =~ s/</&lt;/g;
17     $s =~ s/"/&quot;/g;
18     return $s;
19     } # htescape
20    
21     sub get_id ($) {
22     my $s = shift;
23     $s =~ s/([^0-9A-Za-z-])/sprintf '_%08X', ord $1/ge;
24     return $s;
25     } # get_id
26    
27 wakaba 1.2 print q[Content-Type: text/html; charset=utf-8
28 wakaba 1.1
29     <!DOCTYPE HTML>
30     <html lang=en>
31     <title>data: URIs</title>
32     <style>
33     .note {
34    
35     }
36     .item {
37     margin: 1em;
38     padding: 0.2em 0.7em;
39     background-color: #F0F8FC;
40     color: black;
41     }
42 wakaba 1.2 [irrelevant] {
43     display: none;
44     }
45     </style>
46     <script>
47     window.onload = function () {
48     var anchors = document.getElementsByTagName ('a');
49     var anchorsL = anchors.length;
50     for (var i = 0; i < anchorsL; i++) {
51     var anchor = anchors[i];
52     if (!anchor.hasAttribute ('href')) {
53     anchor.setAttribute ('href', '#tag=' + encodeURIComponent (anchor.textContent));
54     anchor.onclick = function () {
55     showTag (this.textContent);
56     };
57     }
58     }
59    
60     var uri = location.href;
61     if (uri.match (/#/)) {
62     var hash = uri.substring (uri.indexOf ('#'));
63     if (hash.match (/^#tag=/)) {
64     showTag (decodeURIComponent (hash.substring (5)));
65     }
66     }
67     }; // window.onload
68    
69     function showTag (tag) {
70     var items = document.getElementsByTagName ('div');
71     var itemsL = items.length;
72     I: for (var i = 0; i < itemsL; i++) {
73     var item = items[i];
74     if (tag == '') {
75     item.removeAttribute ('irrelevant');
76     } else {
77     var itemAs = item.getElementsByTagName ('a');
78     var itemAsL = itemAs.length;
79     for (var j = 0; j < itemAsL; j++) {
80     if (itemAs[j].textContent == tag) {
81     item.removeAttribute ('irrelevant');
82     continue I;
83     }
84     }
85     item.setAttribute ('irrelevant', '');
86     }
87     }
88     }
89     </script><p><a href="#" onclick="showTag ('')">Show all</a></p>];
90 wakaba 1.1
91     for (@item) {
92     s/^#//;
93     my %prop;
94     for (split /\n#/, $_) {
95 wakaba 1.2 if (s/^([0-9A-Za-z-]+)(?>\n|\z)//s) {
96 wakaba 1.1 $prop{$1} = $_;
97     }
98     }
99    
100     my $id = htescape (get_id ($prop{data}));
101     my $euri = htescape ($prop{data});
102     print qq[<div class=item id=$id><p>URI: &lt;<a href="$euri">$euri</a>&gt;];
103 wakaba 1.2 for (qw/note conforming non-conforming source/) {
104 wakaba 1.1 next unless defined $prop{$_};
105     print qq[<p>];
106     print qq[<strong>Conforming</strong>: ] if $_ eq 'conforming';
107     print qq[<strong>Non-conforming</strong>: ] if $_ eq 'non-conforming';
108 wakaba 1.2 print qq[Source: ] if $_ eq 'source';
109 wakaba 1.1 my $v = htescape ($prop{$_});
110     $v =~ s[&lt;([^>]+)>][&lt;<a href="$1">$1</a>&gt;]g;
111     print qq[<span class=note>] . $v . qq[</span>];
112 wakaba 1.2 }
113    
114     if (defined $prop{tag}) {
115     my @tag = split /\n/, $prop{tag};
116     print q[<p class=tags>Tags: ];
117     print join ', ', map {'<a>' . htescape ($_) . '</a>'} @tag;
118 wakaba 1.1 }
119     print qq[</div>];
120     }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24