Coder Social home page Coder Social logo

dzoukr / shaver Goto Github PK

View Code? Open in Web Editor NEW
22.0 22.0 3.0 93 KB

Lightweight F# library for Suave.io web server using Razor engine adding some extra features like template composing, custom return codes or localization resources support.

License: Apache License 2.0

Batchfile 0.85% F# 95.69% HTML 2.29% Shell 1.17%

shaver's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

shaver's Issues

Plans for .NET Core support?

I love the idea of this library and it even seems to fill a need I have very nicely. However, I'm building a .NET Core application and I'm wondering: do you plan to support .NET Core? Razor itself is portable to .NET Core, and there's even another project not unlike this one that uses it: toddams/RazorLight

Error running demo in FSI

So I was going to try this out as I'm looking for a good HTML template engine for Fsharp

Just doing the following example from your read me in FSI

#r "packages/Suave/lib/net40/Suave.dll"
#r "packages/Shaver/lib/net45/Shaver.dll"
#r "packages/RazorEngine/lib/net45/RazorEngine.dll"
#r "packages/Microsoft.AspNet.Razor/lib/net40/System.Web.Razor.dll"

open Suave
open Shaver.Razor

type MyModel = { Message: string }

let app = singlePage "SinglePage.html" { Message = "Hello Shaver"}

startWebServer defaultConfig app

it starts up fine however on running the page I get

[E] 2016-11-17T14:27:17.1187548Z: request failed [Suave.Web.defaultErrorHandler] exn:
System.TypeLoadException: Inheritance security rules violated while overriding member: 'RazorEngine.Compilation.CSharp.CSharpRazorCodeLanguage.CreateCodeGenerator(System.String, System.String, System.String
, System.Web.Razor.RazorEngineHost)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
   at RazorEngine.Compilation.CSharp.CSharpDirectCompilerService..ctor(Boolean strictMode, Func`1 markupParserFactory)
   at RazorEngine.Compilation.DefaultCompilerServiceFactory.CreateCompilerService(Language language)
   at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
   at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at [email protected](Unit unitVar) in C:\Dzoukr\FSharp\Shaver\src\Shaver\Razor.fs:line 52
   at [email protected](AsyncParams`1 args)

[E] 2016-11-17T14:27:17.4312756Z: request failed [Suave.Web.defaultErrorHandler] exn:
System.TypeLoadException: Inheritance security rules violated while overriding member: 'RazorEngine.Compilation.CSharp.CSharpRazorCodeLanguage.CreateCodeGenerator(System.String, System.String, System.String
, System.Web.Razor.RazorEngineHost)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
   at RazorEngine.Compilation.CSharp.CSharpDirectCompilerService..ctor(Boolean strictMode, Func`1 markupParserFactory)
   at RazorEngine.Compilation.DefaultCompilerServiceFactory.CreateCompilerService(Language language)
   at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
   at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at [email protected](Unit unitVar) in C:\Dzoukr\FSharp\Shaver\src\Shaver\Razor.fs:line 52
   at [email protected](AsyncParams`1 args)

Any ideas am I doing something stupid?

How set the template folder?

I'm trying to load a include template but I get the error:

Could not resolve template ~/templates/product.html

I have a suave F# project, where the folders are:

Root
-- static (css, js, etc)
-- templates
---- base.html
---- products.html
---- product.html

Then I try in products.html:

<section class="row">
@foreach(var item in @Model.Products) {
    @Include("~/templates/product.html", item)
}
</section>

So I can render:

    <div class="thumbnail">
        <img src="http://placehold.it/320x220" alt="" />
        <div class="caption">
            <h4 class="pull-right">Silver, Black, Gold, Coffee, Blue</h4>
            <h4><a href="#">@Model.name</a>
            </h4>
            <p>@Model.description</p>
            <a class="btn btn-link" href="#" role="button">Ver</a>
            <a class="btn btn-primary" href="#" role="button">Link</a>
        </div>
    </div>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.