Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 100 lines (87 sloc) 2.965 kB
cfdbe94 @tene [Tags]
tene authored
1 use v6;
2
3 module Tags::EXPORT::DEFAULT { }
4
5 module Tags {
6 our @frames;
7
4985e64 @masak [Tags] removed 'map' from exports list
authored
8 # XXX: The below list used to contain 'map', but I removed it because it
9 # screwed up code elsewhere. -- masak
10
f54cc4b @tene Ad a list of tags to not collapse to <tag/> when empty.
tene authored
11 my @nocollapse = <textarea>;
cfdbe94 @tene [Tags]
tene authored
12 # Hide it in a sub to work around a bug
13 sub _setup {
14 for <
15 h1 h2 h3 h4 h5 h6 p br hr ol ul li dl dt dd menu code var strong em tt
16 u i b blockquote pre img a address cite samp dfn html head base body
17 link nextid title meta kbd start_html end_html input select option
18 comment charset escapehtml div table caption th td tr tr sup sub
19 strike applet param nobr embed basefont style span layer ilayer font
4985e64 @masak [Tags] removed 'map' from exports list
authored
20 frameset frame script small big area abbr acronym bdo col colgroup
cfdbe94 @tene [Tags]
tene authored
21 del fieldset iframe ins label legend noframes noscript object optgroup
22 q thead tbody tfoot blink fontsize center textfield textarea filefield
23 password_field hidden checkbox checkbox_group submit reset defaults
24 radio_group popup_menu button autoescape scrolling_list image_button
25 start_form end_form startform endform start_multipart_form
26 end_multipart_form isindex tmpfilename uploadinfo url_encoded
27 multipart form canvas
28 > -> $tag {
e8d3f5e @tene [Tags]
tene authored
29 ::Tags{$tag} = sub ($c?, *%attrs) {
30 _tag($tag, $c, :attrs{%attrs});
cfdbe94 @tene [Tags]
tene authored
31 }
32 ::Tags::EXPORT::DEFAULT{$tag} = ::Tags{$tag};
33 }
34 }
35 _setup();
36
1693bdc @tene Minor update to tags to help with foreign languages.
tene authored
37 sub show(Code $code) is export(:DEFAULT) {
cfdbe94 @tene [Tags]
tene authored
38 new_buffer_frame();
1693bdc @tene Minor update to tags to help with foreign languages.
tene authored
39 $code();
cfdbe94 @tene [Tags]
tene authored
40 return end_buffer_frame();
41 }
42
f54cc4b @tene Ad a list of tags to not collapse to <tag/> when empty.
tene authored
43 sub _tag(Str $tag is rw, $body, *%named-args) {
b5b6bf6 @tene [Tags]: Basic support for attributes.
tene authored
44 my %attrs = %named-args<attrs>;
45 my $buf = "\n" ~ ' ' x (@frames.elems() - 1) ~ "<$tag";
46 for %attrs.kv -> $k, $v {
47 $buf ~= " $k='$v'";
48 }
e8d3f5e @tene [Tags]
tene authored
49 given $body {
50 when Failure {
f54cc4b @tene Ad a list of tags to not collapse to <tag/> when empty.
tene authored
51 if $tag ~~ @nocollapse {
52 $buf ~= "></$tag>";
53 }
54 else {
55 $buf ~= '/>';
56 }
e8d3f5e @tene [Tags]
tene authored
57 }
58 when Code {
59 $buf ~= '>';
60 new_buffer_frame();
61 my $ret = $body();
62 my $frame = end_buffer_frame();
63 if $frame.chars() > 0 {
64 $buf ~= $frame;
65 }
66 else {
67 $buf ~= $ret;
68 }
69 $buf ~= "\n" ~ ' ' x (@frames.elems() - 1) ~ "</$tag>";
70 }
71 when Str {
72 $buf ~= ">$body</$tag>";
73 }
cfdbe94 @tene [Tags]
tene authored
74 }
75 outs($buf);
76 return '';
77 }
78
79 sub outs($text) is export(:DEFAULT) {
80 @frames[0] ~= ($text);
81 }
82
83 sub new_buffer_frame {
84 @frames.unshift('');
85 }
86
87 sub end_buffer_frame {
88 @frames.shift();
89 }
90
91 class Web::Tags::Buffer {
92 has $.data is rw;
93 method append($text) {
94 $.data ~= $text;
95 }
96 }
97
98 }
99
Something went wrong with that request. Please try again.