From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Sassmannshausen Subject: Re: patch for list-packages Date: Sun, 11 Aug 2013 22:28:01 +0200 Message-ID: <874naw9dm6.fsf@honeybear.home> References: <87mwoxw6i0.fsf@honeybear.home> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V8bJP-0003Zu-VV for guix-devel@gnu.org; Sun, 11 Aug 2013 15:28:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V8bJK-0005jP-TV for guix-devel@gnu.org; Sun, 11 Aug 2013 15:28:23 -0400 Received: from mail-ee0-x22c.google.com ([2a00:1450:4013:c00::22c]:59806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V8bJK-0005iy-F7 for guix-devel@gnu.org; Sun, 11 Aug 2013 15:28:18 -0400 Received: by mail-ee0-f44.google.com with SMTP id b47so3084710eek.17 for ; Sun, 11 Aug 2013 12:28:17 -0700 (PDT) Received: from honeybear.home.home (231.147-243-81.adsl-dyn.isp.belgacom.be. [81.243.147.231]) by mx.google.com with ESMTPSA id f49sm45179833eec.7.2013.08.11.12.28.14 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 11 Aug 2013 12:28:16 -0700 (PDT) In-Reply-To: <87mwoxw6i0.fsf@honeybear.home> (Alex Sassmannshausen's message of "Sun, 04 Aug 2013 22:22:47 +0200") List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org Hello, I have now been able to finish (in my mind) the work I wanted to carry out for list-packages.scm's output. I have attached the complete patch series (3 files, including the first one I sent on 4 August). As well as the patch series you can visualise what the results of the final 2 patches are at http://www.atheia.org/guix/output.html (2nd patch) and http://www.atheia.org/guix/output-final.html (3rd patch). I've stuck to what I set out to do in my original email. I ended up generating JavaScript function calls (using ") + + + +") (display (sxml->xml (packages->sxml packages))) (format #t "
--=20 1.7.10.4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3DFile ~/projects/guix/0002-list-packages-tidying-tidying-and-refactoring-in-pre.p= atch=3D=3D=3D >From 1bc1c348e8a792d3ac7b22bbb82ea9285d03f1ea Mon Sep 17 00:00:00 2001 From: Alex Sassmannshausen Date: Sun, 11 Aug 2013 19:53:15 +0200 Subject: [PATCH 2/3] list-packages tidying: tidying and refactoring in preparation for substantive changes. * build-aux/list-packages.scm (license package): add title for element. (status package): add title for element. (package->sxml package): add alt and title for gnu-logo element. (package->sxml package): add title to package website element. (packages->sxml packages): wrap
intro paragraph in

= element. (packages->sxml packages): add table header row to (packages->sxml packages): add back to top of the page beneath table. (insert-css): create new function returning page's CSS; apply whole load = of new CSS. (insert-js): create new function returning page's JavaScript. (list-packages . args): move JavaScript to (insert-js). (list-packages . args): move CSS to (insert-css). --- build-aux/list-packages.scm | 148 +++++++++++++++++++++++++++++----------= ---- 1 file changed, 102 insertions(+), 46 deletions(-) diff --git a/build-aux/list-packages.scm b/build-aux/list-packages.scm index ceadbef..b598b97 100755 --- a/build-aux/list-packages.scm +++ b/build-aux/list-packages.scm @@ -65,7 +65,8 @@ exec guile -l "$0" \ (let ((uri (license-uri license))) (case (and=3D> (and uri (string->uri uri)) uri-scheme) ((http https) - `(div (a (@ (href ,uri)) + `(div (a (@ (href ,uri) + (title "Link to the full license")) ,(license-name license)))) (else `(div ,(license-name license) " (" @@ -78,7 +79,8 @@ exec guile -l "$0" \ (define (url system) `(a (@ (href ,(string-append "http://hydra.gnu.org/job/gnu/master/" (package-full-name package) "." - system))) + system)) + (title "View the status of this architecture's build at Hydra= ")) ,system)) =20 `(div "status: " @@ -92,9 +94,12 @@ exec guile -l "$0" \ (let ((description-id (symbol->string (gensym (package-name package))))) `(tr (td ,(if (gnu-package? package) - `(img (@ (src "/graphics/gnu-head-mini.png"))) + `(img (@ (src "/graphics/gnu-head-mini.png") + (alt "Part of GNU") + (title "Part of GNU"))) "")) - (td (a (@ (href ,(source-url package))) + (td (a (@ (href ,(source-url package)) + (title "Link to the Guix package source code")) ,(package-name package) " " ,(package-version package))) (td (@ (colspan "2") (height "0")) @@ -104,7 +109,6 @@ exec guile -l "$0" \ description-id))) ,(package-synopsis package)) (div (@ (id ,description-id) - (class "package-description") (style "display: none;")) ,(match (package-logo (package-name package)) ((? string? url) @@ -114,7 +118,8 @@ exec guile -l "$0" \ (_ #f)) (p ,(package-description package)) ,(license package) - (a (@ (href ,(package-home-page package))) + (a (@ (href ,(package-home-page package)) + (title "Link to the package's website")) ,(package-home-page package)) ,(status package)))))) =20 @@ -127,16 +132,93 @@ exec guile -l "$0" \ (img (@ (src "graphics/guix-logo.small.png") (alt "GNU Guix and the GNU System") (height "83em")))) - "This web page lists the packages currently provided by the " - (a (@ (href "manual/guix.html#GNU-Distribution")) - "GNU system distribution") - " of " - (a (@ (href "/software/guix/guix.html")) "GNU Guix") ". " - "Our " (a (@ (href "http://hydra.gnu.org/jobset/gnu/master")) - "continuous integration system") - " shows their current build status.") + (p "This web page lists the packages currently provided by the " + (a (@ (href "manual/guix.html#GNU-Distribution")) + "GNU system distribution") + " of " + (a (@ (href "/software/guix/guix.html")) "GNU Guix") ". " + "Our " (a (@ (href "http://hydra.gnu.org/jobset/gnu/master")) + "continuous integration system") + " shows their current build status.")) (table (@ (id "packages")) - ,@(map package->sxml packages)))) + (tr (th "GNU?") + (th "Package version") + (th "Package details")) + ,@(map package->sxml packages)) + (a (@ (href "#intro") + (title "Back to top.") + (id "top")) + "^"))) + + +(define (insert-css) + "Return the CSS for the list-packages page." + (format #t +"")) + +(define (insert-js) + "Return the JavaScript for the list-packages page." + (format #t +"")) =20 (define (list-packages . args) @@ -154,39 +236,13 @@ with gnu.org server-side include and all that." (string - GNU Guix - GNU Distribution - GNU Project - - - ") - (display (sxml->xml (packages->sxml packages))) + (insert-css) + (insert-js) + (format #t "") + + (sxml->xml (packages->sxml packages)) (format #t "
=20 --=20 1.7.10.4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3DFile ~/projects/guix/0003-list-packages.scm-cause-description-to-be-shown-and-.p= atch=3D=3D=3D >From 2b9542cfcc180a6b5fc3b0ed28217eb0896c0d2b Mon Sep 17 00:00:00 2001 From: Alex Sassmannshausen Date: Sun, 11 Aug 2013 21:40:29 +0200 Subject: [PATCH 3/3] list-packages.scm: cause description to be shown, and 'void' links to not be shown when JS is disabled. * build-aux/list-packages.scm (package->sxml package): no longer use package-synopsis as link as we cannot assume the JavaScript in the link w= ill work (no JS safety net); instead use a span. (package->sxml package): remove default invisibility of package descriptions. (package->sxml package): call (show_hide-grouper description-id) after ea= ch package is processed to collect the package description-ids to be made invisible. (show_hide-grouper id-or-force): new function; collect n package IDs, and= to insert a JS call to bulk_show_hide with the package IDs to be processed i= nto the xml. (packages->sxml packages): call (show_hide-grouper #f) after (map package->sxml packages) returns to force the remaining package IDs to be processed, even if n have not been reached yet. (insert-js): (show_hide(idThing)): add general clause to check whether working, DOM conforming JS exists; introduce thingLink variable to allow = its text to be modified depending on the show/hide package description state = of a given package. (insert-js): (prep(idThing)): new JS function that generates a link in the span containing package-synopsis. New link provides show/hide package-description functionality. (insert-js): (bulk_show_hide()): new JS function that is able to process (first call prep, then show_hide on a package-ID) any number of package-I= Ds sequentially (for now defaults to 15, as provided by (show_hide-grouper id-or-force)). --- build-aux/list-packages.scm | 72 +++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/build-aux/list-packages.scm b/build-aux/list-packages.scm index b598b97..2aa6194 100755 --- a/build-aux/list-packages.scm +++ b/build-aux/list-packages.scm @@ -102,14 +102,8 @@ exec guile -l "$0" \ (title "Link to the Guix package source code")) ,(package-name package) " " ,(package-version package))) - (td (@ (colspan "2") (height "0")) - (a (@ (href "javascript:void(0)") - (title "show/hide package description") - (onClick ,(format #f "javascript:show_hide('~a')" - description-id))) - ,(package-synopsis package)) - (div (@ (id ,description-id) - (style "display: none;")) + (td (span (strong ,(package-synopsis package))) + (div (@ (id ,description-id)) ,(match (package-logo (package-name package)) ((? string? url) `(img (@ (src ,url) @@ -121,7 +115,35 @@ exec guile -l "$0" \ (a (@ (href ,(package-home-page package)) (title "Link to the package's website")) ,(package-home-page package)) - ,(status package)))))) + ,(status package)) + ,(show_hide-grouper description-id))))) + + (define show_hide-grouper + (let ((lid '()) + (group-counter 15)) + (lambda (id-or-force) + "Collect GROUP-COUNTER element IDs, then apply them to +bulk_show_hide. Pass ID-OR-FORCE #f to apply collected IDs to bulk_show_hi= de +even when GROUP-COUNTER IDs have not been collected." + (letrec + ((lid->js-argl + (lambda (l separator) + "Parse a list into JavaScript style arguments." + (if (null? l) + "" + (string-append separator "'" (car l) "'" + (lid->js-argl (cdr l) ", ")))))) + (cond ((or (not id-or-force) + (> (length lid) group-counter)) + (let ((t lid)) + (if id-or-force + (set! lid (list id-or-force)) + (set! lid '())) + `(script (@ (type "text/javascript")) + ,(format #f "bulk_show_hide(~a)" + (lid->js-argl t ""))))) + (else (set! lid (cons id-or-force lid)) + "")))))) =20 (define (packages->sxml packages) "Return an HTML page as SXML describing PACKAGES." @@ -145,6 +167,7 @@ exec guile -l "$0" \ (th "Package version") (th "Package details")) ,@(map package->sxml packages)) + ,(show_hide-grouper #f) (a (@ (href "#intro") (title "Back to top.") (id "top")) @@ -209,14 +232,45 @@ color:#fff; // license: CC0 function show_hide(idThing) { + if(document.getElementById && document.createTextNode) { var thing =3D document.getElementById(idThing); + /* Used to change the link text, depending on whether description is + collapsed or expanded */ + var thingLink =3D thing.previousSibling.lastChild.firstChild; if (thing) { if (thing.style.display =3D=3D \"none\") { thing.style.display =3D \"\"; + thingLink.data =3D 'Collapse'; } else { thing.style.display =3D \"none\"; + thingLink.data =3D 'Expand'; } } + } +} +/* Add controllers used for collapse/expansion of package descriptions */ +function prep(idThing) +{ + var tdThing =3D document.getElementById(idThing).parentNode; + if (tdThing) { + var aThing =3D tdThing.firstChild.appendChild(document.createElement('= a')); + aThing.setAttribute('href', 'javascript:void(0)'); + aThing.setAttribute('title', 'show/hide package description'); + aThing.appendChild(document.createTextNode('Expand')); + aThing.onclick=3Dfunction(){show_hide(idThing);}; + /* aThing.onkeypress=3Dfunction(){show_hide(idThing);}; */ + } +} +/* Take n element IDs, prepare them for javascript enhanced +display and hide the IDs by default. */ +function bulk_show_hide() +{ + if(document.getElementById && document.createTextNode) { + for(var i=3D0; i")) =20 --=20 1.7.10.4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D