Instant Handlebars.js - Gabriel Manricks - E-Book

Instant Handlebars.js E-Book

Gabriel Manricks

0,0
19,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Handlebars is one of the leading JavaScript templating engines and is quickly gaining widespread adoption by developers, as well as with frameworks like Ember.js and Meteor.

"Instant Handlebars.js" is a complete guide to the Handlebars library filled with internal concepts and practical examples that will help illustrate what's going on and take you from a complete beginner to a Handlebars expert.

"Instant Handlebars.js" begins with the very basics, requiring no previous knowledge about templating engines. Throughout the course of this book, you get a thorough tour of all the features available in Handlebars.js and you will learn how to organize your websites for both development and production.

In this book, we will cover how to create templates with both placeholders and helpers. We will then go into organizing your projects for rapid -development using Require.js and how to optimize and compile your projects for production. To finish off, you will learn how to annotate your code and leave debug points so that you can easily maintain and troubleshoot your code in the future.

Handlebars is a small library;, it is meant to fill a specific need and it does this well. "Instant Handlebars.js" takes a very methodical approach to cover every aspect of this amazing library with practical examples provided every step of the way.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 69

Veröffentlichungsjahr: 2013

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Instant Handlebars.js
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, e-Books, discount offers, and more
packtlib.packtpub.com
Why Subscribe?
Free Access for Packt account holders
1. Instant Handlebars.js
So, what is Handlebars?
The syntax
Installation
Downloading the Handlebars library
Precompiling templates
Quick start – creating your first template
Preparing the project
Block helpers
Top 6 features you need to know about
Expressions
Helpers
Partials
Structuring a Handlebars app
Precompilation
Logging and comments
People and places you should get to know
Official sites
Community
Frameworks
Twitter

Instant Handlebars.js

Instant Handlebars.js

Copyright © 2013 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2013

Production Reference: 1240913

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78328-265-4

www.packtpub.com

Credits

Author

Gabriel Manricks

Reviewers

Jonathan Christopher

Nuno Oliveira

Acquisition Editor

Rubal Kaur

Commissioning Editor

Llewellyn Rozario

Technical Editor

Dipika Gaonkar

Project Coordinator

Sageer Parkar

Proofreader

Julie Blake

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

Cover Image

Sheetal Aute

About the Author

Gabriel Manricks is a full stack software & web developer focusing on PHP and both frontend and server-side JavaScript frameworks.

Gabriel works as a staff writer for NetTuts+, where he enjoys learning as well as teaching others, and he also freelances in web consulting, development, and writing.

About the Reviewers

Jonathan Christopher is a developer living in upstate New York with his wife Carrie and their son Micah. He focuses on both frontend and server-side development for his company Iron to Iron (http://irontoiron.com). He writes for Monday By Noon (http://mondaybynoon.com) and has also authored Client Oriented WordPress Development (https://clientwp.com).

Nuno Oliveira is a software engineer with over 10 years of professional experience. A windows developer for many years, he has an extensive background in the full life cycle of the software development process. He now concentrates on web development, working with ASP.net, PHP, HTML, CSS, and JavaScript. He currently lives in London, United Kingdom. You can always find him on twitter at @nm_oliveira.

www.PacktPub.com

Support files, e-Books, discount offers, and more

You might want to visit www.PacktPub.com for support files and downloads related to your book.

Did you know that Packt offers e-Book versions of every book published, with PDF and e-Pub files available? You can upgrade to the e-Book version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the e-Book copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and e-Books.

packtlib.packtpub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read, and search across Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print and bookmark contentOn demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

Chapter 1. Instant Handlebars.js

Welcome to the Instant Handlebars.js, in this book we will be taking a thorough look through this amazing templating library, as well as ways to manage your projects and optimize them for production.

This book contains the following sections:

So, what is Handlebars? here we will take a look at what a templating engine really is and more specifically why we are learning Handlebars.

Installation we will go through downloading the Handlebars library as-well as installing node.js and the handlebars CLI.

Quick start – creating your first template will get our feet wet, starting off by writing the minimum amount of code required to get a template onto the page, moving on to creating a simple helper.

Top 6 Features you need to know about will take a deep look at all the features Handlebars has to offer, as well as tips on organizing large projects and pre-compiling templates. Topics include:

Expressions: These are the core of templates, and a good starting point to get comfortable with the libraryHelpers: These are where Handlebars gets its extendibility; we will look at all the different types of helpers and settings you have availablePartials: These are the building blocks of the templating world, and they open the door for modular designStructuring a Handlebars app: In this section, we will take a look at a number of different ways to structure an app, pointing out the different pros and consPrecompilation: will continue to structure are projects, but with a focus on pre-compiling our resources for a more optimized and efficient siteLogging and comments: The final section will be about writing clear and debug-able templates and helpers, so you can easily test and maintain them in the future.

People and places you should get to know will take a look at different people and places you should subscribe to, to stay up-to-date, and learn more.

So, what is Handlebars?

To answer this properly, we need to first understand what a templating engine is, or better, what it comes to accomplish. Any dynamic site (blog, store, and so on) has parts which remain static, and at least rules on how the dynamic data should be inserted. A templating engine can and should be thought of as a new language in its own right and has a specialized syntax made specifically for rendering views.

Before templating engines you would have some kind of code in your actual DOM pages, through which you would insert the dynamic pieces of data at specific points. This is not great code separation, and it's definitely not a very clean option. A templating engine is meant to augment this step with its specialized syntax made specifically for this purpose; if done right, you should end up with clean and reusable templates, and leave your app clear of any bodge code.

Mustache was a pretty popular templating library for years and has basically been ported to nearly every programming language available. The problem with Mustache is that it is fairly opinionated on how you should write your templates; it follows a strict "View-Controller" separation and is a purely logic-less engine made specifically for replacing expressions with pre-computed data. Handlebars is a superset of the Mustache library, that adds a lot of logic and extensibility, making it a more flexible solution, while still retaining full backward compatibility, so that any Mustache templates can work out of the box. Following are the features of Handlebars:

It has a very simple and easy to write syntaxIt allows you to add some logic using helpers but still separates it from the actual template's code to keep them easy to manageIt's very fast and allows you to pre-compile your templates in JavaScript

Because of this, Handlebars has become the premier choice when it comes to frontend templates and is currently being used in many of the popular frameworks such as Meteor and Ember.js.

Not to mention the fact that it was built by the legendary Yehuda Katz, who is a core member on projects such as, jQuery, Ruby on Rails, and the Ember.js framework.

The syntax