From 7b05ede5539e7abd408b4237b4c3b85d5f09fd08 Mon Sep 17 00:00:00 2001 From: slava Date: Thu, 19 Oct 2006 21:28:58 +0000 Subject: [PATCH] Furnace tools overhaul --- contrib/furnace/page.fhtml | 2 +- contrib/furnace/responder.factor | 11 ++-- contrib/furnace/tools/browser.factor | 61 +++---------------- contrib/furnace/tools/browser.fhtml | 22 +++++++ contrib/furnace/tools/help.factor | 2 +- contrib/furnace/tools/list.fhtml | 14 +++++ contrib/httpd/default-responders.factor | 2 +- contrib/{ => httpd}/embedded.factor | 26 ++++---- contrib/httpd/html.factor | 16 +++-- contrib/httpd/load.factor | 4 +- contrib/httpd/prototype-js.factor | 2 +- .../{javascript => resources}/prototype.js | 0 contrib/httpd/resources/stylesheet.css | 4 ++ 13 files changed, 78 insertions(+), 88 deletions(-) create mode 100644 contrib/furnace/tools/browser.fhtml create mode 100644 contrib/furnace/tools/list.fhtml rename contrib/{ => httpd}/embedded.factor (77%) rename contrib/httpd/{javascript => resources}/prototype.js (100%) create mode 100644 contrib/httpd/resources/stylesheet.css diff --git a/contrib/furnace/page.fhtml b/contrib/furnace/page.fhtml index b50ad436f3..17d4dabbc8 100644 --- a/contrib/furnace/page.fhtml +++ b/contrib/furnace/page.fhtml @@ -1,6 +1,6 @@ <% USING: namespaces io furnace ; %> - +<% xhtml-preamble %> <% "title" get write %> diff --git a/contrib/furnace/responder.factor b/contrib/furnace/responder.factor index b33d30429d..a434aacf35 100644 --- a/contrib/furnace/responder.factor +++ b/contrib/furnace/responder.factor @@ -109,13 +109,12 @@ C: page ( title model template -- page ) : render-template ( model template -- ) template-path get swap path+ call-template ; -: render-component - dup component-model swap component-template - render-template ; - : render-page ( title model template -- ) - serving-html - "contrib/furnace/page" call-template ; + [ + rot [ + render-template + ] html-document + ] with-html-stream ; : web-app ( name default path -- ) over responder-vocab create-vocab drop diff --git a/contrib/furnace/tools/browser.factor b/contrib/furnace/tools/browser.factor index c9f4fa2a64..01fe1e1e6d 100644 --- a/contrib/furnace/tools/browser.factor +++ b/contrib/furnace/tools/browser.factor @@ -5,27 +5,10 @@ IN: furnace:browser USING: definitions hashtables help html httpd io kernel memory namespaces prettyprint sequences words xml furnace arrays ; -: option ( current text -- ) - #! Output the HTML option tag for the given text. If - #! it is equal to the current string, make the option selected. - ; +TUPLE: list current options name ; -: options ( current seq -- ) [ option ] each-with ; - -: list ( current seq name -- ) - ; - -: current-vocab ( -- string ) - "vocab" query-param [ "kernel" ] unless* ; - -: current-word ( -- word ) - "word" query-param "vocab" query-param lookup ; +: list ( current options name -- ) + "list" render-template ; : vocab-list ( vocab -- ) vocabs "vocab" list ; @@ -33,49 +16,23 @@ namespaces prettyprint sequences words xml furnace arrays ; [ lookup [ word-name ] [ f ] if* ] keep vocab hash-keys natural-sort "word" list ; -: word-source ( -- ) - #! Write the source for the given word from the vocab as HTML. - current-word [ see-help ] when* ; - -: browser-body ( word vocab -- ) - #! Write out the HTML for the body of the main browser page. - - - - - - - - - - - -
"Vocabularies" write "Words" write "Documentation" write
- dup vocab-list - - word-list - word-source
; - : browser-title ( word vocab -- str ) 2dup lookup dup [ 2nip summary ] [ drop nip "IN: " swap append ] if ; +TUPLE: browser word vocab ; + : browse ( word vocab -- ) - #! Display a Smalltalk like browser for exploring words. - 2dup browser-title [ - [ -
- browser-body -
- ] with-html-stream - ] html-document ; + 2dup browser-title + -rot + "browser" render-page ; \ browse { { "word" } { "vocab" "kernel" v-default } } define-action -"browser" "browse" "contrib/furnace" web-app +"browser" "browse" "contrib/furnace/tools" web-app M: word browser-link-href dup word-name swap word-vocabulary \ browse diff --git a/contrib/furnace/tools/browser.fhtml b/contrib/furnace/tools/browser.fhtml new file mode 100644 index 0000000000..d9e269b34e --- /dev/null +++ b/contrib/furnace/tools/browser.fhtml @@ -0,0 +1,22 @@ +<% USING: namespaces furnace:browser words help kernel ; %> + +
+ + + + + + + + + + + +
VocabulariesWordsDocumentation
+ <% "vocab" get vocab-list %> + + <% "word" get "vocab" get word-list %> + + <% "word" get "vocab" get lookup [ see-help ] when* %> +
+
diff --git a/contrib/furnace/tools/help.factor b/contrib/furnace/tools/help.factor index 59ba62dbc2..7257cc3f4b 100644 --- a/contrib/furnace/tools/help.factor +++ b/contrib/furnace/tools/help.factor @@ -15,7 +15,7 @@ USING: furnace help html kernel sequences words strings ; { "topic" "handbook" v-default string>topic } } define-action -"help" "show-help" "contrib/furnace" web-app +"help" "show-help" "contrib/furnace/tools" web-app M: link browser-link-href link-name [ \ f ] unless* dup word? [ diff --git a/contrib/furnace/tools/list.fhtml b/contrib/furnace/tools/list.fhtml new file mode 100644 index 0000000000..a4eed927d8 --- /dev/null +++ b/contrib/furnace/tools/list.fhtml @@ -0,0 +1,14 @@ +<% USING: namespaces kernel html io sequences ; %> + + diff --git a/contrib/httpd/default-responders.factor b/contrib/httpd/default-responders.factor index 4fe148e143..ee1a43011f 100644 --- a/contrib/httpd/default-responders.factor +++ b/contrib/httpd/default-responders.factor @@ -17,7 +17,7 @@ global [ ! Javascript source used by ajax libraries "resources" [ [ - "" resource-path "doc-root" set + "contrib/httpd/resources" resource-path "doc-root" set file-responder ] with-scope ] add-simple-responder diff --git a/contrib/embedded.factor b/contrib/httpd/embedded.factor similarity index 77% rename from contrib/embedded.factor rename to contrib/httpd/embedded.factor index 364aed89bd..bb8edf314e 100644 --- a/contrib/embedded.factor +++ b/contrib/httpd/embedded.factor @@ -1,5 +1,7 @@ +! Copyright (C) 2005 Alex Chapman. +! See http://factorcode.org/license.txt for BSD license. IN: embedded -USING: sequences kernel parser math namespaces io ; +USING: sequences kernel parser math namespaces io html test ; ! if example.fhtml contains: ! @@ -38,7 +40,7 @@ USING: sequences kernel parser math namespaces io ; dup "<%" head? [ get-embedded parse % ] [ - get-text , \ write , + get-text , \ write-html , ] if ; : embedded>factor ( string -- ) @@ -53,20 +55,14 @@ USING: sequences kernel parser math namespaces io ; : eval-embedded ( string -- ) parse-embedded call ; -: with-embedded-file ( filename quot -- ) - [ - file-vocabs - over file set ! so that reload works properly - >r contents r> call - ] with-scope ; - -: parse-embedded-file ( filename -- quot ) - [ parse-embedded ] with-embedded-file ; - : run-embedded-file ( filename -- ) - [ eval-embedded ] with-embedded-file ; + [ + [ + file-vocabs + dup file set ! so that reload works properly + dup contents eval-embedded + ] with-scope + ] assert-depth drop ; : embedded-convert ( infile outfile -- ) [ run-embedded-file ] with-stream ; - -PROVIDE: contrib/embedded ; diff --git a/contrib/httpd/html.factor b/contrib/httpd/html.factor index a3543edc7b..e04838ee8e 100644 --- a/contrib/httpd/html.factor +++ b/contrib/httpd/html.factor @@ -188,21 +188,19 @@ M: html-stream with-stream-table ( grid quot style stream -- ) M: html-stream stream-terpri [
] with-stream* ; : default-css ( -- ) - ; + ; : xhtml-preamble - xml-preamble print - "" print ; + xml-preamble write-html + "" write-html ; : html-document ( title quot -- ) xhtml-preamble swap chars>entities - + write default-css diff --git a/contrib/httpd/load.factor b/contrib/httpd/load.factor index 65d4437fb6..88679f19ea 100644 --- a/contrib/httpd/load.factor +++ b/contrib/httpd/load.factor @@ -1,7 +1,6 @@ USING: io ; -REQUIRES: contrib/calendar contrib/embedded contrib/http -contrib/xml ; +REQUIRES: contrib/calendar contrib/http contrib/xml ; PROVIDE: contrib/httpd { "mime.factor" @@ -12,6 +11,7 @@ PROVIDE: contrib/httpd { "cont-responder.factor" "prototype-js.factor" "html.factor" + "embedded.factor" "file-responder.factor" "default-responders.factor" } { diff --git a/contrib/httpd/prototype-js.factor b/contrib/httpd/prototype-js.factor index 77185973e5..738ae3c347 100644 --- a/contrib/httpd/prototype-js.factor +++ b/contrib/httpd/prototype-js.factor @@ -11,7 +11,7 @@ strings ; : include-prototype-js ( -- ) #! Write out the HTML script tag to include the prototype #! javascript library. - ; diff --git a/contrib/httpd/javascript/prototype.js b/contrib/httpd/resources/prototype.js similarity index 100% rename from contrib/httpd/javascript/prototype.js rename to contrib/httpd/resources/prototype.js diff --git a/contrib/httpd/resources/stylesheet.css b/contrib/httpd/resources/stylesheet.css new file mode 100644 index 0000000000..a1afce7c9f --- /dev/null +++ b/contrib/httpd/resources/stylesheet.css @@ -0,0 +1,4 @@ +a:link { text-decoration: none; color: black; } +a:visited { text-decoration: none; color: black; } +a:active { text-decoration: none; color: black; } +a:hover { text-decoration: underline; color: black; } -- 2.34.1