Advertisement
kwasinski

simula_template.pl

Dec 6th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.34 KB | None | 0 0
  1. #!perl -w
  2. use Getopt::Long;
  3. use File::Slurp qw/read_file write_file/;
  4.  
  5. my $title = '';
  6. my $ismobile = '';
  7. GetOptions('title=s', \$title, 'ismobile=i', \$ismobile);
  8.  
  9.  
  10. $\ = '';
  11. opendir DIR, '.';
  12. # Magic trick
  13.  
  14. map  {
  15.     m/(\d+?)\.(\w{3,4})$/g;
  16.     my $nxt = $1 + 1;
  17.     last  if not defined $1;
  18.     $nxt = 'index'  if ! -e "$nxt.$2";
  19.     write_file((($1 eq '1')? 'index': $1).'.html', template($title, $_, $nxt, $ismobile))  if defined $1;
  20. } grep{m/\.jpg|png|jpeg$/} readdir(DIR);
  21.  
  22. sub template {
  23.     my ($title, $image, $pageToGo, $ismobile) = @_;
  24.  
  25.     my $css = '';
  26.     $css = 'width: 360px; margin: 0 auto;'  if $ismobile eq '1';
  27.  
  28.     return "<html>
  29.         <head>
  30.             <meta charset=\"UTF-8\">
  31.             <title>$title</title>
  32.             <style type=\"text/css\">
  33.                 body {
  34.                     margin: 0px;
  35.                     width: 100%;
  36.                     height: 100%;
  37.                     $css;
  38.                 }
  39.                 img { width: 100%; height: auto; }
  40.             </style>
  41.             <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>
  42.             <script type=\"text/javascript\">
  43.                 jQuery(document).ready(function(\$) {
  44.                     \$(\"body\").click(function() {
  45.                         document.location = \"$pageToGo.html\";
  46.                     });
  47.                 });
  48.             </script>
  49.         </head>
  50.         <body>
  51.             <img width=\"auto\" height=\"auto\" src=\"$image\">
  52.         </body>
  53.     </html>";
  54.  
  55. }
  56.  
  57.  
  58. __END__
  59.  
  60.  
  61. Simply Create a HTML for a given N of images to simulate a navigation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement