Package detail

lime-razor

limerun400.2.12

An OWIN-JS implementation of the Razor view template engine for the limerun project

limerun, owin-js, middleware, router

readme

limerun lime-razor

Build Status NPM NPM NPM

NPM

About

This is a simple razor view engine in Node.js javascript for OWIN-JS REST framework. It was created for the limerun project.

Installation

$ npm install lime-razor

Credits

This project, including documentation, was forked under MIT license from andyedinborough/RazorJS with various changes throughout to filename and package handling, and so that it that is easier to consume from OWIN-JS, Connect, Koa, and Express middleware.

To date, the raw parsing routines have not been adjusted materially from the RazorJS implementation.

API

A JavaScript implementation of the Razor view engine that aims to be simple and compatible for use both in the browser and in Node--simple enough for templating:

Razor.compile('hello @model.name')({ name: 'world' }) == 'hello world'

As well as a Node view-engine:

// Dependencies
const lime = require('limerun')
    , razor = require('lime-razor')
    , router = require('lime-router')
    , http = require('http');

// Initiate Factories
var route = router();
var app = new owin.app();

// Run Application
app.use(route);
route.get('/', function(){return  razor.renderViewAsync(this, 'index.js.html');});
http.createServer(app.buildHttp()).listen(8000);

Live Demo (of underlying view engine technology)

Try RazorJS in your browser now: http://jsbin.com/imihov/latest

Syntax

Description Code Notes
Code Block
@{ 
    int x = 123; 
    string y = "because.";
}
Expression (Html Encoded)
<span>@model.message</span>
Expression (Unencoded)
<span>
    @html.raw(model.message)
</span>
Combining Text and markup
@@{ 
    model.items.forEach(function(item) {
        <span>@item.Prop</span> 
    }); 
}
Mixing code and Plain text
@if (foo) {
    <text>Plain Text</text> 
}
Mixing code and plain text (alternate)
@if (foo) {
    @:Plain Text is @bar
}
Email Addresses
Hi test@example.com
Razor recognizes basic email format and is smart enough not to treat the @ as a code delimiter
Explicit Expression
<span>ISBN@(isbnNumber)</span>
In this case, we need to be explicit about the expression by using parentheses.
Escaping the @ sign
<span>In Razor, you use the 
@@foo to display the value 
of foo</span>
@@ renders a single @ in the response.
Server side Comment
@
    This is a server side 
    multiline comment 
@
Mixing expressions and text
Hello @title. @name.
Partials
@html.renderPartial('another-view')

Layouts View
@{ this.layout = '_layout'; } 

@section my_section(){
  @:hi!
}

Layout
  @this.renderBody()
  @this.renderSection('my_section')