# HG changeset patch # User Adam Chlipala # Date 1241369387 14400 # Node ID 9f2555f06901e5235917744861f439978c18f09e # Parent a8bdd5a0d9b025ea78ebebc893d530af3d58515a upload demo diff -r a8bdd5a0d9b0 -r 9f2555f06901 demo/prose --- a/demo/prose Sun May 03 12:36:25 2009 -0400 +++ b/demo/prose Sun May 03 12:49:47 2009 -0400 @@ -74,6 +74,12 @@

Ur/Web supports a structured approach to Cascading Style Sheets, where each style is a first-class value within a module. This demo shows the importing of an external style sheet with one style. By default, like other Ur/Web entities, the name of the style would be Css_quote. We use the rewrite directive in the .urp file to specify an alternate name for a particular canonical module path. The external style sheet contains a definition of a style with the alternate name that we give.

+upload.urp + +

HTTP file upload is made convenient, via the abstract types blob and file in the standard library. A blob is a binary sequence, and a file combines a blob with MIME type information. An upload form input can be used to accept files from the user.

+ +

In the .urp file for this example, we give a whitelist of MIME types to be accepted. The application will echo back to the user any file he uploads as one of those types. You can try submitting other kinds of files to verify that they are rejected.

+ listShop.urp

This example shows off algebraic datatypes, parametric polymorphism, and functors.

diff -r a8bdd5a0d9b0 -r 9f2555f06901 demo/upload.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/upload.ur Sun May 03 12:49:47 2009 -0400 @@ -0,0 +1,11 @@ +fun echo r = + if blobSize (fileData r.File) > 100000 then + return Whoa! That one's too big. + else + returnBlob (fileData r.File) (blessMime (fileMimeType r.File)) + +fun main () = return +

The Amazing File Echoer!

+ +
Upload a file: +
diff -r a8bdd5a0d9b0 -r 9f2555f06901 demo/upload.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/upload.urp Sun May 03 12:49:47 2009 -0400 @@ -0,0 +1,5 @@ +allow mime text/plain +allow mime image/png +allow mime image/gif + +upload diff -r a8bdd5a0d9b0 -r 9f2555f06901 demo/upload.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demo/upload.urs Sun May 03 12:49:47 2009 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page diff -r a8bdd5a0d9b0 -r 9f2555f06901 src/demo.sml --- a/src/demo.sml Sun May 03 12:36:25 2009 -0400 +++ b/src/demo.sml Sun May 03 12:49:47 2009 -0400 @@ -363,6 +363,20 @@ val fname = OS.Path.joinDirFile {dir = dirname, file = "demo.urp"} val outf = TextIO.openOut fname + + fun filters kind = + app (fn rule : Settings.rule => + (TextIO.output (outf, case #action rule of + Settings.Allow => "allow" + | Settings.Deny => "deny"); + TextIO.output (outf, " "); + TextIO.output (outf, kind); + TextIO.output (outf, " "); + TextIO.output (outf, #pattern rule); + case #kind rule of + Settings.Exact => () + | Settings.Prefix => TextIO.output (outf, "*"); + TextIO.output (outf, "\n"))) in Option.app (fn db => (TextIO.output (outf, "database "); TextIO.output (outf, db); @@ -391,16 +405,8 @@ TextIO.output (outf, " "); TextIO.output (outf, #to rule); TextIO.output (outf, "\n"))) (#rewrites combined); - app (fn rule => - (TextIO.output (outf, case #action rule of - Settings.Allow => "allow" - | Settings.Deny => "deny"); - TextIO.output (outf, " url "); - TextIO.output (outf, #pattern rule); - case #kind rule of - Settings.Exact => () - | Settings.Prefix => TextIO.output (outf, "*"); - TextIO.output (outf, "\n"))) (#filterUrl combined); + filters "url" (#filterUrl combined); + filters "mime" (#filterMime combined); TextIO.output (outf, "\n"); app (fn s =>