Giter Site home page Giter Site logo

thecodejunkie / supersimpleviewengine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grumpydev/supersimpleviewengine

1.0 3.0 0.0 148 KB

Super simple regex based view engine used in Nancy diagnostics and (soon to be) TinyTemplates.

C# 100.00%

supersimpleviewengine's Introduction

Super Simple View Engine

A super simple regex based view engine used in Nancy and (soon to be) TinyTemplates.

Models can either be standard types, or ExpandoObjects (or any other object implementing IDynamicMetaObjectProvider that implements IDictionary<string, object> to access its properties).

Syntax

All commands have an optional semi-colon delimiter which can be used to remove ambiguity. Any [.Parameters] paraneter can be multiple levels deep (e.g. This.Property.That.Property).

Standard variable substitution

Syntax: @Model[.Parameters] Example: Hello @Model.Name Example: Hello @Model.User.Age

Replaces with the string representation of the parameter, or the model itself if a parameter is not specified.

Iterators

Syntax: @Each[.Parameters] [@Current[.Parameters]] @EndEach Example: @Each.Users Hello @Current! @EndEach

Creates one copy of the contents of the @Each per element in the collection and substitutes @Current in the same way as @Model, but bound to the current item in the collection.

@Current can be used multiple times inside the @Each block.

Conditionals

Syntax: @If[Not].Parameters [contents] @EndIf Example: @If.HasUsers Users found! @EndIf Example: @IfNot.HasUsers No users found! @EndIf

Parameters must be a boolean (see Implicit Conditionals below). Nesting of @If and @IfNot statements is not supported.

Implicit Conditionals

If the model has property that implements ICollection then you can use an implicit conditional. The implicit conditional syntax is the same as a normal conditional, but the Parameters part is set to "Has[CollectionPropertyName]". The conditional will be true if the collection contains items, and false if it does not or if it is null.

Example: @If.HasUsers Users found! @EndIf

The above example will expand to "Users found!" if the model has a collection called "Users" and it contains items.

HTML Encoding

Both the @Model and @Current keywords (with or without parameters) can have an optional ! after the @ to HTML encode the output.

Example: @!Model.Test

Would HTML encode the output.

Partials

Syntax: @Partial[''[, Model.Property]]

Example: @Partial['subview.sshtml']; (Renders the partial view with the same model as the parent)

Example: @Partial['subview.sshtml', Model.User]; (Renders the partial view using the User as the model)

Renders a partial view. A property of the current model can be specified to be used as the partial view's model, or it may be omitted to use the current view's model instead.

supersimpleviewengine's People

Contributors

grumpydev avatar

Stargazers

 avatar

Watchers

 avatar  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.