Presentation is loading. Please wait.

Presentation is loading. Please wait.

Telerik Software Academy End-to-end JavaScript Applications.

Similar presentations


Presentation on theme: "Telerik Software Academy End-to-end JavaScript Applications."— Presentation transcript:

1 Telerik Software Academy http://academy.telerik.com End-to-end JavaScript Applications

2  View Engines  Overview  Client-side view engines  KendoUI, Handlebars.js, AngularJS  Server-side view engines  Jade

3

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, Handlebars.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, Handlebars.js

7  Client view engines (templates) are used to parse data  The data is fetched from some place  i.e. with AJAX  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  Handlebars.js is a library for creating client- side templates  Handlebars supports:  One-time value-binding to JavaScript objects  Iteration over a collection of elements  Conditional templates

9  Generates a list with all mustache types

10 {{title}} {{title}} {{#types}} <input name="mustaches[]" <input name="mustaches[]" id="mustache-{{.}}" id="mustache-{{.}}" type="radio" type="radio" value="{{.}}" /> value="{{.}}" /> {{.}} {{.}} {{/types}} <- Template

11  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}} JavaScript <- <- Template

12  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 {{ }} JavaScript <- <- Template

13 Live Demo

14  KendoUI templates are part of the KendoUI framework  Can be found in kendo.core.js  Can be used stand-alone  KendoUI templates supports:  One-time value-binding to JavaScript objects  Iteration over a collection of elements  Conditional templates

15  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' }]};

16 Live Demo

17  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

18  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; }; };});

19 Live Demo

20

21  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

22  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

23  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>

24 Live Demo

25  Omit the opening and closing tags  Even their brackets  IDs and classes are set as in CSS selectors  #id and.class #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

26  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

27 Live Demo

28  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

29 Live Demo

30  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>

31 Live Demo

32 форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен 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

33 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


Download ppt "Telerik Software Academy End-to-end JavaScript Applications."

Similar presentations


Ads by Google