Skip to content

Instantly share code, notes, and snippets.

@gfx
Created August 14, 2010 13:06
Show Gist options
  • Select an option

  • Save gfx/524283 to your computer and use it in GitHub Desktop.

Select an option

Save gfx/524283 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw(encode_utf8);
use FindBin qw($Bin);
use Text::Markdown qw(markdown);
use Text::Xslate qw(mark_raw);
my $xslate = Text::Xslate->new(
path => ["$Bin/templates"],
);
my $books = {
"978-0596520106" => {
name => "Learning Perl",
pages => 352,
},
"978-0596000271" => {
name => "Programming Perl",
pages => 1092,
},
"978-0596527242" => {
name => "Mastering Perl",
pages => 352,
},
"978-0596001735" => {
name => "Perl Best Practices",
pages => 544,
},
};
my $see_also = markdown(<<'END_MD'); # an HTML generator
SEE ALSO
-----------------
* http://perl.com/
* http://perl.org/
* http://search.cpan.org/
END_MD
my $content = $xslate->render("perl.html", {
title => "Perl Books",
books => $books,
see_also => mark_raw($see_also),
});
print encode_utf8($content);
__END__
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title><: $title :></title>
</head>
<body>
<h1><: $title :></h1>
<ol>
: for $books.keys() -> $isbn {
<li><: $books[$isbn].name :> - <: $books[$isbn].pages :> pages / ISBN-13 : <: $isbn :></li>
: }
</ol>
<pre>
$books =
: $books | dump
</pre>
: $see_also # interpolate HTML components
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Perl Books</title>
</head>
<body>
<h1>Perl Books</h1>
<ol>
<li>Programming Perl - 1092 pages / ISBN-13 : 978-0596000271</li>
<li>Perl Best Practices - 544 pages / ISBN-13 : 978-0596001735</li>
<li>Learning Perl - 352 pages / ISBN-13 : 978-0596520106</li>
<li>Mastering Perl - 352 pages / ISBN-13 : 978-0596527242</li>
</ol>
<pre>
$books =
(
&apos;978-0596000271&apos; =&gt; {
name =&gt; &apos;Programming Perl&apos;,
pages =&gt; 1092
},
&apos;978-0596001735&apos; =&gt; {
name =&gt; &apos;Perl Best Practices&apos;,
pages =&gt; 544
},
&apos;978-0596520106&apos; =&gt; {
name =&gt; &apos;Learning Perl&apos;,
pages =&gt; 352
},
&apos;978-0596527242&apos; =&gt; {
name =&gt; &apos;Mastering Perl&apos;,
pages =&gt; 352
}
)
</pre>
<h2>SEE ALSO</h2>
<ul>
<li>http://perl.com/</li>
<li>http://perl.org/</li>
<li>http://search.cpan.org/</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment