Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Opa Application Development
Opa Application Development

Opa Application Development: A rapid and secure web development framework to develop web applications quickly and easily in Opa

By Li Wenbo
$16.99 $10.99
Book Jun 2013 116 pages 1st Edition
eBook
$16.99 $10.99
Print
$32.99
Subscription
$15.99 Monthly
eBook
$16.99 $10.99
Print
$32.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 12, 2013
Length 116 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782163749
Category :
Languages :
Table of content icon View table of contents Preview book icon Preview Book

Opa Application Development

Chapter 1. Getting Started with Opa

This chapter shows how to install Opa and set its environment. A simple Opa program will also be shown to give a first glimpse of Opa programming.

Installing Opa


This section is about installation and configuration of Opa. You can get a more detailed installation guide that includes how to build Opa from source on Opa's webpage (https://github.com/MLstate/opalang/wiki/Getting-started). This section will give us brief instructions on how to install Opa compiler, Node.js, and some required modules for Node.js.

Installing Node.js

Node.js (http://nodejs.org) is a platform for building fast and scalable network applications. It is the backend of Opa (since Opa 1.0.0). We need to install Node.js first before installing Opa. The following are the steps to install Node.js on various operating systems:

  • Mac OS: Following are the steps to install Node.js:

    1. Download the latest .pkg package from http://nodejs.org/dist/latest/.

    2. Double-click on the package to install Node.js.

  • Ubuntu and Debian Linux: To install Node.js on Ubuntu and Debian Linux, type the following commands:

    $sudo apt-get install python-software-properties
    $sudo add-apt-repository ppa:chris-lea/node.js
    $sudo apt-get update
    $sudo apt-get install nodejs npm
    

    Tip

    Downloading the example code files

    You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

  • Windows: The following are the steps to install Node.js:

    1. Download the latest .msi package from http://nodejs.org/dist/latest/.

    2. Double-click on the package to install Node.js on Windows.

Type the following commands to confirm your installation. If everything goes right, you will see the version information of Node.js and npm.

$ node -v
$ npm –v

Installing the required modules

There are several modules that are required by Opa to run an application. Type the following command to install these modules:

$ npm install -g mongodb formidable nodemailer simplesmtp imap

Installing the Opa compiler

The easiest solution for installing Opa is to download an installer from the Opa website (http://opalang.org/). You can also get the installer from Opa's GitHub repository (https://github.com/MLstate/opalang/downloads). At the time this book is being written, the latest version of Opa is 1.1.0.

Following are the steps to install Opa on various operating systems:

  • Mac OS X: Download the latest .dmg package and double-click on it to install. You will need the password of an administrative account.

  • Ubuntu and Debian Linux: Download the latest .deb package and double-click on it to install. You can also install it with the following command line:

    $sudo dpkg –i opa-1.1.0.x86.deb
    
  • Windows: Download the latest .exe file and double-click on it to install. Note that only 64-bit packages are available for Windows at this time.

  • Other Linux: To install Opa follow these steps:

    1. Download the latest .run package for Linux.

    2. Go to the download folder and add an execution privilege to the downloaded file by running the following command:

      $ chmod a+x opa-1.1.0.x64.run
      
    3. Run the installing script:

      $ sudo ./opa-1.1.0.x64.run
      

Testing the installation

To test if Opa is installed properly on your computer, run the following command:

$ opa --version

Opa is installed properly if the version information of the Opa compiler is printed.

Setting up editors


You can write Opa codes with any text editor you like, but a good editor can make coding easier. This section is about setting up editors you may commonly use. For now, Sublime Text is the most complete Integrated Development Environment (IDE) for Opa.

Sublime Text

Sublime Text (http://www.sublimetext.com/) is a sophisticated text editor for code, markup, and prose. You can download and try Sublime Text for free from http://www.sublimetext.com/2.

There is an Opa plugin that offers syntax highlighting, code completion, and some other features. To install the plugin, follow these steps:

  1. Get the plugin from https://github.com/downloads/MLstate/OpaSublimeText/Opa.sublime-package.

  2. Move it to ~/.config/sublime-text2/Installed Packages/ (in Linux), or %%APPDATA%%\Sublime Text 2\Installed Packages\ (in Windows), or ~/Library/Application Support/Sublime Text 2/Installed Packages (in Mac).

  3. Start Sublime and check if the menu entry (View | Syntax | Opa) is present. If everything goes well, the file with the .opa extension should automatically have its syntax highlighted. If not, please make sure you are using the Opa plugin (View | Syntax | Opa). We can navigate to Edit | Line | Reindent to auto-indent the Opa code.

Vim

Vim (http://www.vim.org/) is a highly configurable text editor, freely available for many different platforms. The Opa installation package provides a mode for Vim at /usr/share/opa/vim/ (for Linux) or /opt/mlstate/share/opa/vim/ (for Mac OS). To enable Vim to detect Opa syntax, copy these files to your .vim directory in your home folder (create it if it does not exist already):

  • On Linux, type the following command:

    $cp –p /usr/share/opa/vim/* ~/.vim/
    
  • On Mac OS, type the following command:

    $cp –p /opt/mlstate/share/opa/vim/* ~/.vim
    

Emacs

On Mac OS X, you can either use Aquamacs and the package installation will take care of it, or you should add the following line to your configuration file (which might be ~/.emacs; create it if it does not exist already):

(autoload 'opa-classic-mode "/Library/Application Support/Emacs/site-lisp/opa-mode/opa-mode.el" "Opa CLASSIC editing mode." t)
(autoload 'opa-js-mode "/Library/Application Support/Emacs/site-lisp/opa-mode/opa-js-mode.el" "Opa JS editing mode." t)
(add-to-list 'auto-mode-alist '("\.opa$" . opa-js-mode))
(add-to-list 'auto-mode-alist '("\.js\.opa$" . opa-js-mode))
(add-to-list 'auto-mode-alist '("\.classic\.opa$" . opa-classic-mode))

On Linux, add the following lines to your configuration file:

(autoload 'opa-js-mode "/usr/share/opa/emacs/opa-js-mode.el" "Opa JS editing mode." t)
(autoload 'opa-classic-mode "/usr/share/opa/emacs/opa-mode.el" "Opa CLASSIC editing mode." t)
(add-to-list 'auto-mode-alist '("\.opa$" . opa-js-mode))
(add-to-list 'auto-mode-alist '("\.js\.opa$" . opa-js-mode))
(add-to-list 'auto-mode-alist '("\.classic\.opa$" . opa-classic-mode))

For Eclipse, the experimental plugin is available at https://github.com/MLstate/opa-eclipse-plugin.

Your first Opa application


As a first example, here is the most simple program in Opa:

jlog("hello Opa!")

Compile and run it:

$ opa hello.opa -o hello.js
$ ./hello.js

Note

We can type opa hello.opa -- to compile and run the code in a single line.

The code does nothing but prints hello Opa on your screen. If you can see this message, it means Opa is working properly on your machine.

Summary


In this chapter, we learned how to install Opa, set up a proper editor, and write our first Opa program. In the next chapter, we will have a brief look at the basic grammar of the Opa language.

Left arrow icon Right arrow icon

Key benefits

  • Discover the Opa framework in a progressive and structured way
  • Build secure, powerful web applications with Opa.
  • Create three complete web application demos with Opa.

Description

Opa is a full-stack Open Source web development framework for JavaScript that lets you write secure and scalable web applications. It generates standard Node.js/MongoDB applications, natively supports HTML5 and CSS and automates many aspects of modern web application programming. It handles all aspects of web programming written in one consistent language and compiled to web standards.Opa Application Development is a practical,hands-on guide that provides you with a number of step-by-step exercises. It covers almost all aspects of developing a web application with Opa, which will help you take advantage of the real power of Opa, as well as building a secure, powerful web application rapidly.Opa Application Development dives into all concepts and components required to build a web application with Opa. The first half of this book shows you all of the basic building blocks that you will need to develop an Opa application, including the syntax of Opa, web development aspects, client and server communication and slicing, plugin, database, and so on. By the end of the book you will have yourself created a complete web application along with a game: Pacman!

What you will learn

Set up Opa development environment Develop a web application, manipulate DOM and CSS. Use bootstrap in Opa, including classes, icons and widgets. Slice client and server code. Bind JavaScript and Nodejs to Opa and build a plugin. Store, update and query data in database with MongoDB as the backend. Build a chat application, LiveRoom application in Opa. Handle image and audio with canvas to build a Pacman game

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 12, 2013
Length 116 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781782163749
Category :
Languages :

Table of Contents

18 Chapters
Opa Application Development Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Getting Started with Opa Chevron down icon Chevron up icon
Basic Syntax Chevron down icon Chevron up icon
Developing Web Applications Chevron down icon Chevron up icon
Using Bootstrap Chevron down icon Chevron up icon
Communicating between Client and Server Chevron down icon Chevron up icon
Binding with Other Languages Chevron down icon Chevron up icon
Working with Databases Chevron down icon Chevron up icon
Internationalization Chevron down icon Chevron up icon
Building a Chat Application Chevron down icon Chevron up icon
Building a Game – Pacman Chevron down icon Chevron up icon
Developing a Social Mobile Application – LiveRoom Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.