Book Image

Learning Sinatra

By : Sudeep Agarwal, Manoj Sehrawat
Book Image

Learning Sinatra

By: Sudeep Agarwal, Manoj Sehrawat

Overview of this book

<p>Sinatra is a Ruby framework that is widely used in the Industry. You can use it to make a single-page web app or a large-scale one. With the increased online footprint, you can create and deploy your own application.</p> <p>Whether you are brand-new to online learning or a seasoned expert, this book will provide you with the skills you need to successfully create, customize, and deploy a Sinatra application. Starting from the beginning, this book will cover how to install Ruby and Sinatra, construct the back-end, design and customize the front-end layout, and utilize the innovative and user-friendly features of ORMs. By sequentially working through the steps in each chapter, you will quickly master Sinatra's features to create your own application.</p> <p>With ample screenshots and code that offers a play-by-play account of how to build an application, Learning Sinatra will ensure your success with this cutting-edge framework.</p>
Table of Contents (17 chapters)
Learning Sinatra
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

What did the code do?


You might have already guessed how this code works. We have added a new require line to helloworld.rb. This loads the haml gem. In the controller, we are returning a haml instead of a string.

Let's see line 5 once again:

5   haml :index

This is a ruby method call. The haml method has argument:index. The method will look for a file named index.haml in the views folder, generate the HTML from HAML, and return it to the client.

The following method will call the required file:

haml :<filename>

If the file does not exist in the views folder or if there are any syntax errors in HAML, then the application will throw an error.

Let's now see index.haml:

1 %body
2   %h1
3     Hello World!

We will see later that an HTML element can be defined by % in HAML and indented blocks can be used to define child elements. So, the preceding code will be interpreted as follows:

<body>
  <h1>
    Hello World!
  </h1>
</body>