Browse files

adding support to compile less files living inside a plugin

  • Loading branch information...
1 parent 08d1475 commit c01ffe1227a63fb96fa83feb86601661bfb8db60 @jvalde committed Sep 16, 2011
Showing with 33 additions and 2 deletions.
  1. +1 −1 LesscssResourcesGrailsPlugin.groovy
  2. +32 −1 grails-app/resourceMappers/LesscssResourceMapper.groovy
View
2 LesscssResourcesGrailsPlugin.groovy
@@ -1,6 +1,6 @@
class LesscssResourcesGrailsPlugin {
// the plugin version
- def version = "0.6"
+ def version = "0.6.1-SNAPSHOT"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.3.5 > *"
// the other plugins this plugin depends on
View
33 grails-app/resourceMappers/LesscssResourceMapper.groovy
@@ -1,6 +1,7 @@
import com.asual.lesscss.LessEngine
import com.asual.lesscss.LessException
import org.grails.plugin.resource.mapper.MapperPhase
+import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
/**
* @author Paul Fairless
@@ -9,12 +10,16 @@ import org.grails.plugin.resource.mapper.MapperPhase
*/
import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
import org.codehaus.groovy.grails.commons.GrailsResourceUtils
+import org.springframework.util.AntPathMatcher
class LesscssResourceMapper {
def phase = MapperPhase.GENERATION // need to run early so that we don't miss out on all the good stuff
static defaultExcludes = ['**/*.js','**/*.png','**/*.gif','**/*.jpg','**/*.jpeg','**/*.gz','**/*.zip']
static String LESS_FILE_EXTENSION = '.less'
+ static String PLUGIN_PREFIX = '/plugins/'
+ static final PATH_MATCHER = new AntPathMatcher()
+
def map(resource, config){
File originalFile = resource.processedFile
@@ -50,6 +55,32 @@ class LesscssResourceMapper {
}
private File getOriginalFileSystemFile(String sourcePath) {
- new File(GrailsResourceUtils.WEB_APP_DIR + sourcePath);
+ def resourceFile
+ if(isPlugin(sourcePath)){
+ def pluginName = getPluginFullName(sourcePath)
+ def resourcePath = getResourceRelativePath(pluginName, sourcePath)
+
+ for(directory in GrailsPluginUtils.getPluginBaseDirectories()){
+ resourceFile = new File(directory + '/' + pluginName + '/' + GrailsResourceUtils.WEB_APP_DIR + '/' + resourcePath)
+ if(resourceFile.exists()){
+ return resourceFile
+ }
+ }
+ }
+
+ return new File(GrailsResourceUtils.WEB_APP_DIR + sourcePath)
+ }
+
+ private getPluginFullName(sourcePath){
+ def pluginMap = PATH_MATCHER.extractUriTemplateVariables(PLUGIN_PREFIX + '{plugin}/**', sourcePath)
+ pluginMap.get('plugin')
+ }
+
+ private getResourceRelativePath(pluginName, sourcePath){
+ PATH_MATCHER.extractPathWithinPattern(PLUGIN_PREFIX+ pluginName +'/**', sourcePath)
+ }
+
+ private isPlugin(String original){
+ PATH_MATCHER.match(PLUGIN_PREFIX + '**', original)
}
}

0 comments on commit c01ffe1

Please sign in to comment.