Skip to content

Instantly share code, notes, and snippets.

@tonosaman
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonosaman/c24770ad893fb75edc3b to your computer and use it in GitHub Desktop.
Save tonosaman/c24770ad893fb75edc3b to your computer and use it in GitHub Desktop.
WebSharper input formlet with radio button suggestions.
get-package
Id Version Description/Release Notes
-- ------- -------------------------
Microsoft.Bcl 1.1.10 This packages enables projects targeting down-level platforms to use some of the types added in later versions ...
Microsoft.Bcl.Async 1.0.168 This package enables Visual Studio 2012 projects to use the new 'async' and 'await' keywords. This package also...
Microsoft.Bcl.Build 1.0.14 This package provides build infrastructure components so that projects referencing specific Microsoft packages ...
Microsoft.Owin 2.1.0 Provides a set of helper types and abstractions for simplifying the creation of OWIN components.
Microsoft.Owin.Diagnostics 2.1.0 Provides middleware components to assist in developing OWIN-based applications.
Microsoft.Owin.FileSystems 2.1.0 This package contains file system abstractions and implementations.
Microsoft.Owin.Host.HttpLis... 2.1.0 OWIN server built on the .NET Framework's HttpListener class. Currently the default server used for self-hosting.
Microsoft.Owin.Hosting 2.1.0 Provides default infrastructure types for hosting and running OWIN-based applications.
Microsoft.Owin.StaticFiles 2.1.0 This package contains OWIN middleware that handle requests for file system resources including files and direct...
Mono.Cecil 0.9.5.4 Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. I...
Owin 1.0 OWIN IAppBuilder startup interface
WebSharper 3.0.15.92-alpha F#-to-JavaScript compiler and web application framework
Add References
--
HttpMultipartParser.dll
System.Net.dll
System.Web.dll
Sytem.Configuration.dll
System.ServiceModel.dll
System.ServiceMode.Discovery.dll
Id Version Description/Release Notes
-- ------- -------------------------
Microsoft.Owin 3.0.0 Provides a set of helper types and abstractions for simplifying the creation of OWIN components.
Microsoft.Owin.Diagnostics 3.0.0 Provides middleware components to assist in developing OWIN-based applications.
Microsoft.Owin.FileSystems 3.0.0 This package contains file system abstractions and implementations.
Microsoft.Owin.Host.HttpLis... 3.0.0 OWIN server built on the .NET Framework's HttpListener class. Currently the default server used for self-hosting.
Microsoft.Owin.Hosting 3.0.0 Provides default infrastructure types for hosting and running OWIN-based applications.
Microsoft.Owin.StaticFiles 3.0.0 This package contains OWIN middleware that handle requests for file system resources including files and directories.
Mono.Cecil 0.9.5.4 Cecil is a library written by Jb Evain to generate and inspect programs and libraries in the ECMA CIL format. It has full support for generics, and support some debugging symbol format. In simple Engl...
Owin 1.0 OWIN IAppBuilder startup interface
WebSharper 3.0.15.92-alpha F#-to-JavaScript compiler and web application framework
WebSharper.Owin 3.0.8.18-alpha WebSharper Sitelets module for Owin 1.0
module SuggestFormlet
// [References]
// - msdn.microsoft.com/ja-jp/magazine/cc967279.aspx
// - www.websharper.com/question/74314/None/4/redirecting-from-websharper-formlets
open IntelliFactory.WebSharper
module Server =
type Suggests = (string * string) list
[<Rpc>]
let queryA (s: string): Async<Suggests> =
System.Threading.Thread.Sleep(1000)
[ "Church", "1"; "Chompsky", "2"; "Turing", "3"; "Torvalds", "4"; "Curry", "5"; ]
|> List.filter (fst >> fun x -> x.Contains s)
|> async.Return
[<JavaScript>]
module Client =
open IntelliFactory.WebSharper.Formlets
open IntelliFactory.WebSharper.Html.Client
let WithSuggests (a : Async<Server.Suggests>) (f : Server.Suggests -> Formlet<'U>) : Formlet<'U> =
let loadingPane =
Formlet.BuildFormlet <| fun _ ->
let elem = Span [Attr.Class "suggests"]
let observer = new Event<Result<Server.Suggests>>()
async {
let! (x: Server.Suggests) = a
do observer.Trigger (Result.Success x)
return ()
} |> Async.Start
elem, ignore, observer.Publish
Formlet.Replace loadingPane f
let SuggestFormlet : Formlet<string> =
Formlet.Do {
let! str = Controls.Input ""
return! WithSuggests (Server.queryA str) <| fun xs ->
xs
|> Controls.RadioButtonGroup None
|> Formlet.Horizontal
}
|> Validator.IsNotEmpty "Plese select one from suggests."
|> Enhance.WithValidationIcon
|> Enhance.WithFormContainer
type Action =
| Create
module View =
type SuggestHtml() =
inherit Web.Control()
[<JavaScript>]
override this.Body = Client.SuggestFormlet :> _
open IntelliFactory.WebSharper.Html.Server
let Create : Sitelets.Content<Action> =
Sitelets.PageContent <| fun ctx ->
{ Sitelets.Page.Default with
Title = Some @"test"
Body = [Div [new SuggestHtml()]]
}
let Sitelet : Sitelets.Sitelet<Action> = Sitelets.Sitelet.Content "/" Action.Create View.Create
@tonosaman
Copy link
Author

I need to build Self-Host WebSharper for "net40" platform.
But WebSharper.Owin only support "net45".

  • git clone https://github.com/intellifactory/websharper.owin
  • change "project > properties > Application > Target Framework" to ".Net Framework 4"
  • build HttpMultipartParser.dll
  • copy Owin.Sitelets.fs to my project, and commented out codes about cookie.
  • install several packages by nuget and add references. (@see "packages for net40")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment