Git Product home page Git Product logo

bibaviewengine's Introduction

BibaViewEngine

Aspnet core view engine

Overview

Biba view engine is a new approach of data displaying. Its a brand new engine written from scratch. It is pretty simple have some similarness with angularjs or reactjs so if you familiar with those frameworks it will be easy for you to understand how it works

Currently it is working with netcoreapp2.0 and SDK 2.0.0

Docs

You can look at working sample with router

First you need to add Nuget.config file to the root project directory with the next source

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Daviator storm packages" value="https://www.myget.org/F/daviatorstorm/api/v3/index.json" />
  </packageSources>
</configuration>

Then add package reference to csproj file

<PackageReference Include="BibaViewEngine" Version="0.0.5" />

Restore packages

To make a Biba work you must to add Services and pipe to you application in Startup.cs file. We will craete AppComponent later on

Example:

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddBibaViewEngine<AppComponent>();

    ...
}

It will add some main Biba engine services and AppComponent to application DI

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    ...

    app.UseStaticFiles();
    app.UseBibaViewEngine();

    ...
}

It will add Biba engine middlewares and features to main application pipeline

By defalt, when application starts Biba engine copy biba.min.js file to wwwroot directory

Now you can add your components

Components

To create a component first create a folder calls Client in project root directory. There you can create your components

Add a component called AppComponent.cs with base constructor. Each component injecting to DI

Write a next code to that file

using BibaViewEngine;
using BibaViewEngine.Compiler;

namespace YourNamespace.Client
{
    public class AppComponent : Component
    {
        public AppComponent(BibaCompiler bibaCompiler)
            : base(bibaCompiler)
        {
        }
    }
}

Note

Every component must inherit BibaViewEngine.Component class, because BibaEngine searches component classes by this base class and it have a base implementation behavior that needed for every component

Then add a template called AppComponent.html in same location as AppComponnet.cs and write some html code there

<div>
    <h1>Hello World!!!</h1>
</div>

Then add you app component like this <app></app> to index.html. Then you must force engine to start compilation with code in script tag

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Hello world</title>
</head>
<body>
    <app></app> <!-- Here app component -->
    <script>
        Biba.Start('app');
    </script>
</body>
</html>

After this you can start an application

Data Binding

Simple binding

Lets take a look at the next step - Data Binding. For now, you can bind only simple data, such as nummerics, strings and booleans. Lets see how it works. First modify Client/AppComponent.cs and Client/AppComponent.html

Client/AppComponent.cs
------------------------------------------------------------------
public class AppComponent : Component
{
    public AppComponent(BibaCompiler bibaCompiler)
        : base(bibaCompiler)
    {
    }

    public string HelloWorld { get; set; } = "Hello World!";
}

Client/AppComponent.html
------------------------------------------------------------------
<h1>([HelloWorld])</h1>

And start an application.

Note

Bind properties to html is case sensitive

Simple :)

Component data binding

There is a posibility to send data from parent to child component. For this we need to create another component. Lets call it SimpleBindComponent

Example

Client/SimpleBindComponent.cs
------------------------------------------------------------------
using BibaViewEngine;
using BibaViewEngine.Attributes;
using BibaViewEngine.Compiler;

namespace BibaViewEngineTutorial.Client
{
    public class SimpleBindComponent : Component
    {
        public SimpleBindComponent(BibaCompiler bibaCompiler)
            : base(bibaCompiler)
        {
        }

        [Input]
        public string Message { get; set; }
    }
}

Client/SimpleBindComponent.html
------------------------------------------------------------------
<p>([Message])</p>

For data bindin component-component you need to set an Input attribute for property that you want ot bind. In our example its Message

Then make some modifications in AppComponent.html

Client/AppComponent.cs
------------------------------------------------------------------
using BibaViewEngine;

namespace BibaViewEngineTutorial.Client
{
    public class AppComponent : Component
    {
        public AppComponent(BibaCompiler bibaCompiler)
            : base(bibaCompiler)
        {
        }

        public string HelloWorld { get; set; } = "Hello World!";

        public string Message { get; set; } = "My name is John Doe"; // Added this property
    }
}

Client/AppComponent.html
------------------------------------------------------------------
<h1>([HelloWorld])</h1>
<simplebind message="message"></simplebind> <!-- Added this component -->

Start an application.

Routing

An AddBibaViewEngine() have some parameters: BibaViewEngine.Router.Routes and BibaViewEngine.Models.BibaViewEnginePropperties that are equals to null. Then method to set these to default values

In our application we will create one route and look how it works. For doing that we must to create, for example, Client/MainComponent.cs, Client/MainComponent.html and modify a Startup.cs and wwwroot/index.html

Client/MainComponent.cs
------------------------------------------------------------------
using BibaViewEngine;
using BibaViewEngine.Compiler;

namespace BibaViewEngineTutorial.Client
{
    public class MainComponent : Component
    {
        public MainComponent(BibaCompiler bibaCompiler)
            : base(bibaCompiler)
        {
        }

        public string Message { get; set; } = "My name is John Doe";
    }
}


Client/MainComponent.html
------------------------------------------------------------------
<simplebind message="message"></simplebind>

Then remove message property from AppComponent.cs and remove <simplebind message="message"></simplebind> line from AppComponent.html and the the next line <div router-container></div>. That line means that this is a container for all routes that you will define

So files will looks like this

Client/AppComponent.cs
------------------------------------------------------------------
using BibaViewEngine;

namespace BibaViewEngineTutorial.Client
{
    public class AppComponent : Component
    {
        public string HelloWorld { get; set; } = "Hello World!";
    }
}

Client/AppComponent.html
------------------------------------------------------------------
<h1>([helloworld])</h1>
<div router-container></div>

At last we just have to add a route with MainComponent class in Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    var routes = new Routes
    {
        new BibaRoute { Path = "", Component = typeof(MainComponent) }
    };

    services.AddBibaViewEngine<AppComponent>(routes);
}

Start application

Great! Everything works as we expected

One route is good, but not enough to show what router can. Now we will try to move between routes. For this we must to add another route

Create another one component called ContactComponent.

Client/ListComponent.cs
------------------------------------------------------------------
public class ContactComponent : Component
{
    public ContactComponent(BibaCompiler bibaCompiler)
        : base(bibaCompiler)
    {
    }
}

Client/ListComponent.html
------------------------------------------------------------------
<p>Contact form here</p>

Then add this to routes

public void ConfigureServices(IServiceCollection services)
{
    var routes = new Routes
    {
        new BibaRoute { Path = "", Component = typeof(MainComponent) },
        new BibaRoute { Path = "contact", Component = typeof(ContactComponent) }
    };

    services.AddBibaViewEngine<AppComponent>(routes);
}

And create links for those routes in AppComponent.html

<h1>([helloworld])</h1>

<div>
    <a router-path="">Main</a>
    <a router-path="contact">Contact</a>
</div>

<div router-container></div>

Found a problem? - Post an issue

Want to contribute - write me an email [email protected]

Enjoy :)

bibaviewengine's People

Contributors

daviatorstorm avatar

Stargazers

Dmytro Ostapenko avatar

Watchers

James Cloos avatar Dmytro Ostapenko avatar  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.