Commit 97273d05 authored by Michael Hanus 's avatar Michael Hanus

Foreign HTML integrator changed to html2

parent 71add747
......@@ -11,17 +11,18 @@ import HTML.Base
Remark:
The integrated code ``html ...'' expands to a list of HTML expressions,
i.e., to an expression of type [HtmlExp].
i.e., to an expression of type `[a]` where `a` is an instance of class `HTML`.
A Curry expression enclosed with {...} inside the integrated code
must be of type String and is inserted as (HTML-quoted) text.
A Curry expression enclosed with {{...}} inside the integrated code
must be of type HtmlExp and is inserted as an HTML element.
must be of type `a`, where `a` is an instance of class `HTML`,
and is inserted as an HTML element.
-}
test1 :: String -> IO ()
test1 name = putStrLn $ showHtmlExps ``html
test1 name = putStrLn $ showBaseHtmls ``html
<html>
<head>
......
......@@ -12,35 +12,42 @@ import HTML.Base
Remark:
The integrated code ``html ...'' expands to a list of HTML expressions,
i.e., to an expression of type [HtmlExp].
i.e., to an expression of type `[a]` where `a` is an instance of class `HTML`.
A Curry expression enclosed with {...} inside the integrated code
must be of type String and is inserted as (HTML-quoted) text.
A Curry expression enclosed with {{...}} inside the integrated code
must be of type HtmlExp and is inserted as an HTML element.
must be of type `a`, where `a` is an instance of class `HTML`,
and is inserted as an HTML element.
-}
main :: IO HtmlForm
main = return $ form "Question" $
-- Example: a form with a text input field and two submit buttons.
revDupForm :: HtmlFormDef ()
revDupForm = simpleFormDef
``html
Enter a string: {{textfield tref ""}}
Enter a string: {{textField tref ""}}
<hr>
{{button "Reverse string" revhandler}}
{{button "Duplicate string" duphandler}}''
where
tref free
revhandler env = return $ form "Answer"
revhandler env = return $ page "Answer"
``html <h1>Reversed input: {reverse (env tref)}''
duphandler env = return $ form "Answer"
duphandler env = return $ page "Answer"
``html
<h1>
Duplicated input:
{env tref ++ env tref}''
-- main HTML page containing the form
main :: IO HtmlPage
main = return $ page "Question" $
``html
<h1>This is an example form:
{{formElem revDupForm}}''
-- Install the CGI program by:
-- curry makecgi -cpm -o ~/public_html/revdup.cgi RevDup
-- Install with:
-- > cypm exec curry2cgi -o ~/public_html/cgi-bin/revdup.cgi RevDup
......@@ -8,7 +8,7 @@
import HTML.Base
import Test.Prop
htmlTest1 :: String -> [HtmlExp]
htmlTest1 :: String -> [BaseHtml]
htmlTest1 name = ``html
<html>
......@@ -23,29 +23,30 @@ htmlTest1 name = ``html
<h2>{reverse name}
Bye!''
htmlDoc1 :: [HtmlExp]
htmlDoc1 :: [BaseHtml]
htmlDoc1 =
[HtmlStruct "html" []
[HtmlStruct "head" []
[HtmlStruct "title" [] [HtmlText "Simple Test\n"]],
HtmlStruct "body" []
[HtmlStruct "h1" []
[HtmlText "Hello ", HtmlText "Joe", HtmlText "!"],
HtmlStruct "p" [] [HtmlText "Bye!\n"],
HtmlStruct "p" [] [HtmlText "Bye!\n"],
HtmlStruct "h2" []
[HtmlText "eoJ", HtmlText "\n"],
HtmlText "Bye!"]]]
[htmlStruct "html" []
[htmlStruct "head" []
[htmlStruct "title" [] [htmlText "Simple Test\n"]],
htmlStruct "body" []
[htmlStruct "h1" []
[htmlText "Hello ", htmlText "Joe", htmlText "!"],
htmlStruct "p" [] [htmlText "Bye!\n"],
htmlStruct "p" [] [htmlText "Bye!\n"],
htmlStruct "h2" []
[htmlText "eoJ", htmlText "\n"],
htmlText "Bye!"]]]
------------------------------------------------------------------------------
-- Partial equality on HTML documents for testing.
instance Eq HtmlExp where
instance Eq BaseHtml where
hexp1 == hexp2 = case (hexp1,hexp2) of
(HtmlText s, HtmlText t) -> s == t
(HtmlStruct t ats hes, HtmlStruct t' ats' hes') ->
(BaseText s, BaseText t) -> s == t
(BaseStruct t ats hes, BaseStruct t' ats' hes') ->
t==t' && ats==ats' && hes == hes'
_ -> error "HTML.==: cannot compare cgi refs or handlers"
_ -> error "BaseHTML.==: cannot compare actions"
------------------------------------------------------------------------------
test_Html_code :: Prop
test_Html_code = always (htmlTest1 "Joe" == htmlDoc1)
......@@ -19,7 +19,7 @@
"fl-parser" : ">= 1.0.0",
"flatcurry" : ">= 2.0.0",
"frontend-exec" : ">= 0.0.1",
"html" : ">= 2.0.0, < 3.0.0",
"html2" : ">= 1.0.0",
"printf" : ">= 0.0.1",
"regexp" : ">= 1.1.0",
"searchtree" : ">= 0.0.1",
......
......@@ -43,11 +43,11 @@ translateHTML start input =
showTree :: Tree -> String
showTree (Tree (Content ds) _) = intercalate "," (map showCont ds)
showTree (Tree (Element a par) ys) =
"HtmlStruct " ++ show a ++ " " ++ showAttrs par ++ " "
++ showStringList (map showTree ys)
"htmlStruct " ++ show a ++ " " ++ showAttrs par ++ " "
++ showStringList (map showTree ys)
showCont :: Text -> String
showCont (Raw s) = "HtmlText " ++ show s ++ ""
showCont (Raw s) = "htmlText " ++ show s ++ ""
showCont (ExpT s) = "htxt (" ++ s ++ ")"
showCont (ExpC s) = "(" ++ s ++ ")"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment