line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Caribou::Tags::HTML::Extended; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
22867
|
$Template::Caribou::Tags::HTML::Extended::AUTHORITY = 'cpan:YANICK'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: custom HTML tags optimized for DWIMery |
6
|
|
|
|
|
|
|
$Template::Caribou::Tags::HTML::Extended::VERSION = '0.2.4'; |
7
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
120
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1772
|
use Method::Signatures; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Template::Caribou::Tags ':all'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Sub::Exporter -setup => { |
17
|
|
|
|
|
|
|
exports => [qw/ css anchor image markdown javascript javascript_include submit |
18
|
|
|
|
|
|
|
less css_include doctype |
19
|
|
|
|
|
|
|
favicon |
20
|
|
|
|
|
|
|
/], |
21
|
|
|
|
|
|
|
groups => { default => ':all' }, |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub doctype($) { |
26
|
|
|
|
|
|
|
my $type = shift; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ( $type eq 'html 5' ) { |
29
|
|
|
|
|
|
|
print ::RAW "<!DOCTYPE html>\n"; |
30
|
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
die "type '$type' not supported"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub favicon($) { |
38
|
|
|
|
|
|
|
my $url = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
render_tag( 'link', sub { |
41
|
|
|
|
|
|
|
attr rel => 'shortcut icon', |
42
|
|
|
|
|
|
|
href => $url |
43
|
|
|
|
|
|
|
} ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub submit(@) { |
48
|
|
|
|
|
|
|
my( $value, %attr ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
render_tag( 'input', '', sub { |
51
|
|
|
|
|
|
|
$_[0]->{type} = 'submit'; |
52
|
|
|
|
|
|
|
$_[0]->{value} = $value if $value; |
53
|
|
|
|
|
|
|
$_[0]->{$_} = $attr{$_} for keys %attr; |
54
|
|
|
|
|
|
|
}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub less($) { |
59
|
|
|
|
|
|
|
my $text = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
require CSS::LESSp; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $css = join '', CSS::LESSp->parse($text); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
css($css); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub javascript($) { |
71
|
|
|
|
|
|
|
my $script = shift; |
72
|
|
|
|
|
|
|
render_tag( 'script', sub { |
73
|
|
|
|
|
|
|
attr type => 'text/javascript'; |
74
|
|
|
|
|
|
|
print ::RAW $script; |
75
|
|
|
|
|
|
|
}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub javascript_include($) { |
80
|
|
|
|
|
|
|
my $url = shift; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
render_tag( 'script', sub { |
83
|
|
|
|
|
|
|
attr type => 'text/javascript', |
84
|
|
|
|
|
|
|
src => $url; |
85
|
|
|
|
|
|
|
print ::RAW ' '; # to prevent collapsing the tag |
86
|
|
|
|
|
|
|
}); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
func css_include( $url, \%args? = () ) { |
91
|
|
|
|
|
|
|
render_tag( 'link', sub { |
92
|
|
|
|
|
|
|
attr rel => 'stylesheet', |
93
|
|
|
|
|
|
|
href => $url, |
94
|
|
|
|
|
|
|
%args |
95
|
|
|
|
|
|
|
; |
96
|
|
|
|
|
|
|
}); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub css($) { |
101
|
|
|
|
|
|
|
my $css = shift; |
102
|
|
|
|
|
|
|
render_tag( 'style', sub { |
103
|
|
|
|
|
|
|
attr type => 'text/css'; |
104
|
|
|
|
|
|
|
$css; |
105
|
|
|
|
|
|
|
}); |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub anchor($$) { |
110
|
|
|
|
|
|
|
my ( $href, $inner ) = @_; |
111
|
|
|
|
|
|
|
render_tag( 'a', $inner, sub { |
112
|
|
|
|
|
|
|
$_[0]->{href} ||= $href; |
113
|
|
|
|
|
|
|
}); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub image(@) { |
118
|
|
|
|
|
|
|
my ( $src, %attr ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
croak "src required" unless $src; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$attr{src} = $src; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
render_tag( 'img', '', sub { |
125
|
|
|
|
|
|
|
$_[0]->{$_} = $attr{$_} for keys %attr; |
126
|
|
|
|
|
|
|
} ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub markdown($){ |
131
|
|
|
|
|
|
|
require Text::MultiMarkdown; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return unless length $_[0]; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
print ::RAW Text::MultiMarkdown::markdown(shift); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=pod |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=encoding UTF-8 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 NAME |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Template::Caribou::Tags::HTML::Extended - custom HTML tags optimized for DWIMery |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 VERSION |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
version 0.2.4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SYNOPSIS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
package MyTemplate; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
use Moose; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
use Template::Caribou::Tags::HTML; |
161
|
|
|
|
|
|
|
use Template::Caribou::Tags::HTML::Extended; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
with 'Template::Caribou'; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
template 'page' => sub { |
166
|
|
|
|
|
|
|
html { |
167
|
|
|
|
|
|
|
head { |
168
|
|
|
|
|
|
|
css q{ |
169
|
|
|
|
|
|
|
color: magenta; |
170
|
|
|
|
|
|
|
}; |
171
|
|
|
|
|
|
|
}; |
172
|
|
|
|
|
|
|
body { |
173
|
|
|
|
|
|
|
markdown q{Ain't Markdown **grand**?}; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
anchor "http://foo.com" => sub { |
176
|
|
|
|
|
|
|
image 'http://foo.com/bar.jpg', alt => 'Foo logo'; |
177
|
|
|
|
|
|
|
}; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
}; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 DESCRIPTION |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
I<Template::Caribou::Tags::HTML::Extended> provides utility tags that provides |
186
|
|
|
|
|
|
|
shortcuts for typical HTML constructs. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 doctype $type |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Prints the doctype declaration for the given type. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
For the moment, only I<html 5> is supported as a type. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 favicon $url |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Generates the favicon tag. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
favicon 'my_icon.png'; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
will generates |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
<link rel="shortcut icon" href="my_icon.png" /> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 submit $value, %attr |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Shortcut for |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
input { attr type => submit, value => 'value', %attr; } |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
If you don't want I<value> to be passed, the first argument might be |
211
|
|
|
|
|
|
|
set to I<undef>. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head2 less $script |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Compile the LESS script into CSS. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 javascript $script |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Shortcut for |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
<script type="text/javascript>$script</script> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 javascript_include $url |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Shortcut for |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
<script type="text/javascript" src="http://..."> </script> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 css_include |
230
|
|
|
|
|
|
|
<link href="public/bootstrap/css/bootstrap.min.css" rel="stylesheet" |
231
|
|
|
|
|
|
|
media="screen" /> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 css $text |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Wraps the I<$text> in a style element. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
<style type="text/css">$text</style> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head2 anchor $url, $inner |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Shortcut for <a>. I<$inner> can be either a string, or a subref. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
anchor 'http://foo.com' => 'linkie'; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
is equivalent to |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
a { |
248
|
|
|
|
|
|
|
attr href => 'http://foo.com'; |
249
|
|
|
|
|
|
|
'linkie'; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 image $src, @attr |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Shortcut for <img>. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 markdown $text |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Converts the markdown $text into its html equivalent. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Uses L<Text::MultiMarkdown>. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 AUTHOR |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Yanick Champoux. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
271
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=cut |