RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core

APACHE-2.0 License

Stars
1.5K

Bot releases are visible (Hide)

RazorLight - 1.1.0

Published by toddams over 7 years ago

  • Fixed bug with Configuration.Namespace not applied to the template
  • Downgrade dependency on Codeanalysis.CSharp to 1.3.0 to avoid nuget version conflicts with ASP.NET MVC
RazorLight - 1.0.1

Published by toddams over 7 years ago

What's new

  • #49 TemplateCompilationException now includes line and column number where an error occured
  • #46 Added new overload for Parse() method. Now you can set a PreCenderCallback for each page individually. (Before you could only add callbacks to IEngineConfiguration that are applied for each page)

Bug fixes

  • Fix #47 (ExpandoObject as model type throws RuntimeBinderException)
RazorLight - 1.0.0

Published by toddams over 7 years ago

What's new:

  • Update nuget packages to 1.1
  • Minor bug fixes
RazorLight - 1.0.0-rc2

Published by toddams over 7 years ago

What's new:

  • Project migrated to MSBuild / *.csproj
  • For the convenience, compilation errors are now shown in Exception Message. No need to inspect CompilationErrors.
  • EngineFactory now returns IRazorLightEngine (was RazorLightEngine)
  • Minor bug fixes
RazorLight - 1.0.0-rc1

Published by toddams about 8 years ago

Out first Release Candidate!

This release comes out with some improvements and refactorings. We are planning to roll up a stable version soon

  • ParseString() is extracted to an extension method (under RazorLight.Extensions namespace)
  • PreRenderCallbacks moved to IEngineConfiguration
  • While searching for Layout file - instead of InvalidOperationException - RazorLightException is thrown
  • No more AggregateExceptions. I'm erasing annoying AggregateExceptions from code. Please, open an issue If you see it again somewhere
RazorLight -

Published by toddams about 8 years ago

This small release brings fixed for #15 and #18

RazorLight -

Published by toddams about 8 years ago

Full .NET Support arrived!

  • Now you can use RazorLight with a Full .NET Framework v4.5.1 and higher

ASP.NET MVC Core integration

New package brings ASP.NET MVC Core integration which allows you to inject services into your templates via built in Dependency Injection container

  • Add package

    Install-Package RazorLight.MVC

  • Add RazorLight services in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
     ....
    services.AddRazorLight("/Views"); // <- This one
     ....
}
  • Retreive IRazorLightEngine instance from controller constructor
private readonly IRazorLightEngine engine;

public HomeController(IRazorLightEngine engine)
{
    this.engine = engine;
}
  • Inject services to your templates
@inject MyProject.TestViewModel myModel

Small fixes

@Include now works in Layout and ViewStart pages as well (#12)

RazorLight -

Published by toddams about 8 years ago

This release brings you Include feature

Example

@model MyProject.TestViewModel
<div>
    Hello @Model.Title
</div>

@{ await IncludeAsync("SomeView.cshtml", Model); }

First argument takes a key of the template to resolve, second argument is a model of the view (can be null)

RazorLight -

Published by toddams about 8 years ago

New features

  • Use Raw() method to output model value without encoding ( #7 )

Changes

  • Fix #5
  • Rename PageCacheItem and PageCacheResult to PageLookupItem and PageLookupResult
  • Removed IMemoryCache from DefaultPageLookup
  • Added new IPageFactory with caching - CachingPageFactory
  • PageLookupResult default constructor removed. Use PageLookupResult.Failed instead
RazorLight -

Published by toddams about 8 years ago

Changes

  • Pass ITemplateConfiguration to EngineFactory #3
IEngineConfiguration config = EngineConfiguration.Default;
config.Namespaces.Add("My.Custom.Namespace");
var engine = EngineFactory.CreatePhysical("root/folder", config);
  • Pass a ViewBag to Parse method. #4

Note: Viewbag is accessible both from the template page and it's layout.

Code

var model = new MyModel()
{
    Title = "Test"
};

//create a dynamic viewbag
dynamic viewBag = new ExpandoObject();
viewBag.DataForLayoutPage = "Hello world";

string result = engine.Parse("key", model, viewBag);

Template

@model MyViewModel

@{
    Layout = "layout_key";
}

<div>Hello @ViewBag.Title</div>
RazorLight -

Published by toddams about 8 years ago

This release brings Layout, _Viewstart pages support, sections and custom template namespaces. API is completely reworked.

New features

  • Use ITemplateManager(string key) to resolve a templates. For files, Key - is a relative path to the view. For embeded resources - it's a name of the resourse.
  • Layout pages
@model MyModel
@{
    Layout = "_Layout.cshtml"; // <- This is a key of the layout page
}
  • Sections

Layout.cshtml:

@RenderSection("section-name", required : false)

View.cshtml:

@section section-name
{
    <div>It is a content inside a section</div>
}
  • ViewStart pages. (Same as with ASP.NET MVC.)
  • Custom namespaces. To add custom namespaces to your templates, use ITemplateConfiguration.Namespaces (ISet<string)

Breaking changes:

  • ConfigurationOptions removed. Use ITemplateConfiguration instead.
  • AdditionalMetadataReferences and LoadDependenciesFromEntryAssembly are removed. Use IMetadataResolver to provide an additional metadata references to RazorLight compilation service
  • Parameterless constructor of RazorLightEngine was removed. Use static EngineFactory class instead.

Before:

var config = new ConfigurationOptions() { ViewsFolder = "C:/path/to/folder" }
var engine = new RazorLightEngine(config);
string result = engine.ParseFile("Test.cshtml", model);

After:

var engine = EngineFactory.CreatePhysical("C:/path/to/folder");
string result = engine.Parse("Test.cshtml", model);
  • ParseFile method is removed. Use Parse method instead with a FileSystemTemplateManager to resolve a template (ParseString method is still there)

Notes

  • To comply with Nuget versioning guidlines, version was changes from 0.0.1 to 1.0.0-beta1
  • Package is under active development and there might be breaking changes in a new releases. I expect to ship 3-4 betas and then go to stable, sorry for inconvenience, to create something good you must create at least something and then find the room for improvements
RazorLight - v0.0.1

Published by toddams about 8 years ago

First release with initial features:

  • Parse string
  • Parse files
  • Caching
  • Recompile cached view on file content change
  • Anonymous types models
  • Strongly typed views
  • Loading models from extenral assemblies
Package Rankings
Top 9.59% on Proxy.golang.org
Badges
Extracted from project README
NuGet Pre Release NuGet downloads Join the chat at https://gitter.im/gitterHQ/gitter
Related Projects