Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
/ ReMikus Public archive

ASP.NET Core MVC tag helpers for Laravel Mix and Inertia.js.

License

Notifications You must be signed in to change notification settings

VocaDB/ReMikus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReMikus

ASP.NET Core MVC tag helpers for Laravel Mix and Inertia.js.

Installation

PM> Install-Package VocaDb.ReMikus

Usage

Laravel Mix

Startup.cs:

using VocaDb.ReMikus;

public void ConfigureServices(IServiceCollection services)
{
    services.AddLaravelMix();
}

By using remikus tag helper:

@addTagHelper *, VocaDb.ReMikus

<remikus path="/css/app.css" />
<remikus path="/js/app.js" />

By using dependency injection:

@using VocaDb.ReMikus
@inject LaravelMix LaravelMix

<link rel="stylesheet" href="@LaravelMix.GetVersionedPath("/css/app.css")" />
<script src="@LaravelMix.GetVersionedPath("/js/app.js")"></script>

Inertia.js

HandleInertiaRequests.cs (optional):

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using VocaDb.ReMikus;

public class HandleInertiaRequests
{
    private readonly RequestDelegate _next;

    public HandleInertiaRequests(RequestDelegate next)
    {
        _next = next;
    }

    public async Task InvokeAsync(HttpContext context, LaravelMix laravelMix)
    {
        // shared data
        Inertia.SharedProps = new
        {
            AppName = "VocaDB",
        };

        // asset versioning
        using var md5 = MD5.Create();
        using var stream = File.OpenRead(laravelMix.ManifestPath);
        var hash = await md5.ComputeHashAsync(stream);
        Inertia.VersionSelector = () => BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();

        await _next(context);
    }
}

Startup.cs:

using VocaDb.ReMikus;

public void ConfigureServices(IServiceCollection services)
{
    services.AddInertia();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseMiddleware<HandleInertiaRequests>();/* optional */
    app.UseInertia();
}

Views/App.cshtml:

@addTagHelper *, VocaDb.ReMikus
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <remikus path="/css/app.css" />
    </head>
    <body>
        <inertia model="@Model" />
        <remikus path="/js/app.js" />
    </body>
</html>

EventController.cs:

using VocaDb.ReMikus;

public class EventController : Controller
{
    public IActionResult Details(int id)
    {
        // ...
        return Inertia.Render(new
        {
            Event = new
            {
                event.Id,
                event.Title,
                event.StartDate,
                event.Description,
            },
        });
    }
}

References

About

ASP.NET Core MVC tag helpers for Laravel Mix and Inertia.js.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages