RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

Upgrade to support v3 language (e.g. local functions)

Open conficient opened this issue 5 years ago • 5 comments

The current RazorLight (excellent library, thank you!) supports the Razor 2.2 language syntax.

With ASP.NET Core 3.0 an updated language syntax and base library 3.0.0 and 3.1.0 have been introduced with Microsoft.AspNetCore.Razor.Language - is there any plan to upgrade RazorLight to support this?

Example of new language feature: local functions (a @Helper replacement)

<div>
@Hello()
</div>

@functions 
{
   void Hello() 
   {
       <p>Hello world</p>
   }
}

conficient avatar Dec 30 '19 10:12 conficient

tl;dr: If you want to accept a PR, I'll review, but please include tests. Thank you.

Long answer:

The current RazorLight (excellent library, thank you!) supports the Razor 2.2 language syntax.

How did you determine it supports the Razor 2.2 language syntax?

It's called RazorLight for a reason: It's a sub-set of Razor. There are likely features missing, even from the Razor 2.2 language syntax.

is there any plan to upgrade RazorLight to support this?

It's an open source library and not a business - nothing is "planned". The original author, Ivan Balan, has been working on other projects while I help maintain the library. I'm happy to accept PRs, but I personally don't have any use for local functions in my projects, and never will, because they're not unit testable. I'd rather have static methods on a static class instead, because I can unit test those.

jzabroski avatar Dec 30 '19 14:12 jzabroski

Thanks for the reply - yes I'll try to submit a PR for the upgrade. I tried to create a Razor view with a @functions block and a method that contained HTML (like the old '@helper' syntax) and the template compilation step failed, so this is why I assumed it only supported 2.2 syntax. The 'helper' method was introduced in .NET Core 3.0

conficient avatar Dec 31 '19 12:12 conficient

The way Razor works internally, and it's changed a bit from .net core version to version, is it's basically a set of plug-ins called directives (ugh - hate the angular-like vocabulary) and these directives help process "chunks" of text. Dave Glick, who maintains Wyam.io (a great static site generator), has written some blog posts about the internals: https://daveaglick.com/posts/the-bleeding-edge-of-razor

jzabroski avatar Dec 31 '19 14:12 jzabroski

Have you had a chance to create a PR, @conficient? :)

toddams avatar Jan 14 '20 13:01 toddams

Sorry work commitments since everyone came back has put it on the back burner. Feel free to close this issue if you wish.

conficient avatar Jan 14 '20 16:01 conficient