(Quick Reference)

2 Getting Started - Reference Documentation

Authors: 3.musket33rs

Version: 0.4

2 Getting Started

Let's start with installing the plugin, get a brief description of what it is. Let's give it a trial. Follow the guide to build a geolocalized mobile application in a minute and have lots of fun.

2.1 How to install ?

Ideally, add the plugin dependency into BuildConfig.groovy. It is important that the plugin is scoped as compile, otherwise you may get some unexpected problems if you are letting the plugin manage your datasource config:

plugins {
   compile ':html5-mobile-scaffolding:0.6'
}

Alternately you can use the install-plugin command in grails:

grails install-plugin html5-mobile-scaffolding

2.2 What is it?

Grails supports a feature known as static scaffolding which involves the generation of a CRUD (Create/Read/Update/Delete) interface for a given domain class. Once generated, the controller can be modified by you but they won't automatically update when you change the domain class.

Generating HTML5 web mobile application is as easy as using standard Grails scaffolding. Html5-mobile-scaffolding is using static scaffolding. The idea is to give you the skeleton of the application for CRUD operation and then it's up to you to modify it.

As html5-mobile-scaffolding plugin targets mobile application, the challenge is to scaffold an application that can be fully installed as an hybrid application using PhoneGap build or Cordova command line. The controller part is minimal and serves RESTfull services as JSON.

2.3 Quick sample

Create a Grails project

using command line or you favoutrite IDE

grails create-app bookstore
cd bookstore

install HTML5 scaffolding plugins

Our plugin is not yet publish in grails repository, in the meantime

  • fork or clone projects from github.com/3musket33rs/htm5-mobile-scaffolding
  • add jsonp and html5-mobile-scaffolding dependencies to BuildConfig.groovy file

jsonp plugin is for cross domain application. If you want to package your application as an hybrid application, this dependency is required.

Create a domain class

grails create-domain-class bookstore.Book

add content to it

class Book {
    String name
    String isbn
    Double latitude
    Double longitude
    static constraints = {}
}

geolocalization

To enable geolocalization add attributes latitude and longitude as Double. By convention, the plugin will understand those attributes as geolocalized information and will scaffold using a google map.

Generate JSON Controller and HTML view

You can generate both in one go:

grails html-generate-all bookstore.Book

Launch the application

grails run-app

Whith geolocation activated, book list can be rendered as map (default render)

You can switch to list rendering:

2.4 What is generated?

Generated Controller

From domain class controller class is generated. Controller renders as JSON.

def list() {
      params.max = Math.min(params.max ? params.int('max') : 10, 100)
     	render Book.list(params) as JSON
    }

Generated views

Views are generated in web-app directory. for each domain class one html file will be generated. This file contains different sections for each CRUD operations. 2 associated JavaScript files are generated.

- web-app
  book-index.html
  - js
    - bookstore ----------------> Folder to customize
      configuration-bootstrap.js
      manager-bootstrap.js
      - bootstrap
        book-bootstrap.js ------> describe your domain class relationships 
      - controller 
        book-controller.js-------------> add methods other than CRUD
      - model 
        book-model.js -----------------> entry point to enhance model
      - view
        book-view.js ------------------> entry point to enhance view
    - grails.mobile -------------------> 3musketeers Mobile Framework
      - camera
      - feed
      - map
      - mvc
      - push
      - storage
      - sync