Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve .less handling and compiling #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ggiraldez
Copy link

Hey Paul:

Thanks for your work on this plugin. It's been very useful.

In this pull request I improved the support for .less files from the resources plugin by "monkey-patching" ResourceService and ResourceTagLib. I'm sure this is not the ideal way, but since there's currently no direct support to add asset types in resources, this approach seemed the best option.

This brings the benefit of no longer needing to specify type and rel attributes in the resource declaration. Also, I added operation = "compile" to the mapper so it's now possible to exclude the execution of the engine via the option exclude: 'compile' in the resource declaration. And since the tag lib is patched, it'll render the tag with the appropriate attributes.

The other change is compiling the less files from URLs instead of files. I was using version 0.6 and ran into problems when trying to deploy in a WAR (the mapper was not finding the source file). I think probably your fix in 0.6.1 might have solved the issue, but I didn't know about it until today. Anyway, since the solution I found is different, I'm sending it nevertheless. In any case, I think mine is a more general solution, in part because it uses the resources service to perform the path resolution.

The only complication is that in development mode the mapper wasn't working with resource reloads due to a problem with the class loader (somewhat related to http://jira.grails.org/browse/GRAILS-5592 ). Hence, I added a workaround by setting the context class loader before attempting to compile.

Regards,
Gustavo

and ResourceTagLib. Compile the less files from URLs, using
resourceService as path resolver.
@@ -25,34 +26,48 @@ class LesscssResourceMapper implements GrailsApplicationAware {

if (resource.sourceUrl && originalFile.name.toLowerCase().endsWith(LESS_FILE_EXTENSION)) {
LessEngine engine = new LessEngine()
File input = getOriginalFileSystemFile(resource.sourceUrl);
URL input = getOriginalResourceURLForURI(resource.sourceUrl)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this will work better for a problem I'm facing. I had some trouble with deployments having war files that are unexploded.
http://grails.1312388.n4.nabble.com/lesscss-resources-not-working-in-production-tt4429062.html has the discussion for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants