diff --git a/wordle-life.cgi b/wordle-life.cgi index 7698502..c3721a7 100755 --- a/wordle-life.cgi +++ b/wordle-life.cgi @@ -11,6 +11,9 @@ use Mojo::Template; use Mojo::Loader 'data_section'; #use Routes::Tiny; #don't even need use Readonly; +use List::Util qw(first); +#use HTML::Entities; +#use URL::Encode; #=== # MAKE SURE ORIGIN PAGE MATCHES FILENAME (especially if you are testing changes)! @@ -18,6 +21,8 @@ use Readonly; #=== my $ORIGIN_PAGE = "/wordle-life.cgi"; my $defaulttext = "Paste your wordle share here (replace this text)"; + my $WORDLE_INPUT_PARAM = "wordle-result"; + my $SHARENOTE_PARAM = "share-note"; cgi { @@ -41,17 +46,26 @@ use Readonly; my $wordle; my $method = $cgi->method; my $rle = ""; + my $isshare = 0; #flag for sharing, default false + my $sharenote = ""; #a note someone can tack onto their share #Simple switch: make a one page app, and always go back to the same page. #GET or HEAD loads the page blank, POST runs the Life file maker - if ($method eq 'GET' or $method eq 'HEAD') { + if ($method eq 'HEAD') { $wordle = $defaulttext; - #$wordle = ""; + + } elsif ($method eq 'GET') { + #TODO: if there are query parameters put them in $wordle and activate share page logic + if (first { $_ eq $WORDLE_INPUT_PARAM } @{$cgi->query_param_names} ){ + $wordle = $cgi->query_param($WORDLE_INPUT_PARAM); + $isshare = 1; #true + $sharenote = $cgi->query_param($SHARENOTE_PARAM); + }else{ + $wordle = $defaulttext; + } } elsif ($method eq 'POST') { #textarea name, pull the value from POST and reload into textarea - $wordle = $cgi->body_param('wordle-result'); - - + $wordle = $cgi->body_param($WORDLE_INPUT_PARAM); #if input textarea not changed from default text, do nothing unless ($wordle =~ /\Q$defaulttext\E/ or $wordle eq '') { #[Cc] /){ #cheat, if they put in something that looks like an RLE, pass output through @@ -61,7 +75,11 @@ use Readonly; }else{ $rle = generate_rle($wordle); } + #$sharequery= "?" . $WORDLE_INPUT_PARAM . "=" . url_escape($rle); + #$template = data_section __PACKAGE__, 'sharepage.html.ep'; + #$output = $mt->render($template, { ORIGIN_PAGE =>$ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle }); } + #$output = $mt->render($template, { WORDLE_INPUT_PARAM => $WORDLE_INPUT_PARAM, ORIGIN_PAGE => $ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle, sharenote => $sharenote }); } else { #some other request? PUT, DELETE? $cgi->set_response_status(405)->render; @@ -71,9 +89,11 @@ use Readonly; #die "Invalid wordle parameter" unless length $wordle; #Load template from DATA section and output - my $mt = Mojo::Template->new(auto_escape => 1, vars => 1); - my $template = data_section __PACKAGE__, 'index.html.ep'; - my $output = $mt->render($template, { ORIGIN_PAGE =>$ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle }); + #my $mt = Mojo::Template->new(auto_escape => 1, vars => 1); + my $mt = Mojo::Template->new(vars => 1); + my $template = data_section __PACKAGE__, 'index.html.ep'; + my $output = $mt->render($template, { WORDLE_INPUT_PARAM => $WORDLE_INPUT_PARAM, ORIGIN_PAGE => $ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle, isshare => $isshare, sharenote => $sharenote }); + #my $output = $mt->render($template, { ORIGIN_PAGE =>$ORIGIN_PAGE, defaulttext => $defaulttext, wordle => $wordle, rle => $rle }); #my $output = $mt->render($template, {wordle => $wordle}); $cgi->render(html => $output ); @@ -91,7 +111,8 @@ sub generate_rle { Readonly my $headline_prefix => "#C "; #Part of RLE spec https://conwaylife.com/wiki/Run_Length_Encoded Readonly my $row_prefix => "x = 5"; #for wordle always 5 Readonly my $col_prefix => ",y = "; - Readonly my $lifeviewer_settings => "\n[[\n GPS 3\n ZOOM 23\n COLOR ALIVE LIME\n COLOR BACKGROUND BLUE\n STOP 100\n GRID\n]]"; #Part of Viewer Spec + Readonly my $lifeviewer_settings => "\n[[\n GPS 3\n ZOOM 23\n COLOR ALIVE LIME\n COLOR BACKGROUND MIDNIGHTBLUE\n STOP 100\n GRID\n]]"; #Part of Viewer Spec + #Readonly my $lifeviewer_settings => "\n[[\n GPS 3\n ZOOM 23\n THEME INVERSE\n STOP 100\n GRID\n]]"; #Part of Viewer Spec my $wordle = shift; # this is how you get variables in your function call! $rowcount = 0; @@ -148,7 +169,6 @@ sub generate_rle { return "$headline\n$row_prefix$col_prefix$rowcount\n$rleline\n$lifeviewer_settings"; } - __DATA__ @@ index.html.ep @@ -160,7 +180,7 @@ __DATA__ @@ -170,8 +190,22 @@ __DATA__

Wordle->Life

+ + % if ($isshare) { + +

Hey, someone wants to share their Wordle->Life score with you!

+ %if ($sharenote){ +

They said: <%= $sharenote =%>

+ %}; +

Skip to step 2 of the instructions below and see the shared wordle-life happen!

+
+%}else{ + +

Play your Wordle Share score in Conway's Life!

+
+ % }; + -

Play your Wordle Share score in Conway's Life!

Hey, nerds, isn't it funny how the Wordle Scores can look like a glider in that old computer programming exercise, Conway's Life?

Glider image from Conwaylife.org, it looks like an 8-bit staple gun @@ -180,11 +214,11 @@ __DATA__

Paste your wordle share below and submit to convert it to a Conway's Life file so you can run it (to learn more about Conway's Life, read this).

-
+ - +


@@ -198,16 +232,15 @@ __DATA__
- - + +

If the RLE is correct, it should be loaded in the Life Viewer, and so you are ready to go!

- @@ -221,6 +254,27 @@ __DATA__

This should work with the share/copy button in wordle, or copy/pasting your friends' wordles out of Discord or wherever as well. See whose Wordle Score runs the coolest! +

+ + + +% if ($rle ne ""){ + + +

Share your wordle-life! +

You can copy/paste the RLE into your favorite social media post or email +
OR
+ Click this button to go to a share page where you can copy/paste the URL to someone:

+ + + + +% }; + +

+ +

If it doesn't seem to be working:

    @@ -242,7 +296,7 @@ GRID -

    (the main thing that needs to be right are the first 3 lines. If the 3rd line has any : symbols, just try deleting them. The stuff between double brackets aren't part of the RLE but are comments that set some defaults for the Life Viewer)

    +

    (the main thing that needs to be right are the first 3 lines. If the 3rd line has any colon : symbols, just try deleting them. The stuff between double brackets aren't part of the RLE but are comments that set some defaults for the Life Viewer)

    For details about the Life RLE file format above, read this.

    @@ -315,11 +369,11 @@ Hosted by SDF.org

    -

    + -


    @@ -332,7 +386,7 @@ Hosted by SDF.org