From 0b3a34d0c8dcc72aff8c1736fef8ceace4bc861c Mon Sep 17 00:00:00 2001 From: Chris Double Date: Mon, 14 Feb 2005 21:44:15 +0000 Subject: [PATCH] add browser style to words to allow browsing source. add browser and cont-responder to factor httpd. add cont-responder tutorial to main doc dicretory. mention location of cont-test.factor in tutorial. change defauly startup location of browser. --- .../cont-responder/cont-numbers-game.factor | 1 - contrib/cont-responder/eval-responder.factor | 5 ++-- .../live-updater-responder.factor | 3 +- contrib/cont-responder/load.factor | 28 +++++++++++-------- contrib/cont-responder/todo-example.factor | 1 - library/bootstrap/boot-stage2.factor | 2 ++ library/httpd/default-responders.factor | 4 +++ library/httpd/html.factor | 21 ++++++++++++-- library/io/vocabulary-style.factor | 16 ++++++++++- 9 files changed, 58 insertions(+), 23 deletions(-) diff --git a/contrib/cont-responder/cont-numbers-game.factor b/contrib/cont-responder/cont-numbers-game.factor index 598de12b8a..de8293aaba 100644 --- a/contrib/cont-responder/cont-numbers-game.factor +++ b/contrib/cont-responder/cont-numbers-game.factor @@ -39,7 +39,6 @@ USE: random USE: parser USE: html USE: cont-responder -USE: cont-utils USE: stdio USE: namespaces diff --git a/contrib/cont-responder/eval-responder.factor b/contrib/cont-responder/eval-responder.factor index b769f95779..d2c02418da 100644 --- a/contrib/cont-responder/eval-responder.factor +++ b/contrib/cont-responder/eval-responder.factor @@ -26,7 +26,6 @@ IN: eval-responder USE: html USE: cont-responder -USE: cont-utils USE: kernel USE: stdio USE: namespaces @@ -110,7 +109,7 @@ USE: logging #! of the given word. dup dup [ - "responder" "inspect" put + "responder" "browser" put @@ -186,7 +185,7 @@ USE: logging #! All output should go to a string which is returned on the #! callstack along with the resulting datastack as a list. [ - "inspect" "responder" set + "browser" "responder" set 1024 dup >r [ do-eval ] with-stream r> stream>str diff --git a/contrib/cont-responder/live-updater-responder.factor b/contrib/cont-responder/live-updater-responder.factor index 1db05950cb..aad1ef7e19 100644 --- a/contrib/cont-responder/live-updater-responder.factor +++ b/contrib/cont-responder/live-updater-responder.factor @@ -31,7 +31,6 @@ USE: html USE: words USE: stdio USE: kernel -USE: cont-utils USE: cont-responder USE: prettyprint @@ -39,7 +38,7 @@ USE: prettyprint #! Given a string that is a factor word, show the #! aporpos of that word. [ - "responder" "inspect" put + "responder" "browser" put
 
         stdio get  [   
           apropos.
diff --git a/contrib/cont-responder/load.factor b/contrib/cont-responder/load.factor
index 967a089a0f..d25f24ed15 100644
--- a/contrib/cont-responder/load.factor
+++ b/contrib/cont-responder/load.factor
@@ -33,19 +33,23 @@ USE: stdio
 
 USE: parser
 
-: l1  
-  "cont-responder.factor" run-file 
-  "cont-utils.factor" run-file ;
-: l2 
+: l1 
   "cont-examples.factor" run-file 
   "cont-numbers-game.factor" run-file ;
-: l3 "todo.factor" run-file ;
-: l4 "todo-example.factor" run-file ;
-: l5 "live-updater.factor" run-file ;
-: l6 "eval-responder.factor" run-file ;
-: l7 "live-updater-responder.factor" run-file ;
-: l8 "browser.factor" run-file ;
-: l9 "cont-testing.factor" run-file ;
-: la ;
+: l2 "todo.factor" run-file ;
+: l3 "todo-example.factor" run-file ;
+: l4 "live-updater.factor" run-file ;
+: l5 "eval-responder.factor" run-file ;
+: l6 "live-updater-responder.factor" run-file ;
+: l7 "cont-testing.factor" run-file ;
+: l8 
+  #! Use for reloading and testing changes to browser responder
+  #! in factor core.
+  "../../library/httpd/browser-responder.factor" run-file ;
+: l9
+  #! Use for reloading and testing changes to cont responder
+  #! in factor core.
+  "../../library/httpd/cont-responder.factor" run-file ;
+DEFER: la
 : la [ 8888 httpd ] [ dup . flush [ la ] when* ] catch ;
 : lb [ la "httpd thread exited.\n" write flush ] in-thread  ;
diff --git a/contrib/cont-responder/todo-example.factor b/contrib/cont-responder/todo-example.factor
index 591878f9f3..a79b0b46c1 100644
--- a/contrib/cont-responder/todo-example.factor
+++ b/contrib/cont-responder/todo-example.factor
@@ -29,7 +29,6 @@
 IN: todo-example
 USE: cont-responder
 USE: html
-USE: cont-utils
 USE: html
 USE: stdio
 USE: strings
diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor
index cf1f2a061b..4e839a3f1d 100644
--- a/library/bootstrap/boot-stage2.factor
+++ b/library/bootstrap/boot-stage2.factor
@@ -119,6 +119,8 @@ USING: kernel lists parser stdio words namespaces ;
     "/library/httpd/test-responder.factor"
     "/library/httpd/quit-responder.factor"
     "/library/httpd/resource-responder.factor"
+    "/library/httpd/cont-responder.factor"
+    "/library/httpd/browser-responder.factor"
     "/library/httpd/default-responders.factor"
 
     "/library/tools/jedit.factor"
diff --git a/library/httpd/default-responders.factor b/library/httpd/default-responders.factor
index 39cc7c89d4..35b8ee86b1 100644
--- a/library/httpd/default-responders.factor
+++ b/library/httpd/default-responders.factor
@@ -36,6 +36,8 @@ USE: inspect-responder
 USE: quit-responder
 USE: file-responder
 USE: resource-responder
+USE: cont-responder
+USE: browser-responder
 
 #! Remove all existing responders, and create a blank
 #! responder table.
@@ -68,4 +70,6 @@ global [  "httpd-responders" set ] bind
     [ resource-responder ] "get" set
 ] extend add-responder
 
+"browser" [ f browser-responder ] install-cont-responder
+
 "file" set-default-responder
diff --git a/library/httpd/html.factor b/library/httpd/html.factor
index 63946c13d1..6ad7e251f0 100644
--- a/library/httpd/html.factor
+++ b/library/httpd/html.factor
@@ -77,6 +77,19 @@ url-encoding presentation generic ;
         call
     ] ifte* ;
 
+: browser-link-href ( style -- href )
+    dup "browser-link-word" swap assoc url-encode
+    swap "browser-link-vocab" swap assoc url-encode
+    "responder" get url-encode
+    [ "/responder/" , , "/?vocab=" , , "&word=" , , ] make-string ;
+
+: browser-link-tag ( style quot -- style )
+    over "browser-link-word" swap assoc [
+         call 
+    ] [
+        call
+    ] ifte ;
+
 : icon-tag ( string style quot -- )
     over "icon" swap assoc dup [
         
@@ -93,9 +106,11 @@ M: html-stream fwrite-attr ( str style stream -- )
     wrapper-stream-scope [
         [
             [
-                [ drop chars>entities write ] span-tag
-            ] file-link-tag
-        ] icon-tag
+                [
+                    [ drop chars>entities write ] span-tag
+                ] file-link-tag
+            ] icon-tag
+        ] browser-link-tag
     ] bind ;
 
 C: html-stream ( stream -- stream )
diff --git a/library/io/vocabulary-style.factor b/library/io/vocabulary-style.factor
index 7226b87c3c..8d16f17ebd 100644
--- a/library/io/vocabulary-style.factor
+++ b/library/io/vocabulary-style.factor
@@ -40,8 +40,22 @@ USE: words
 : set-vocab-style ( style vocab -- )
     >r default-style append r> "vocabularies" style set-hash ;
 
+: browser-styles ( word -- style )
+    #! Return the style values for the HTML word browser
+    dup word-vocabulary [ 
+        swap word-name "browser-link-word" swons 
+        swap "browser-link-vocab" swons 
+        2list
+    ] [
+        drop [ ]  
+    ] ifte* ;
+
 : word-style ( word -- style )
-    word-vocabulary [ vocab-style ] [ default-style ] ifte* ;
+    dup browser-styles swap word-vocabulary [ 
+        vocab-style 
+    ] [ 
+        default-style 
+    ] ifte* append ;
 
  "vocabularies" set-style
 
"Source" write
[ [ parse ] [ [ "No such word" write ] [ car see ] ifte ] catch ] with-simple-html-output