Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Edvinas
committed
Jul 9, 2011
0 parents
commit 2a5c7d6
Showing
23 changed files
with
2,544 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.idea/ | ||
*.iml | ||
target/ | ||
|
||
|
||
.classpath | ||
.project | ||
.settings/ | ||
|
||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import org.grails.plugins.coffeescript.ModuleManager | ||
import org.springframework.core.io.FileSystemResource | ||
import org.codehaus.groovy.grails.web.context.ServletContextHolder | ||
|
||
class CoffeescriptResourcesGrailsPlugin { | ||
// the plugin version | ||
def version = "0.1" | ||
// the version or versions of Grails the plugin is designed for | ||
def grailsVersion = "1.3.7 > *" | ||
// the other plugins.coffeescript this plugin depends on | ||
def dependsOn = [:] | ||
// resources that are excluded from plugin packaging | ||
def pluginExcludes = [ | ||
"src/coffee/test.coffee", | ||
"src/coffee/smtelse.coffee", | ||
"web-app/js/one.js", | ||
"grails-app/views/error.gsp" | ||
] | ||
|
||
def author = "Edvinas Bartkus" | ||
def authorEmail = "edvinas@geeks.lt" | ||
def title = "Create coffeescript modules that automatically compiles on every file change with jCoffeeScript" | ||
def description = '''\\ | ||
Brief description of the plugin. | ||
''' | ||
|
||
def watchedResources = "file:./src/coffee/**.coffee" | ||
def documentation = "http://github.com/edvinasbartkus/coffeescript-resources" | ||
|
||
|
||
def onChange = { event -> | ||
def source = event.source | ||
if(source instanceof FileSystemResource && source.file.name.endsWith(".coffee")) { | ||
def relativePath = source.file.path - new File(ServletContextHolder.servletContext.getRealPath("/")).parent | ||
def modules = ModuleManager.filesHash.get(relativePath) | ||
if(modules) { | ||
new ModuleManager().compileModules(modules) | ||
} | ||
} | ||
} | ||
|
||
def onConfigChange = { event -> | ||
new ModuleManager().compileModules() | ||
} | ||
|
||
def doWithApplicationContext = { | ||
new ModuleManager().compileModules() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Grails Metadata file | ||
#Wed Jul 06 17:15:56 EEST 2011 | ||
app.grails.version=1.3.7 | ||
app.name=coffeescript-resources | ||
plugins.hibernate=1.3.7 | ||
plugins.tomcat=1.3.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
grails.project.class.dir = "target/classes" | ||
grails.project.test.class.dir = "target/test-classes" | ||
grails.project.test.reports.dir = "target/test-reports" | ||
//grails.project.war.file = "target/${appName}-${appVersion}.war" | ||
grails.project.dependency.resolution = { | ||
// inherit Grails' default dependencies | ||
inherits("global") { | ||
// uncomment to disable ehcache | ||
// excludes 'ehcache' | ||
} | ||
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose' | ||
repositories { | ||
grailsPlugins() | ||
grailsHome() | ||
grailsCentral() | ||
|
||
// uncomment the below to enable remote dependency resolution | ||
// from public Maven repositories | ||
//mavenLocal() | ||
//mavenCentral() | ||
//mavenRepo "http://snapshots.repository.codehaus.org" | ||
//mavenRepo "http://repository.codehaus.org" | ||
//mavenRepo "http://download.java.net/maven/2/" | ||
//mavenRepo "http://repository.jboss.com/maven2/" | ||
} | ||
dependencies { | ||
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg. | ||
|
||
// runtime 'mysql:mysql-connector-java:5.1.13' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// configuration for plugin testing - will not be included in the plugin zip | ||
|
||
log4j = { | ||
// Example of changing the log pattern for the default console | ||
// appender: | ||
// | ||
//appenders { | ||
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n') | ||
//} | ||
|
||
error 'org.codehaus.groovy.grails.web.servlet', // controllers | ||
'org.codehaus.groovy.grails.web.pages', // GSP | ||
'org.codehaus.groovy.grails.web.sitemesh', // layouts | ||
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping | ||
'org.codehaus.groovy.grails.web.mapping', // URL mapping | ||
'org.codehaus.groovy.grails.commons', // core / classloading | ||
'org.codehaus.groovy.grails.plugins.coffeescript', // plugins.coffeescript | ||
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration | ||
'org.springframework', | ||
'org.hibernate', | ||
'net.sf.ehcache.hibernate' | ||
|
||
warn 'org.mortbay.log' | ||
} | ||
|
||
// Modules for testing | ||
/* | ||
coffeescript.modules = { | ||
one { | ||
files "src/coffee/test" | ||
} | ||
two { | ||
files "src/coffee/test" | ||
output "test.js" | ||
} | ||
} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
dataSource { | ||
pooled = true | ||
driverClassName = "org.hsqldb.jdbcDriver" | ||
username = "sa" | ||
password = "" | ||
} | ||
hibernate { | ||
cache.use_second_level_cache = true | ||
cache.use_query_cache = true | ||
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider' | ||
} | ||
// environment specific settings | ||
environments { | ||
development { | ||
dataSource { | ||
dbCreate = "create-drop" // one of 'create', 'create-drop','update' | ||
url = "jdbc:hsqldb:mem:devDB" | ||
} | ||
} | ||
test { | ||
dataSource { | ||
dbCreate = "update" | ||
url = "jdbc:hsqldb:mem:testDb" | ||
} | ||
} | ||
production { | ||
dataSource { | ||
dbCreate = "update" | ||
url = "jdbc:hsqldb:file:prodDb;shutdown=true" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class UrlMappings { | ||
|
||
static mappings = { | ||
"/$controller/$action?/$id?"{ | ||
constraints { | ||
// apply constraints here | ||
} | ||
} | ||
|
||
"/"(view:"/index") | ||
"500"(view:'/error') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<html> | ||
<head> | ||
<title>Grails Runtime Exception</title> | ||
<style type="text/css"> | ||
.message { | ||
border: 1px solid black; | ||
padding: 5px; | ||
background-color:#E9E9E9; | ||
} | ||
.stack { | ||
border: 1px solid black; | ||
padding: 5px; | ||
overflow:auto; | ||
height: 300px; | ||
} | ||
.snippet { | ||
padding: 5px; | ||
background-color:white; | ||
border:1px solid black; | ||
margin:3px; | ||
font-family:courier; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>Grails Runtime Exception</h1> | ||
<h2>Error Details</h2> | ||
|
||
<div class="message"> | ||
<strong>Error ${request.'javax.servlet.error.status_code'}:</strong> ${request.'javax.servlet.error.message'.encodeAsHTML()}<br/> | ||
<strong>Servlet:</strong> ${request.'javax.servlet.error.servlet_name'}<br/> | ||
<strong>URI:</strong> ${request.'javax.servlet.error.request_uri'}<br/> | ||
<g:if test="${exception}"> | ||
<strong>Exception Message:</strong> ${exception.message?.encodeAsHTML()} <br /> | ||
<strong>Caused by:</strong> ${exception.cause?.message?.encodeAsHTML()} <br /> | ||
<strong>Class:</strong> ${exception.className} <br /> | ||
<strong>At Line:</strong> [${exception.lineNumber}] <br /> | ||
<strong>Code Snippet:</strong><br /> | ||
<div class="snippet"> | ||
<g:each var="cs" in="${exception.codeSnippet}"> | ||
${cs?.encodeAsHTML()}<br /> | ||
</g:each> | ||
</div> | ||
</g:if> | ||
</div> | ||
<g:if test="${exception}"> | ||
<h2>Stack Trace</h2> | ||
<div class="stack"> | ||
<pre><g:each in="${exception.stackTraceLines}">${it.encodeAsHTML()}<br/></g:each></pre> | ||
</div> | ||
</g:if> | ||
</body> | ||
</html> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import org.grails.plugins.coffeescript.ModuleManager | ||
|
||
eventCreateWarStart = { name, stagingDir -> | ||
// TODO: must be done here something with war archive | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ant.mkdir dir: "${basedir}/src/coffee" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// | ||
// This script is executed by Grails when the plugin is uninstalled from project. | ||
// Use this script if you intend to do any additional clean-up on uninstall, but | ||
// beware of messing up SVN directories! | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// | ||
// This script is executed by Grails during application upgrade ('grails upgrade' | ||
// command). This script is a Gant script so you can use all special variables | ||
// provided by Gant (such as 'baseDir' which points on project base dir). You can | ||
// use 'ant' to access a global instance of AntBuilder | ||
// | ||
// For example you can create directory under project tree: | ||
// | ||
// ant.mkdir(dir:"${basedir}/grails-app/jobs") | ||
// |
37 changes: 37 additions & 0 deletions
37
src/groovy/org/grails/plugins/coffeescript/CoffeeScriptModule.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.grails.plugins.coffeescript | ||
|
||
import org.codehaus.groovy.grails.web.context.ServletContextHolder | ||
import grails.util.BuildSettingsHolder | ||
|
||
class CoffeeScriptModule { | ||
String name | ||
List<String> files | ||
String output | ||
|
||
public CoffeeScriptModule() { | ||
files = new ArrayList<String>() | ||
} | ||
|
||
def compile() { | ||
def wholeContent = [] | ||
|
||
files.each { | ||
def file = new File(it + ".coffee") | ||
wholeContent << file.getText() | ||
} | ||
|
||
def content = wholeContent.join(System.getProperty("line.separator")) | ||
File outputFile = this.output ? new File(getRealPath(), this.output) : new File(getRealPath("/web-app/js"), "${name}.js") | ||
|
||
System.out.println("Compiling ${name} to ${outputFile.absolutePath}.") | ||
|
||
def js = new org.jcoffeescript.JCoffeeScriptCompiler().compile(content) | ||
outputFile.write(js) | ||
} | ||
|
||
def getRealPath(path = "/web-app/js") { | ||
return new File(BuildSettingsHolder.settings.baseDir, path) | ||
// return ServletContextHolder.servletContext.getRealPath(path) | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
src/groovy/org/grails/plugins/coffeescript/ConfigBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.grails.plugins.coffeescript | ||
|
||
class ConfigBuilder implements GroovyInterceptable { | ||
ModuleManager manager | ||
|
||
def invokeMethod(String name, args) { | ||
if(args.size() == 1 && args.first() instanceof Closure) { | ||
CoffeeScriptModule module = manager.modulesHash.get(name) | ||
|
||
if(!module) { | ||
module = new CoffeeScriptModule(name:name) | ||
manager.modulesHash.put name, module | ||
} | ||
|
||
def moduleClosure = args.first() | ||
moduleClosure.delegate = new ModuleBuilder(module: module) | ||
moduleClosure.resolveStrategy = Closure.DELEGATE_FIRST | ||
moduleClosure() | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/groovy/org/grails/plugins/coffeescript/ModuleBuilder.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.grails.plugins.coffeescript | ||
|
||
class ModuleBuilder { | ||
CoffeeScriptModule module | ||
|
||
def invokeMethod(String name, args) { | ||
if(module) { | ||
switch(name) { | ||
case "output" : | ||
if(args.size() > 0) { | ||
module.output = args.first() | ||
} | ||
|
||
break | ||
case "files" : | ||
args.each { | ||
module.files.push it | ||
} | ||
|
||
break | ||
default : | ||
break | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.