From f22a9debc2c3c50828c31ff028057734a4aadea6 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 18 Dec 2009 00:22:40 +0000 Subject: [PATCH] common html initialisation function --- charset.plp | 43 ++++++++++++-------------------- common.inc.plp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ countries.plp | 34 +++++++------------------- digraphs.plp | 37 +++++++++------------------- index.plp | 38 ++++++++++------------------- mplayer.plp | 51 +++++++++++--------------------------- mutt.plp | 51 +++++++++++--------------------------- nethack.plp | 51 +++++++++++--------------------------- readline.plp | 51 +++++++++++--------------------------- source.plp | 49 +++++++++++++------------------------ termcol.plp | 40 +++++++++++------------------- unicode.plp | 38 ++++++++++------------------- vi.plp | 53 ++++++++++++---------------------------- vimperator.plp | 52 ++++++++++++--------------------------- 14 files changed, 246 insertions(+), 408 deletions(-) diff --git a/charset.plp b/charset.plp index 440cabe..e2b2e27 100644 --- a/charset.plp +++ b/charset.plp @@ -1,20 +1,20 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - -:> - - - - -charset cheat sheet - - -<:= stylesheet(qw'light') :> - - - - + +Html({ + title => 'charset cheat sheet', + version => 'v1.0', + description => [ + "Reference sheet with all glyphs in common character encoding tables,", + "and an overview of Unicode ranges and UTF-8 bytes.", + ], + keywords => [qw' + charset codepage unicode ascii utf8 latin glyph character encoding + reference common overview table + '], + stylesheet => [qw'light'], +}); + +:>

Character encoding

<: @@ -191,14 +191,3 @@ for my $row (@request) { - - - diff --git a/common.inc.plp b/common.inc.plp index 28a14ce..fb1d54a 100644 --- a/common.inc.plp +++ b/common.inc.plp @@ -6,7 +6,11 @@ no warnings 'qw'; # you know what you doing no warnings 'uninitialized'; # save some useless checks for more legible code use open IO => ':utf8'; +use Shiar_Sheet::KeySigns qw(%sign); # dependant on $get{ascii} + our $style; +our $showkeys = !exists $get{keys} ? undef : + ($get{keys} ne '0' && ($get{keys} || 'always')); $header{content_type} = 'text/html; charset=utf-8'; @@ -32,3 +36,65 @@ sub stylesheet { ) } @_; } +sub Html { + my ($meta) = @_; + + # default fallbacks + $meta->{stylesheet} ||= [qw'light dark circus mono red terse']; + $meta->{charset} ||= 'utf-8'; + + # optional amends + push @{ $meta->{raw} }, ( + '', + '', + !$showkeys ? '' + : $showkeys eq 'ghost' ? '' + : (), + '', + ) if $meta->{keys}; + + # flatten arrays + ref $_ eq 'ARRAY' and $_ = join ' ', @$_ for $meta->{description}; + ref $_ eq 'ARRAY' and $_ = join ', ', @$_ for $meta->{keywords}; + ref $_ eq 'ARRAY' and $_ = join "\n", @$_ for $meta->{rawstyle}, $meta->{raw}; + + # other vars + my $sep = $meta->{charset} eq 'utf-8' ? '•' : ' -- '; + my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x; + + # leading output + $header{content_type} = "text/html; charset=$meta->{charset}"; + print <<"EOT"; + + + + + +$meta->{title} + + + +EOT + print stylesheet(@$_), "\n" for $meta->{stylesheet} || (); + print $_, "\n" for $meta->{raw} || (); + print qq{\n\n\n}; + + # prepare trailing output + PLP_END { + print <<"EOT"; + + + +EOT + }; +} + diff --git a/countries.plp b/countries.plp index 6e12b1b..838a288 100644 --- a/countries.plp +++ b/countries.plp @@ -1,20 +1,15 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; -:> - +Html({ + title => 'country code cheat sheet', + version => 'v1.0', + description => + "Table of ISO-3166-2 country codes with the names of reserved territories.", + keywords => [qw'country code cc tld territory land table'], + stylesheet => [qw'light dark mono red'], +}); - - -country code cheat sheet - - -<:= stylesheet(qw'light dark mono red') :> - - - - +:>

Country codes

<: @@ -96,14 +91,3 @@ my $cc = do 'countries.inc.pl'; - - - diff --git a/digraphs.plp b/digraphs.plp index 237cc7b..8b09697 100644 --- a/digraphs.plp +++ b/digraphs.plp @@ -1,20 +1,18 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; -:> - +Html({ + title => 'digraph cheat sheet', + version => 'v1.0', + description => [ + "Complete table of digraph characters from RFC-1345.", + ], + keywords => [qw' + digraph compose character char glyph table unicode vim + '], + stylesheet => [qw'light'], +}); - - -digraph cheat sheet - - -<:= stylesheet(qw'light') :> - - - - +:>

RFC-1345 Digraphs

i^k in Vim. @@ -104,14 +102,3 @@ print "\n"; -

- - diff --git a/index.plp b/index.plp index f91364d..839392d 100644 --- a/index.plp +++ b/index.plp @@ -1,21 +1,18 @@ <(common.inc.plp)><: - our $VERSION = 'v1.3'; - -:> - - - - -cheat sheets - - -<:= stylesheet(qw'light dark red') :> - - - - +Html({ + title => 'cheat sheets', + version => 'v1.3', + description => [ + "Cheat sheets summarising various software programs and standards.", + ], + keywords => [qw' + sheet cheat reference software overview summary help keyboard map unicode + '], + stylesheet => [qw'light dark red'], +}); + +:>

Shiar's cheat sheets

@@ -55,12 +52,3 @@ but you're free to use, print, alter, and redistribute under the AGPL license. -

- diff --git a/mplayer.plp b/mplayer.plp index 1cd6cf8..2de974a 100644 --- a/mplayer.plp +++ b/mplayer.plp @@ -1,33 +1,21 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - use Shiar_Sheet::KeySigns qw(%sign); +Html({ + title => 'mplayer cheat sheet', + version => 'v1.0', + description => [ + "Keyboard cheat sheet for the MPlayer media player,", + "overviewing the default controls." + ], + keywords => [qw' + mplayer video media sheet cheat reference overview control shortkey keyboard + '], + charset => $sign{charset}, + stylesheet => [qw'light dark circus mono red terse'], + keys => 1, +}); - $header{content_type} = "text/html; charset=$sign{charset}"; - -:> - - - - -mplayer cheat sheet - - -<:= stylesheet(qw'light dark circus mono red terse') :> - -<: - our $showkeys = exists $get{keys} && $get{keys} ne '0'; - print "\n".'' - unless $showkeys; - print "\n".'' - if $showkeys and $get{keys} eq 'ghost'; :> - - - - -

MPlayer cheat sheet

index (default)

@@ -92,14 +80,3 @@ $keys->print_rows($get{rows}, [1,0]); - - - diff --git a/mutt.plp b/mutt.plp index 0dbb0d0..ec4d0a2 100644 --- a/mutt.plp +++ b/mutt.plp @@ -1,33 +1,21 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - use Shiar_Sheet::KeySigns qw(%sign); +Html({ + title => 'mutt cheat sheet', + version => 'v1.0', + description => [ + "Cheat sheet for the Mutt e-mail client,", + "showing the default binding for each key.", + ], + keywords => [qw' + mutt MUA email client sheet cheat reference overview commands keyboard + '], + charset => $sign{charset}, + stylesheet => [qw'light dark circus mono red terse'], + keys => 1, +}); - $header{content_type} = "text/html; charset=$sign{charset}"; - -:> - - - - -mutt cheat sheet - - -<:= stylesheet(qw'light dark circus mono red terse') :> - -<: - our $showkeys = exists $get{keys} && $get{keys} ne '0'; - print "\n".'' - unless $showkeys; - print "\n".'' - if $showkeys and $get{keys} eq 'ghost'; :> - - - - -

Mutt cheat sheet

index (default)

@@ -94,14 +82,3 @@ $keys->print_rows($get{rows}); - - - diff --git a/nethack.plp b/nethack.plp index 8396edd..eaea76c 100644 --- a/nethack.plp +++ b/nethack.plp @@ -1,33 +1,21 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - use Shiar_Sheet::KeySigns qw(%sign); +Html({ + title => 'nethack cheat sheet', + version => 'v1.0', + description => [ + "Keyboard overview sheet for the Nethack console RPG game,", + "describing the default controls.", + ], + keywords => [qw' + nethack rogue game control controls sheet reference overview keyboard + '], + charset => $sign{charset}, + stylesheet => [qw'light dark circus mono red terse'], + keys => 1, +}); - $header{content_type} = "text/html; charset=$sign{charset}"; - -:> - - - - -nethack cheat sheet - - -<:= stylesheet(qw'light dark circus mono red terse') :> - -<: - our $showkeys = exists $get{keys} && $get{keys} ne '0'; - print "\n".'' - unless $showkeys; - print "\n".'' - if $showkeys and $get{keys} eq 'ghost'; :> - - - - -

NetHack cheat sheet

normal gameplay

@@ -94,14 +82,3 @@ $keys->print_rows($get{rows} || '4321-421', [3,2,1,0]); - - - diff --git a/readline.plp b/readline.plp index ded1709..cc70d05 100644 --- a/readline.plp +++ b/readline.plp @@ -1,33 +1,21 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - use Shiar_Sheet::KeySigns qw(%sign); # dependant on $get{ascii} +Html({ + title => 'readline cheat sheet', + version => 'v1.0', + description => [ + "Reference sheet of default key bindings for GNU readline,", + "used in line-editing in most Unix software, notably emacs and bash.", + ], + keywords => [qw' + readline gnu bash emacs sheet cheat reference overview keyboard editing curses + '], + charset => $sign{charset}, + stylesheet => [qw'light dark circus mono red terse'], + keys => 1, +}); - $header{content_type} = "text/html; charset=$sign{charset}"; - -:> - - - - -readline cheat sheet - - -<:= stylesheet(qw'light dark circus mono red terse') :> - -<: - our $showkeys = exists $get{keys} && $get{keys} ne '0'; - print "\n".'' - unless $showkeys; - print "\n".'' - if $showkeys and $get{keys} eq 'ghost'; :> - - - - -

readline cheat sheet

default emacs mode

@@ -95,14 +83,3 @@ $keys->print_rows($get{rows} || '^x=213', [4,3,2]); - - - diff --git a/source.plp b/source.plp index de3ad54..cdd40a1 100644 --- a/source.plp +++ b/source.plp @@ -1,28 +1,22 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - my $source = $ENV{PATH_INFO}; - $source =~ s{^/}{}; +my $source = $ENV{PATH_INFO}; +$source =~ s{^/}{}; -:> - +Html({ + title => "$source source code", + version => 'v1.0', + description => !$source ? 'Index of source files for this site.' : [ + "Source code of local $source file,", + "with syntax highlighted and references linked." + ], + keywords => [qw' + sheet cheat source code perl plp html agpl + '], + stylesheet => [qw'light dark mono red'], +}); - - -<:= $source :> source code -"> - -<:= stylesheet(qw'light dark mono red') :> - - - - -<: +print "\n"; if (not $source) { print "

Source files

"; @@ -84,16 +78,7 @@ else { else { print "
\n", EscapeHTML(ReadFile($source)), "
\n"; } + + print "\n"; } -:> - - diff --git a/termcol.plp b/termcol.plp index 5a0306a..4b91032 100644 --- a/termcol.plp +++ b/termcol.plp @@ -1,22 +1,21 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - use List::Util 'min'; - -:> - +Html({ + title => 'terminal colour cheat sheet', + version => 'v1.0', + description => [ + "Index of all terminal/console colour codes,", + "with an example result of various environments.", + ], + keywords => [qw' + color code terminal console escape table xterm rxvt + '], + stylesheet => [qw'light dark'], +}); - - -terminal colour cheat sheet - - -<:= stylesheet(qw'light dark') :> - - +use List::Util 'min'; - +:>

Terminal colours

@@ -139,14 +138,3 @@ print "\n"; <: } :>
- - - diff --git a/unicode.plp b/unicode.plp index 51bf7c8..4a6856e 100644 --- a/unicode.plp +++ b/unicode.plp @@ -1,20 +1,19 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; -:> - +Html({ + title => 'unicode glyph cheat sheet', + version => 'v1.0', + description => [ + "Common Unicode characters with digraph or code point, layed out for quick location.", + "Includes general signs, arrows, drawing characters, and IPA letters.", + ], + keywords => [qw' + unicode glyph char character reference common ipa sign mark table digraph + '], + stylesheet => [qw'light dark red'], +}); - - -digraph cheat sheet - - -<:= stylesheet(qw'light dark red') :> - - - - +:>

Common Unicode

i^k in Vim. @@ -277,14 +276,3 @@ $verbose ? (

- - - diff --git a/vi.plp b/vi.plp index fc5e194..67326cb 100644 --- a/vi.plp +++ b/vi.plp @@ -1,33 +1,21 @@ <(common.inc.plp)><: - our $VERSION = 'v1.2'; - use Shiar_Sheet::KeySigns qw(%sign); # dependant on $get{ascii} +Html({ + title => 'vi cheat sheet', + version => 'v1.2', + description => [ + "Interactive cheat sheet for vi text editors, notably Vim,", + "describing each key in various modes.", + ], + keywords => [qw' + vi vim nvi sheet cheat reference overview commands keyboard + '], + charset => $sign{charset}, + stylesheet => [qw'light dark circus mono red terse'], + keys => 1, +}); - $header{content_type} = "text/html; charset=$sign{charset}"; - -:> - - - - -vi cheat sheet - - -<:= stylesheet(qw'light dark circus mono red terse') :> - -<: - our $showkeys = exists $get{keys} && $get{keys} ne '0'; - print "\n".'' - unless $showkeys; - print "\n".'' - if $showkeys and $get{keys} eq 'ghost'; :> - - - - -

vi/vim cheat sheet

normal mode (default)

@@ -93,21 +81,10 @@ $keys->print_rows($get{rows}); $sign{-ascii} ? 'on' : 'off' :>
  • keys are <:= $showkeys ? 'always shown' : 'hidden if unassigned' :><:= - !exists $get{keys} && ' by default' :> + !defined $showkeys && ' by default' :>
  • default style is <:= defined $get{style} && 'set to ' :><:= $style :> - - - diff --git a/vimperator.plp b/vimperator.plp index 7b02c53..88f5e95 100644 --- a/vimperator.plp +++ b/vimperator.plp @@ -1,33 +1,22 @@ <(common.inc.plp)><: - our $VERSION = 'v1.0'; - use Shiar_Sheet::KeySigns qw(%sign); +Html({ + title => 'vimperator cheat sheet', + version => 'v1.0', + description => [ + "Interactive cheat sheet for the Vimperator Firefox extension,", + "describing the function of each key.", + ], + keywords => [qw' + vimperator firefox vim iceweasel sheet cheat reference overview + commands keyboard browser + '], + charset => $sign{charset}, + stylesheet => [qw'light dark circus mono red terse'], + keys => 1, +}); - $header{content_type} = "text/html; charset=$sign{charset}"; - -:> - - - - -vimperator cheat sheet - - -<:= stylesheet(qw'light dark circus mono red terse') :> - -<: - our $showkeys = exists $get{keys} && $get{keys} ne '0'; - print "\n".'' - unless $showkeys; - print "\n".'' - if $showkeys and $get{keys} eq 'ghost'; :> - - - - -

    Vimperator cheat sheet

    normal mode (default)

    @@ -98,14 +87,3 @@ $keys->print_rows($get{rows}); - - - -- 2.30.0