Git Product home page Git Product logo

pthomson / blade Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamsar/blade

0.0 0.0 0.0 1.2 MB

Blade is a presentation framework for Sitecore 7. Blade is currently considered deprecated as Sitecore MVC is mature enough to make Blade no longer needed. Still good and stable for Web Forms projects though.

License: MIT License

Pascal 0.82% Batchfile 0.17% PowerShell 1.04% C# 97.97%

blade's Introduction

Blade

Blade is a presentation framework for Sitecore 7. It is not compatible with Sitecore 6.x.

How Blade Works

Blade uses the MVP pattern to allow you to create very DRY, single-responsibility renderings; focus on presentation code and not data access by coding renderings against interface contracts or ViewModels instead of the Sitecore API.

With Blade, your renderings only request the type of model they expect. For example:

public partial class SampleSublayout : UserControlView<MyViewModelClass>

Then Blade steps in and maps the model type onto a Presenter class, which defines how to supply the model type. For example:

public class SamplePresenter : SitecorePresenter<MyViewModelClass>
{
	protected override MyViewModelClass GetModel(IView view, Item dataSource)
	{
		var model = new MyViewModelClass();
		model.Example = dataSource.DisplayName;
		
		return model;
	}
}

This enables simple isolation of both views and presenters for writing testable frontends, and looser coupling even if you aren't testing. Don't worry, not every rendering needs a presenter. If you're just using a model type from a Sitecore object mapper such as Synthesis, Glass, or Compiled Domain Model, you can make that automatically map to the data source item without defining an explicit presenter (if you're curious, check out the code for Synthesis.Blade's PresenterFactory).

Ubiquitous Razor 2 Support

Blade also brings first-class support of the Razor 2 templating language into Sitecore, without using the Sitecore MVC functionality. This is advantageous when developing sites that use modules that are not compatible with the Sitecore MVC rendering technology - you can reap the benefits of MVC-style renderings without the hassle of implementing renderings twice or resorting to XSLT. A Razor rendering with Blade works exactly like a sublayout - only the path is to a cshtml file instead of an ascx. There are also many useful helpers included that simplify things like rendering dates, images, and controlling page editor functionality. For example:

@inherits RazorRendering<MyProject.MyViewModelClass>

<h1>@Html.Raw(Model.Example)</h1>

<p>@Html.TextFor(model => model.SitecoreDataField)</p>

Blade does its best to feel as much as possible like Sitecore as well as ASP.NET MVC, so it doesn't require digesting lots of unfamiliar ways of doing things. Sitecore features such as Page Editor are fully supported. MVC conventions like automatic HTML encoding, partial views, anonymous types defining HTML attributes, and relative view referencing are all there.

Awesome Rendering Diagnostics

Ever spent an hour figuring out why a rendering was busted, only to realize it was output cached without you realizing it? What about having to find a rendering file for a HTML/CSS dev so they can make markup changes? You'll love Blade then. Blade's rendering types emit HTML comments that indicate where a specific rendering begins and ends, as well as if it was output cached, when, and what the cache criteria were. The comments disappear when dynamic debug compilation is disabled, leaving production sites pristine.

Check this out:

<!-- Begin Rendering ~/layouts/Sample Inner Sublayout.ascx -->
<!-- Rendering was output cached at 5/16/2013 9:31:42 PM, ClearOnIndexUpdate, VaryByData, VaryByQueryString -->
<h1>Hello, world!</h1>
<!-- End Rendering ~/layouts/Sample Inner Sublayout.ascx, render took 0ms -->

Full Sitecore 7 Support

Blade supports the enhancements made to renderings in Sitecore 7. It supports renderings that decache on index update, have multiple items as data sources, index-query based data sources, and even defining your own data source resolution logic. Even better, it removes boilerplate code by automatically normalizing all kinds of data source specifications back into simple Item (or Item[]) instances.

What next?

See the wiki for more detailed documentation, or just go get the package off NuGet and play around. Make sure to install the samples package if it's your first time :)

Why "Blade"?

You may be thinking "because it has Razor support, how...uh...clever." You'd be partially right, but it's really a ridiculous movie reference ;)

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.