Download presentation
Presentation is loading. Please wait.
Published byMagdalen Griffin Modified over 9 years ago
1
Learning & Development http://academy.telerik.com Telerik Software Academy
2
View Engines Overview Client-side view engines KendoUI, Mustache.js, AngularJS Server-side view engines Jade
4
View engine (template engine) is a framework/library that generates views Using a programming language Web view engines are a mix-up of HTML and JavaScript Given a template/view JavaScript generates a valid HTML code
5
There are lots of JavaScript view engines, and they can be separated into client and server Client: KendoUI, mustache.js, jQuery, AngularJS, etc. Server: Jade, HAML, EJS, Vash, etc. Why use view engines? Speed-up developer performance and easify the writing of HTML code Auto generate DOM elements and make manual DOM manipulation almost useless
6
KendoUI, AngularJS, mustache.js
7
Client view engines (templates) are used to parse data The data is sent over HTTP The data is either raw JSON, XML or plain text Server view engines parse the data on the server The client (browser) receives the read-to-use HTML
8
mustache.js is a library for creating client-side templates mustache.js supports: One-time value-binding to JavaScript objects Iteration over a collection of elements Conditional templates
9
Generates a list with all mustache types var model = { title: 'Hello mustache!', title: 'Hello mustache!', types: ['Hungarian', 'Dali', 'Imperial', …] types: ['Hungarian', 'Dali', 'Imperial', …]} {{title}} {{title}} {{#types}} <input name="mustaches[]" <input name="mustaches[]" id="mustache-{{.}}" id="mustache-{{.}}" type="radio" type="radio" value="{{.}}" /> value="{{.}}" /> {{.}} {{.}} {{/types}} All binding is done inside {{ }} <- Template JavaScript <-
10
Live Demo
11
KendoUI templates are part of the KendoUI framework Can be found in kendo.core.js KendoUI supports: One-time value-binding to JavaScript objects Iteration over a collection of elements Conditional templates
12
Generates a table of technologies #: title # #: title # <table> # for (var i = 0; i < technologies.length; i+=1) { # # for (var i = 0; i < technologies.length; i+=1) { # #: technologies[i].name # #: technologies[i].name # </table> var model = { title: 'Technologies', title: 'Technologies', technologies: [{ name: 'ASP.NET', field: 'web' }, technologies: [{ name: 'ASP.NET', field: 'web' }, { name: 'Node.js', field: 'web' }, { name: 'Node.js', field: 'web' }, { name: 'WPF', field: 'windows desktop' }, { name: 'WPF', field: 'windows desktop' }, { name: 'Android', field: 'mobile' }] { name: 'Android', field: 'mobile' }]};
13
Live Demo
14
AngularJS templates are a part of the Core AngularJS framework They actually represent views for controllers AngularJS supports: Two-way data and event binding to JS objects Iteration over a collection of elements Conditional templates
15
Generates a slide of images {{currentImage.title}} {{currentImage.title}} <img ng-src="{{image.src}}" <img ng-src="{{image.src}}" ng-click="changeCurrent(image)"/> ng-click="changeCurrent(image)"/> </div> app.controller('ImagesController', function ($scope) { $scope.images = [{title: 'QA Academy 2012/2013 Graduation', $scope.images = [{title: 'QA Academy 2012/2013 Graduation', src: 'imgs/9511183282_cbe735bb73_c.jpg'} … ] src: 'imgs/9511183282_cbe735bb73_c.jpg'} … ] $scope.currentImage = $scope.images[0]; $scope.currentImage = $scope.images[0]; $scope.changeCurrent = function(image){ $scope.changeCurrent = function(image){ $scope.currentImage = image; $scope.currentImage = image; }; };});
16
Live Demo
18
Server view engines return ready-to-use HTML to the client (the browser) They parse the data to HTML on the server *Web applications, created with server view engines are not real SPA apps In most cases
19
Jade is a server view engine Produces HTML as a result Can be parsed: Manually (using CMD/Terminal commands) Automatically using a task runner Automatically using framework like Express Jade is more expressive and dynamic than HTML Jade template can be parsed based on JS models or conditionals
20
Install Jade with Node.js: $ npm install jade -g Create the index.jade file: ul each val in [1, 2, 3, 4, 5] each val in [1, 2, 3, 4, 5] li= 'Item ' + val li= 'Item ' + val Run: $ jade index.jade Generates index.html with content: <ul> Item 1 Item 1 Item 2 Item 2 Item 3 Item 3 Item 4 Item 4 Item 5 Item 5 </ul>
21
Live Demo
22
Omit the opening and closing tags Even their brackets IDs and classes are set as in CSS selectors #id and.class div#wrapper table.special table.special tr tr th Header 1 th Header 1 th Header 2 th Header 2 tr tr td Data 1 td Data 1 td Data 2 td Data 2 Header 1 Header 1 Header 2 Header 2 Data 1 Data 1 Data 2 Data 2 </div> Is parsed to
23
Attribites are written inside ' ( ' and ' ) ' And separated with commas ', ' #wrapper header header h1#logo h1#logo a(href='...') a(href='...') img(src='…') img(src='…') nav#main-nav: ul nav#main-nav: ul li.nav-item li.nav-item a(href='…') a(href='…')...... </div> Is parsed to
24
Live Demo
25
Jade can generate markup, using data models i.e. given an array of items, put them into a table #wrapper header header h1#logo h1#logo a(href='...') a(href='...') = title = title nav#main-nav: ul nav#main-nav: ul each item in nav each item in nav li.nav-item li.nav-item a(href= item.url) a(href= item.url) = item.title = item.title Lorem ipsum Lorem ipsum Home Home About About </div> Is parsed to
26
Live Demo
27
Jade can contain conditionals, loops, etc… And the HTML is generated based on the model if condition h1.success h1.success | Fulfilled! | Fulfilled!else h1.error h1.error | Not fullfilled | Not fullfilled model = { condition: true } condition: true } Fulfilled! Fulfilled!</h1> model = { condition: false } condition: false } Not fulfilled! Not fulfilled!</h1>
28
Live Demo
29
форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиранеhttp://academy.telerik.com
30
1. Create a simple web site for buying mobile devices Create the following pages and put them into nav Home -> contains greeting and site information Smart phones -> contains a list of smartphones Tablets -> contains a list of tablets Wearables -> contains a list of wearables All pages must have the same header, navigation and footer Use Jade and Jade Layouts Use the each directive to create the navigation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.