diff --git a/extra/html/components/components-tests.factor b/extra/html/components/components-tests.factor index 0bd5410a3b..d09f8b6b42 100644 --- a/extra/html/components/components-tests.factor +++ b/extra/html/components/components-tests.factor @@ -1,6 +1,7 @@ IN: html.components.tests -USING: html.components tools.test kernel io.streams.string -io.streams.null accessors ; +USING: tools.test kernel io.streams.string +io.streams.null accessors inspector html.streams +html.components ; [ ] [ blank-values ] unit-test @@ -145,3 +146,25 @@ M: link-test link-href drop "http://www.apple.com/foo&bar" ; [ "arbitrary markup for the win!" ] [ [ "html" html render ] with-string-writer ] unit-test + +[ ] [ "int x = 4;" "code" set-value ] unit-test + +[ ] [ "java" "mode" set-value ] unit-test + +[ "int x = 4;\n" ] [ + [ "code" "mode" >>mode render ] with-string-writer +] unit-test + +[ ] [ "-foo\n-bar" "farkup" set-value ] unit-test + +[ "" ] [ + [ "farkup" farkup render ] with-string-writer +] unit-test + +[ ] [ { 1 2 3 } "object" set-value ] unit-test + +[ t ] [ + [ "object" inspector render ] with-string-writer + [ "object" value [ describe ] with-html-stream ] with-string-writer + = +] unit-test diff --git a/extra/html/components/components.factor b/extra/html/components/components.factor index df1d1faa72..9c762eaa3a 100644 --- a/extra/html/components/components.factor +++ b/extra/html/components/components.factor @@ -4,7 +4,7 @@ USING: accessors kernel namespaces io math.parser assocs classes classes.tuple words arrays sequences splitting mirrors hashtables combinators continuations math strings fry locals calendar calendar.format xml.entities validators -html.elements ; +html.elements html.streams xmode.code2html farkup inspector ; IN: html.components SYMBOL: values @@ -144,6 +144,27 @@ M: link render* link-title object>string escape-string write ; +! XMode code component +TUPLE: code mode ; + +: ( -- code ) + code new ; + +M: code render* + [ string-lines ] [ drop ] [ mode>> value ] tri* htmlize-lines ; + +! Farkup component +SINGLETON: farkup + +M: farkup render* + 2drop string-lines "\n" join convert-farkup write ; + +! Inspector component +SINGLETON: inspector + +M: inspector render* + 2drop [ describe ] with-html-stream ; + ! HTML component SINGLETON: html