Grails Plugins By : Ayush Tyagi FinTechLabs Noida-62
Apr 15, 2017
Grails Plugins
By : Ayush TyagiFinTechLabs Noida-62
Content
1. Introduction
2. Console
3. DB Migration
4. Asset Pipeline
5. Pagination
Introduction
A Grails plugin is a self-contained bundle of functionality that can be installed into a Grails application.
When you install a Grails plugin, that plugin's functionality is made available to the installing application.
Console
Console plugin provides a web-based Groovy console for interactive runtime application management and debugging.
Dependency:
compile "org.grails.plugins:console:1.5.7"
plugins {
runtime ':console:1.5.7'
}
Console
restricting access to localhost Ips: grails.plugin.springsecurity.controllerAnnotations.staticRules = [
"/console/**": ["hasRole('ROLE_ADMIN') && (hasIpAddress('127.0.0.1') || hasIpAddress('::1'))"],
"/plugins/console*/**": ["hasRole('ROLE_ADMIN') && (hasIpAddress('127.0.0.1') || hasIpAddress('::1'))"]
]
Console Plugin Key Commands
Ctrl-Enter / Cmd-Enter -> Execute
Ctrl-S / Cmd-S -> Save
Esc -> Clear output
Link:(For properties and their description)
https://github.com/sheehan/grails-console/blob/master/README.md
DB Migration
The Database Migration plugin helps you manage database changes while developing Grails applications.
The plugin uses the Liquibase library.
All of the scripts start with dbm- to ensure that they're unique ,
and don't clash with scripts from Grails or other plugins.
DB Migration
Dependency: runtime "org.grails.plugins:database-migration:1.4.1"
grails dbm-generate-changelog changelog.groovygrails-app/migrations/, you should see a file there called changelog.groovy
Command: grails dbm-gorm-diff
Config.groovy: grails.plugin.databasemigration.updateOnStart = true
grails.plugin.databasemigration.updateOnStartFileNames = ['changelog.groovy']
DB Migration1. To create a changelog from the database, use the dbm-generate-changelog script:
grails dbm-generate-changelog changelog.groovy
or
grails dbm-generate-changelog changelog.xml
2. To create a changelog from your domain classes, use the dbm-generate-gorm-changelog script:
grails dbm-generate-gorm-changelog changelog.groovy
or
grails dbm-generate-gorm-changelog changelog.xml
3. grails dbm-update
DB Migration
grails dbm-gorm-diff 2012-02-01-initial-database.groovy --add
databaseChangeLog = { include file: '2012-02-01-initial-database.groovy' }
Remote Pagination
Dependency:
compile "org.grails.plugins:remote-pagination:0.4.8"
Remote Pagination
The remote-pagination plugin currently provides the following tags:
remotePaginate
remoteSortableColumn
remotePageScroll
remoteNonStopPageScroll
Remote Pagination
<util:remotePaginate controller="book" action="filter" total="${Book.count()}" update="listTemplateDivId" max="20" pageSizes="[10, 20, 50,100]"/>
<util:remotePaginate controller="book" action="filter" total="${Book.count()}" update="listTemplateDivId" max="20" pageSizes="[10:'10 Per Page', 20: '20 Per Page', 50:'50 Per Page',100:'100 Per Page']"/>
Asset Pipeline Plugin
The Asset-Pipeline is a plugin used for managing and processing static assets in Grails applications. Asset-Pipeline functions include processing and minification of both CSS and JavaScript files.
The asset-pipeline levereges the latest in minification (UglifyJS) to reduce your asset sizes as much as possible.
Asset Pipeline PluginDependency:
compile "org.grails.plugins:asset-pipeline:2.11.0"
Asset-Pipeline automatically creates a series of folders within your grails-app directory:
grails-app/assets/javascript ,
grails-app/assets/images,
grails-app/assets/stylesheets
Asset Pipeline Plugin
Including Assets in your Views
Asset pipeline provides several new tag libs for including javascript and css into your gsp files.
Example:
<head><asset:javascript src="application.js"/><asset:stylesheet href="application.css"/>
</head>
Asset Pipeline Plugin
NOTE: In development mode your stylesheets and javascripts will be included as individual script
tags. This is intended to make it easier for debugging. Bundling is enabled in all other environments
and can be forced in development mode by adding
grails.assets.bundle=true to your Config.groovy.
During war build your assets are also minified using UglifierJs. To disable this feature you can add
the following option to your config:
grails.assets.minifyJs = false
Thank You