Git Product home page Git Product logo

razorenginecore.extensions's Introduction

Logo

RazorEngineCore.Extensions

Extensions for RazorEngineCore (ASP.NET Core 3.1.1 Razor Template Engine)

Build status Nuget status

HTML (safe) encoded output by default using RazorEngineCorePageModel or RazorEngineCorePageModel<T>.

RazorEngineCore.Precompiler

Template pre-compiler for RazorEngineCore.

Compile your RazorEngineCore Templates when building your solution/project, thus compiling them during runtime.

Build status Nuget status


Precompiler usage

// Setup the template for the precompiler
[assembly: PrecompiledTemplate("sample", typeof(RazorEngineCorePageModel), "@Model.Name")]

// Using the precompiled template
var resourceTemplate = await PrecompiledTemplate.LoadAsync("sample");
await resourceTemplate.RunAsync(model: someModel);
  • The precompiler tool will run after a build.
  • Scanning the output assemblies for PrecompiledTemplateAttribute.
  • Build the templates and store them in a resource file named RazorEngineCore.templates.

Support for (some) @Html tags with custom RazorEngineCoreHtmlWriter (to reduce external dependencies)

use: @("<div>string</div>")
out: &lt;div&gt;string&lt;/div&gt;

use: @Html.Encode("<div>string</div>")
out: &amp;lt;div&amp;gt;string&amp;lt;/div&amp;gt;

use: @Html.AttributeEncode("<div>string</div>")
out: &amp;lt;div&gt;string&amp;lt;/div&gt;

use: @Html.Raw("<div>string</div>")
out: <div>string</div>

Using the default RazorEngineTemplateBase with @Html will result in an exception The name 'Html' does not exist in the current context.


Extension Methods

For RazorEngine

CompileFromFile(string fileName, ...)
CompileFromFileAsync(string fileName, ...)
CompileFromStream(StreamReader streamReader, ...)
CompileFromStreamAsync(StreamReader streamReader, ...)

For RazorEngineCompiledTemplate<>

These enable direct Model usage w/o the need for the RazorEngineTemplateBase (PageModel) instance.

Run(object model = null)
RunAsync(object model = null)
Run<TModel>(TModel model = null)
RunAsync<TModel>(TModel model = null)

Coming Soon

  • Aditional @Html tags.
  • Unit Tests.
  • And more...

Razor image by Freepik

razorenginecore.extensions's People

Contributors

304notmodified avatar dependabot[bot] avatar wdcossey avatar

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.