Skip to content

Instantly share code, notes, and snippets.

View sergiomichels's full-sized avatar

Sérgio Michels sergiomichels

View GitHub Profile
Ext.define('Bookmarks.model.Category', {
extend : 'Ext.data.Model',
fields : [{
name : 'name',
type : 'string'
}, {
name : 'description',
type : 'string'
@sergiomichels
sergiomichels / JavaScriptController.groovy
Last active December 20, 2015 03:29
Generating JavaScript from a Grails controller
class JavaScriptController {
def i18NService
/**
* Render dynamic JavaScript to the browser. It can be used in a GSP as:
*
* <script type='text/javascript' src='${createLink(controller: "javaScript", action: "scripts")}'></script>
*
* You can access i18n messages in javascript with window.messages variable. Example:
*
@sergiomichels
sergiomichels / ExposedKeysMessageSource.groovy
Created July 23, 2013 16:18
Update for ExposedKeysMessageSource, returning all PropertiesHolder to be used in the i18n javascript messages
package com.wordpress.sergiosmind.i18n
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource
import org.codehaus.groovy.grails.plugins.BinaryGrailsPlugin;
@sergiomichels
sergiomichels / I18NService.groovy
Last active December 20, 2015 03:29
Transform messages in JSON that can be parsed in javascript
package com.wordpress.sergiosmind.lang
import grails.converters.JSON
import org.springframework.context.support.ReloadableResourceBundleMessageSource.PropertiesHolder
class I18NService {
/** Dependency Injection for ExposedKeysMessageSource */
def messageSource
/**
* Get's all messages for the Locale and encode to a JSON String.
@sergiomichels
sergiomichels / MyGrailsPlugin.groovy
Created July 23, 2013 14:11
Hook into the mssageSource declaration
import org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource
import com.wordpress.sergiosmind.i18n.ExposedKeysMessageSource
class MyGrailsPlugin {
...
def doWithSpring = {
def beanconf = springConfig.getBeanConfig('messageSource')
@sergiomichels
sergiomichels / MyGrailsPlugin.groovy
Created July 23, 2013 14:09
Declaration of the new messageSource
import com.wordpress.sergiosmind.i18n.ExposedKeysMessageSource
class MyGrailsPlugin {
...
def doWithSpring = {
messageSource(ExposedKeysMessageSource)
}
...
}
@sergiomichels
sergiomichels / ExposedKeysMessageSource.groovy
Created July 23, 2013 00:27
Message source that you can use to get all message keys (including plugins)
// src/groovy folder
package com.wordpress.sergiosmind.i18n
import org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource
class ExposedKeysMessageSource extends PluginAwareResourceBundleMessageSource {
Set getAllKeys(Locale locale) {
Set applicationKeys = getMergedProperties(locale).getProperties().keySet()
Set pluginsKeys = getMergedPluginProperties(locale).getProperties().keySet()
import org.springframework.security.core.Authentication
import org.springframework.security.core.context.SecurityContextHolder
class AuthFilters {
def springSecurityService
def dataSource
@sergiomichels
sergiomichels / gist:5764968
Created June 12, 2013 12:50
Files needed to compile CssInject Widgetset
//<your-app>/grails-app/vaadin/app/AppWidgetSet.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.vaadin.DefaultWidgetSet" />
<inherits name="org.vaadin.cssinject.Cssinject_addonWidgetset" />
</module>
@sergiomichels
sergiomichels / Menu.groovy
Created June 7, 2013 14:34
Trying TreeModel for GrailsZK plugin
class MenuModel extends AbstractTreeModel<Menu> implements TreeSelectableModel {
public MenuModel(Menu root) {
super(root)
}
@Override
public Menu getChild(Menu menu, int index) {
return menu.getAt(index);
}