Devmachinist.Xavier
7.0.5
dotnet add package Devmachinist.Xavier --version 7.0.5
NuGet\Install-Package Devmachinist.Xavier -Version 7.0.5
<PackageReference Include="Devmachinist.Xavier" Version="7.0.5" />
paket add Devmachinist.Xavier --version 7.0.5
#r "nuget: Devmachinist.Xavier, 7.0.5"
// Install Devmachinist.Xavier as a Cake Addin
#addin nuget:?package=Devmachinist.Xavier&version=7.0.5
// Install Devmachinist.Xavier as a Cake Tool
#tool nuget:?package=Devmachinist.Xavier&version=7.0.5
Xavier Framework
The Xavier Framework is a powerful framework designed to facilitate the development of web applications by providing support for multiple programming languages, including C#, Python, and JavaScript. It allows you to define and process template strings in both C# and JavaScript, ensuring seamless integration and efficient development. Xavier also offers server-side rendering capabilities, enabling full-page rendering for enhanced performance and SEO.
Table of Contents
Installation
To use Xavier, follow these steps using the cli:
- dotnet add package Devmachinist.Xavier
- or dotnet add package Devmachinist.Xavier.AOT
Usage
Template Syntax
The Xavier Framework recognizes three types of languages:
x{ ... }x
- This syntax denotes a C# execution. Any code within these tags will be interpreted as C# code.{{ ... }}
- This syntax represents as JavaScript in a script tag. Code within these tags will be interpreted as JavaScript code.py{ ... }py
- This syntax represents as python 3.4 IronPython. Code within these tags will be interpreted as python code.
Creating a Component
To create a component using the Xavier Framework, follow these steps:
- Create a new file with the
.xavier
extension (e.g.,MyComponent.xavier
). - Define your component within the
.xavier
file using the appropriate afformentioned syntax. - Implement the code behind for the component in a separate file with the same name as the component and a
.xavier.cs
extension (e.g.,MyComponent.xavier.cs
). Use the base class provided by Xavier Framework and match it with the component's code behind file.
Server-Side Rendering
Xavier Framework supports server-side rendering, which provides benefits like improved performance and search engine optimization (SEO). To enable server-side rendering for Xavier pages, follow these steps:
- Configure your web application to use Xavier Framework.
- Use the
app.MapXavierNodes
method in your application's configuration to map the Xavier nodes to specific routes. This method specifies the URL pattern and the destination directory for Xavier pages. - Set the static fallback for Xavier:
<<<<<<< HEAD
memory.StaticFallback("c:/fallback/index.html");
//app build
app.MapXavierNodes("{controller=Home}/{action=Index}/{id?}", Environment.CurrentDirectory + "/Pages", memory);
=======
Xavier.Memory.StaticFallback("c:/fallback/index.html");
app.MapXavierNodes("{controller=Home}/{action=Index}/{id?}", Environment.CurrentDirectory + "/Pages", memory);
>>>>>>> 77bcdb0bd50646e5000d11855349045f0efcf2f8
Initialization
To initialize Xavier in a .NET app, follow these steps:
- Import the required namespace:
using Xavier;
//and
using Xavier.AOT;
Call the Init
method to initialize Xavier with the desired parameters. This method builds your assembly into the specified destination. The last part of the destination path should have a .js
extension.
<<<<<<< HEAD
var memory = new Xavier.Memory();
=======
var memory = new Memory();
>>>>>>> 77bcdb0bd50646e5000d11855349045f0efcf2f8
await memory.Init(root, destination, assembly);
Or with AOT, pass in your memory object without calling memory.Init()...
<<<<<<< HEAD
Parallel.Invoke(async () =>
{
await aot.Init(
memory,
Environment.CurrentDirectory,
Environment.CurrentDirectory + "/Live/Xavier",
null,
typeof(Program).Assembly
);
});
=======
var memory = new Memory();
var aot = new XAOT();
await aot.Init(memory,root,destination,assembly);
>>>>>>> 77bcdb0bd50646e5000d11855349045f0efcf2f8
Examples
Here's an example of a .xavier
file that demonstrates the usage of template strings in C# and JavaScript within the Xavier Framework:
<div id="${this.target}auth">
</div>
{{
let username = "";
var target = '${this.target}'
<<<<<<< HEAD
}}
x{
// C# Code here
var Items = new[]{"item1","item2","item3"};
@foreach( var k in items){
<div>
@k
</div>
}
}x
=======
// More JavaScript code here
}}
// C# code here
x{
var items = new[]{"item1","item2","item3"};
@foreach( var k in items){
<div>
@k
</div>
}
}x
>>>>>>> 77bcdb0bd50646e5000d11855349045f0efcf2f8
Here is the code behind required for each component.
//this file should be named MyComponent.xavier.cs
using Xavier;
namespace MyNamespace{
public partial class MyComponent : XavierNode
{
new public bool? ShouldRender = true;
<<<<<<< HEAD
=======
>>>>>>> 77bcdb0bd50646e5000d11855349045f0efcf2f8
public MyComponent(XavierNode xavier) : base(xavier){
}
public MyComponent(){
}
}
}
Information
- Xavier is experimental and should be treated as such. <<<<<<< HEAD =======
- Known to cause thread pool starvation while using Devmachinist.Xavier.AOT . Simply stop the app when done testing and use the memory.Init(root,destination,assembly) for production.
77bcdb0bd50646e5000d11855349045f0efcf2f8
Contributing
We welcome contributions from the community to enhance the Xavier Framework. If you find any issues, have suggestions for improvements, or would like to add new features, please submit a pull request.
License
The Xavier Framework is released under the MIT License. Feel free to use, modify, and distribute it according to the terms of this license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- IronPython (>= 3.4.0)
- IronPython.StdLib (>= 3.4.0)
- Microsoft.EntityFrameworkCore (>= 7.0.4)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.4)
- Microsoft.Extensions.Configuration.FileExtensions (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Primitives (>= 7.0.0)
- Microsoft.VisualStudio.Web.CodeGeneration.Design (>= 7.0.5)
- Microsoft.VisualStudio.Web.CodeGeneration.Utils (>= 7.0.5)
- System.CodeDom (>= 7.0.0)
- System.Net.Http.Json (>= 7.0.1)
- System.ServiceModel.Primitives (>= 6.0.0-preview1.23060.3)
- System.Text.Encodings.Web (>= 7.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Devmachinist.Xavier:
Package | Downloads |
---|---|
Devmachinist.Xavier.AOT
Package Description |
|
Devmachinist.Xavier.AspNetCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.