Coder Social home page Coder Social logo

grails-asset-pipeline's Introduction

Grails Asset Pipeline

Build Status

Overview

The Grails 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. It is also capable of being extended to compile custom static assets, such as CoffeeScript or LESS.

For contributions to the core plugin please see the repository for the core plugin at asset-pipeline

NOTE: This repository is only for supporting the Grails 2 module of asset-pipeline. For grails3 see the main repository at asset-pipeline.

Documentation

http://www.asset-pipeline.com/manual/

Release Notes

http://www.asset-pipeline.com/manual/index.html#release-history

Things to be Done

  • Improve SourceMaps

Contributions

All contributions are of course welcome as this is an ACTIVE project. Any help with regards to reviewing platform compatibility, adding more tests, and general cleanup is most welcome. Thanks to several people for suggestions throughout development. Notably: Brian Wheeler (@bdwheeler), Rick Jensen (@cdeszaq), Bobby Warner (@bobbywarner), Ted Naleid (@tednaleid) and more to follow I'm sure...

Additional Resources

grails-asset-pipeline's People

Contributors

bobbywarner avatar bodiam avatar brian428 avatar burtbeckwith avatar craigburke avatar ctoestreich avatar davydotcom avatar dewarim avatar donalmurtagh avatar donbeave avatar dspies avatar dtanner avatar ghquant avatar jerleng avatar kgeis avatar manuelvio avatar mikethomsen avatar mrhaki avatar noamt avatar omasiri avatar rgoldberg avatar rlovtangen avatar sbearcsiro avatar scrain avatar spither avatar tbarker9 avatar tedder avatar tednaleid avatar uris77 avatar val-not-var avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grails-asset-pipeline's Issues

ApplicationResources

Hi. Another question. Maybe it make sense to use common solution like ApplicationResources in resources plugin instead of declaration for every stylesheet, js and img? It is not requirement, but point for discussion. Thanks.

utf-8 encoding is not working

I have german umlaute in a javascript file that is saved in utf-8.
but when it get compiled (with some additional resources) like:
//= require libraries/validate/jquery.validate.js
image

they dont get properly encoded
image

any help? how can i set the encoding for the processor?

Grails Asset Pipeline not delivering .gz files

I use to notice the .gz files being created during asset-precompile (harder to see now since I don't normally run war command when dev'ing in IntelliJ), but even now I don't see the .gz's mentioned in the manifest, or any code that would serve them up.

Patches around this have been talked about for the Rails version of the plugin, so I'm curious if I'm missing something here before I go about making a patch...?

make url mapping configurable

If something was already located at /assets it would be difficult (maybe impossible) to use this plugin. Current location is fine as a default, but should be configurable in Config.groovy.

web-app/assets and precompilation mismatch

My "feeling" about the current behaviour of this great plugin is something irritating.

It disturbs me that this folder is used to overwrite all resources created "on the fly" in development mode and also to be a cache for production.

If anyone forgets to delete that folder after issuing "asset-precompile", it comes easily to very unexpected results.
But if we have to delete this folder anyways, what's the matter of his existence?

Have you ever changed a .css and see no change? What's your first and second thought? Grails hadn't pickup the change yet. Wait 2 seconds or change the file again, because grails overseen the file-change (this happens really).
Hmm... maybe my CSS-selector is not explicit enough to overwrite other selectors rules... let me tweak on that...

Someone (like me, who is looking firstly on his own failures) will lose much time looking into the wrong direction, because nobody expects that he have to delete a (version-controlled) folder manually to make any change work again. Especially and as a horrific example: if you create a new grails-app/assets/application.less file, and in web-app/assets lurks a old application.css file... Guess what.. over 2 hours of self doubt and rising anger. We have to stop this before the Vogons are coming to pain us with her lyrics - if you know what i mean :)

I really hope we can change the current behaviour, because a cache for production (what's web-app/assets elsewhere?) should not break the development process.
As example: this would be my expectation (can't talk for others):

  • grails-app/assets over web-app/assets! (why have a "out" folder more weight than a "in" folder like the current implementation?)
  • no forced manual "asset-precompile" (do it automatically on war creation (can be disabled in Config.groovy))
  • don't "precompile" into the web-app/assets folder (should be precompiled to a temp folder and merged into web-app/assets for the .war only (volatile))
  • config-option to "precompile" into a non-volatile folder (like target/assets-precompiled), so you don't have to "precompile" everything - everytime (check the date modified)

Hope you got the point of my concern and my english was nearly understandable :)

asset:image tag w/ directory does not produce a hashed filename

When files are located in a subdirectory of grails-app/assets/images, the tag does not produce a hashed filename.

<asset:image src="small/180x180.png"/>

becomes

<img src="/assets/small/180x180.png">

which loads the image, but lacks the content specific filename.

When files are located directly in grails-app/assets/images, the tag produces a hashed filename.

<asset:image src="180x180.png" />

becomes

<img src="/assets/180x180-c903e2c9036ed0577a2351d8d597933d.png">

Several questions

Hi. Plugin is beauty, I'm desperate to wait for improvements resources plugin and now I want to migrate our projects to asset-pipeline plugin. But I have several questions:

  1. I'm using less, but I notice that recompile of less files occurs every reloading of page in dev mode. Is it correct behavior or I missed something?

asset-pipeline works more faster than lesscss-resources, but recompiling every time take time (is not critical, but it)

  1. Can I use several links to stylesheets in one page. E.g.

< asset:stylesheet src="main.css" />
< asset:stylesheet src="blocks.css "/>

Thanks and sorry for my poor English

Feature request: manifest depend_on

Hi. Is there any way to exclude file from bundling? E.g. I don't want to include jquery.js to bundle, because it can be in users cache and no need to load it every time after changing of another js file.
I'm not familar with rails assets pipeline, but found depend_on.

depend_on [path] declares a dependency on the given path without including it in the bundle. This is useful when you need to expire an asset’s cache in response to a change in another file..

Similar feature to r:script

With the resources plugin we can render several script tags at the end of the page all together. How can be this be accomplished in a similar way to the resources plugin?

For example we can render a script from a taglib or a view using:

<r:script>
//some javascript code
</r:script>

Is there a way for also telling that the content is in coffeescript?
Thanks in advance!

PS: maybe this is not an issue, if so I apologize! ;)
PS2: if there is not a feature to accomplish this, is it wrong to use the resources plugin for this purpose along with the assets plugin?

Few asset-pipeline questions

Hello. Don't know where is better to ask questions

  1. How does asset solves caching problem? Didn't found any info
  2. Is is possible to configure modules using groovy? Sometimes it's usefull to use conditions/loops and so on while defining your css modules

"Load only min file in prod" configuration

Hi.
In grails resources plugin I can check, is it development mode and load min files instead of big.

E.g. GrailsUtil.isDevelopmentEnv() ? 'jquery-2.1.0.js' : 'jquery-2.1.0.min.js'.

Is it possible with asset-pipline? I see that there is conig, that allow not to use ugilfy for minification, but I want to use "min" version for production and not-minified for development.

Empty line breaks assets import

following file will import only a.js. b.js will be skipped because of empty line. Previous version I used (0.5) was ok

//= require a.js

//= require b.js

I use empty lines as logical breaks. Hope you will fix it

Use Cache Digest image names in Css Files

Currently we reprocess css image paths to convert to a relative base path when combining stylesheets in the CssProcessor We need to modify the processor stack to allow the processor to determine if the app is running in 'on-the-fly' mode or running a precompile. If in precompile we want to replace image names with md5 names.

No signature of method: org.codehaus.groovy.grails.support.encoding.EncodedAppenderWriter.isSecure()

Grails 2.3.7

BuildConfig:

compile ':asset-pipeline:1.6.2'
compile ':less-asset-pipeline:1.5.4'

Config:

grails.assets.url = { request ->
    if (request.isSecure()) {
        return 'https://test.com'
    } else {
        return 'http://test.com'
    }
}

Error:

Caused by MissingMethodException: No signature of method: org.codehaus.groovy.grails.support.encoding.EncodedAppenderWriter.isSecure() is applicable for argument types: () values: []
Possible solutions: isCase(java.lang.Object), inspect()
->>  321 | doCall    in Config$_run_closure9

Images are broken

AssetHelper.groovy:29
...
def assetFile = AssetHelper.fileForFullName(uri + "." + ext)
...
AssetHelper.groovy:36
...
def assetFile = AssetHelper.fileForFullName(uri + "." + ext)

Adding the extra dot in the path produces "image..png"

Quick Reload of Javascript Asset Cause Tomcat Plugin Exception

One Line Summary

Stress loading of Javascript asset (by holding the F5 key) cause Tomcat to throw exception.

Environment

  • Operating system: Windows
  • Grails version: 2.3.6
  • asset-pipeline version: 1.5.8
  • tomcat plugin 7.0.50.1

Step to reproduce

  • I created a grails application from scratch: grails create-app
  • I put 2 javascript files to the directory grails-app/assets/javascripts: applications.js and moment-with-langs.js (http://momentjs.com/downloads/moment-with-langs.js)
  • I edit the file application.js with the following lines:
//=encoding UTF-8
//=require moment-with-langs-asset
//=require_self
  • Also, I edit the file Config.groovy and add the following line:
grails.assets.bundle=true
  • I run the app in grails console: run-app
  • I copy the URL of the application.js e.g. http://localhost:8080/example-app/asset/application.js and paste to a new browser and open it.
  • Now, I press and hold the F5 key to continuously reload the page, within a few seconds I saw a stack trace in the Grails console:
[ERROR] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/asset-pipeline-test].[default] Servlet.service() for servlet [default] in context with pat
h [/asset-pipeline-test] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response
        at org.apache.catalina.connector.Response.getWriter(Response.java:638)
        at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
        at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper$5.activateDestination(GrailsPageResponseWrapper.java:150)
        at org.codehaus.groovy.grails.web.sitemesh.GrailsPageResponseWrapper$5.activateDestination(GrailsPageResponseWrapper.java:148)
        at org.codehaus.groovy.grails.web.sitemesh.GrailsRoutablePrintWriter.activateDestination(GrailsRoutablePrintWriter.java:75)
.
.
.
       at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
       at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at javax.servlet.FilterChain$doFilter.call(Unknown Source)
       at asset.pipeline.AssetPipelineFilter.doFilter(AssetPipelineFilter.groovy:52)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
       at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
.
.
.
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
grails>
  • To make sure it is just the Javascript having this problem, I try to reload the page continously. Since loading a page will also load the Javascript, in Google Chrome, I press Ctrl+U to view the HTML source and then press and hold the F5 to only request the HTML page. No exception is found.
  • If I edit the Javascript file application.js and remove the directive //=require, and load the Javascript "moment-with-langs.js" continuously, exception is thrown.

To make sure it is asset pipeline's problem, I test by not using asset pipeline to serve the javascript. I did the following:

  • I copy the javascript to the standard web-app/js directory.
  • In the GSP, I write the tag <g:javascript src="moment-with-langs.js" />
  • I do a stress loading on the javascript
  • No exception is thrown.

Observation and Thoughts

  • I found in the stack trace that AssetsFilter is involved. Although it is not necessary related, but it is a possible suspect since the class contains code related to outputStream, which match that stack trace's error reporting.
  • It seems that serve Javascript file with certain size (momentjs has a size of 267 KB) will cause problem on heavy loading.

Error loading event script from file

Hello

Not sure if this is a grails issue or plugin issue, I am running Grails 2.3.7 (compile ":asset-pipeline:1.6.1") and I am getting an error when I do a "grails test-app" -below.

It seems like perhaps a benign error as I can "run-app" without issue, but I am worried it will lead to issues down the road. I don't have any experience with the asset plugin, so figured I would check in with you first. Thank you for any help, let me know if you need more info...

Error loading event script from file [.\myProject\target\work\plugins\asset-pipeline-1.6.1\scripts_Events.groovy] _GrailsArgParsing_groovy$_run_closure1
java.lang.NoClassDefFoundError: _GrailsArgParsing_groovy$_run_closure1
at _GrailsArgParsing_groovy.run(_GrailsArgParsing_groovy:31)
at _GrailsArgParsing_groovy$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at TestApp.run(TestApp:34)
at TestApp$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at TestApp.run(TestApp:28)
at TestApp$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at TestApp.run(TestApp:28)
at TestApp$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at TestApp.run(TestApp:24)
at TestApp$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at _AssetCompile_groovy.run(_AssetCompile_groovy:5)
at _AssetCompile_groovy$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at _Events.run(_Events.groovy:1)
at TestApp.run(TestApp:49)
at TestApp$run.call(Unknown Source)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at TestApp.run(TestApp:29)
at TestApp$run.call(Unknown Source)
at org.codehaus.gant.IncludeTargets.leftShift(IncludeTargets.groovy:59)
at org.codehaus.gant.IncludeTargets$leftShift.call(Unknown Source)
at TestApp.run(TestApp.groovy:24)
at TestApp$run.call(Unknown Source)
at gant.Gant.prepareTargets(Gant.groovy:607)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: _GrailsArgParsing_groovy$_run_closure1
... 44 more

Overriding resources

Hi,

We are looking into moving over to asset pipeline, from resources. It seems to have a lot of the things we currently use.

It looks like you're planning to add the md5 cached css background images, which we need and you've just added the cache headers!

The last thing we need to check off our list before we can fully switch over is to be able to override resources in certain environments, mainly development and test (we mock some 3rd party libraries), we currently haven't seen a way to do this?

Thanks,
Andrew

UTF-8 Javascript corrupted when being served

This issue is similar to issue #62, except it happens in production mode (or non-development mode).

I am not sure if the same thing will happen on other assets (e.g. CSS).

In my case, I have two js file:

  1. application.is, which //=require moment-with-langs, and
  2. moment-with-langs.js, which is included by application.js via directives.

I have read through the code and found that in production mode, the explicitly defined charset in the asset: tag for application.js will not proporgatr to all required files, and therefore the moment-with-langs.js file will not have an encoding value passed (I found it by adding debug output).

Furthermore, the asset code will not properly read the required files using UTF-8, and in the AssetsController, there is no means to specify the character encoding to use when I am trying to fix issue 62.

This also make me thinks that, what if the js/CSS files to serve may not be necessary all in UTF-8 encoding?

Should add a config parameter to disable the CssProcessor and Image Taglib for processing the versioning of images

Hi Guys,

The plugin is awesome, I'm using it to replace the complicated official plugin of "resources".
But I think the plugin could do its job better by disabling image versioning.
Versioning CSS and JSs files are awesome for the modern web, but image files? I don't think the web developer will change the image or background during the production mode. They will just add new image/background with new name to the project. Which means the static file of images are not need to be rotated their versions.

And the versioning of image files meet an issue to my project. I'm developing a modern web application which should be able to support both normal display and retina display, and I'm using a JS library to do the job named "retina_replace". The plugin works automatically, we just need to follow the rule which is naming the 2x pictures xxxx_2x.png. However, the assets plugin will version image files in production module, then all _2x.png files will be returned HTTP 404. I have modified the code of the plugin to resolve the issue of my project. But I think versioning image files may be not really make sense to the web developer.

I would highly recommend to add a parameter to the config.groovy file, which is able to disable the CssProcessor and Taglib to process the versioning of images.

Best Regards,

Leon

How to correctly exclude *.less from font-awesome plugin

Hi,

I'm using grails-font-awesome-resources, and I see this error:
Error |
2557-02-23 15:08:52,299 [main] ERROR less.LessProcessor - LESS Engine Compiler Failed - font-awesome.less.
Did you mean to compile this file individually (check docs on exclusion)?
-- variable @fa-font-path is undefined Near Line: 6.0, Column: 11.0
--------------------------------------------
font-family: 'FontAwesome';
src: url('@{fa-font-path}/fontawesome-webfont.eot?v=@{fa-version}');
src: url('@{fa-font-path}/fontawesome-webfont.eot?#iefix&v=@{fa-version}') format('embedded-opentype'),
--------------------------------------------
|Compressing File 43 of 43 - font-awesome
|Finished Precompiling Assets

Even I already define these lines in Config.groovy:
grails.assets.plugin."font-awesome-resources".excludes = ["/*.less"]
grails.assets.plugin."font-awesome-resources".includes = ["font-awesome.less"]
grails.assets.plugin."twitter-bootstrap".excludes = ["
/*.less"]
grails.assets.plugin."twitter-bootstrap".includes = ["bootstrap.less"]

So what is the correct way to exclude them to avoid this error?

My environment:
windows 7 x64
jdk1.7
grails2.3.5

To reproduce:

  1. Just create fresh project
  2. Add these lines in BuildConfig.groovy
    runtime ":asset-pipeline:1.5.9"
    runtime ":less-asset-pipeline:1.5.2"
    runtime ":twitter-bootstrap:3.1.0"
    runtime ":font-awesome-resources:4.0.3.0"
  3. Go to command line and call 'grails prod war'.

assetPathExists tag doesn't work

assetPathExists tag in AssetTagLib.groovy returns a closure if body is present, but it should call the closure itself, and then render the results. Note that the same tag should also handle the call in a boolean context.

The plugin documentation example:

<asset:assetPathExists src="test.js">
This will only be displayed if the asset exists
</asset:assetPathExists>

renders

org.codehaus.groovy.grails.web.taglib.GroovyPageTagBody@1d6bb99f

Currently I'm working on this issue on my forked repo, if you agree I will send you a pull request with related unit tests tomorrow or in a couple of days.

Analogue cached-resources

Hi. I have another pesky question. Is there analogue of "cached-resources" plugin? I read about cache-digest, but I can't find in documentation of asset-pipeline information about caching and updating of cache after changing style sheets. Could you improve documentation or show, where it is describes else. Thanks a lot!

UTF-8 Javascipt is not served properly in development mode

I have been using Struts2 and recently switched to Grails 2.3.1.

I have tried using asset pipeline version 1.5.3. However, when I am trying to serving a Javascript library which contains Unicode characters, I found that it does not properly serve the Javacsript file.

Environment

How to reproduce

  1. create a new grails project using command "grails create-app"
  2. copy the momentjs javascript file to the grails-app/asset/javascripts/moment-with-langs.js
  3. in the GSP file, use the <asset:javascript src="moment-with-langs.js" />
  4. in grails console, enter "run-app" and visit the URL of the javascript. e.g. http://localhost:8080/foobar/asset/moment-with-langs.js?compile=false
  5. search for the keyword "japan"
  6. You can see that the unicode character is currupted.

Things to note

  • The same Javascript file is used in my old Apache Struts2 framework without any modification.

What I have tried

  • I tried specifying character encoding in the tag e.g. <asset:javascript charset="utf-8" >. But it does not work
  • I have tried modifying the momentjs javascript source to DOS/UNIX format as well as playing around with UTF-8 and Unicode format.

Thoughts and Possible Solution

Obviously it is something related to character encoding, however it can happen in several areas

  • Reading the source Javascript file.
  • Serving to user agent via controller.
  • Tomcat connector.

After some tracing I found that the Grails controller AssetsController maybe the cause of problem.

Git commit: 3266b01
Source file: https://github.com/bertramdev/asset-pipeline/blob/3266b0168219723753b617c1ea391c4469ec68e8/grails-app/controllers/asset/pipeline/AssetsController.groovy

if(assetFile) {
  response.setContentType(format)
  response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
  response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
  response.setDateHeader("Expires", 0); // Proxies.
  if(format == 'text/html') {
    render contentType: 'text/html', text: new String(assetFile)
  } else {
    response.outputStream << assetFile
    response.flushBuffer()
}

The code "response.outputStream << assetFile" seems not specifying any encoding.

So I made some minor changes to:

  1. specify HTTP response character encoding if "encoding" parameter is specified.
  2. use HttpResponse.getWriter() to write instead of outputStream.

Here is the code fix: (marked with // FIX between)

if(assetFile) {
  response.setContentType(format)
  response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
  response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
  response.setDateHeader("Expires", 0); // Proxies.
  // FIX begins
  if (params.encoding != null) {
    response.setCharacterEncoding(params.encoding);
  }
  // FIX ends
  if(format == 'text/html') {
    render contentType: 'text/html', text: new String(assetFile)
  } else {
    // FIX begins
    if (params.encoding != null) {
      def w = response.writer
      w.write(assetFile)
      w.flush()
    } else {
      response.outputStream << assetFile
      response.flushBuffer()
    }
    // FIX ends
}

MissingMethodException: No signature of method: static asset.pipeline.AssetHelper.getPossibleFileSpecs() is applicable for argument types: (java.util.ArrayList)

Changes in 98f873d are not reflected in method signature and logic.

I think that method should be written like this:

    static getPossibleFileSpecs(contentType){
        AssetHelper.assetFileClasses().findAll { (contentType instanceof String) ? it.contentType == contentType : it.contentType in contentType }
    }

Let me know if you prefer a pull request for this.

Plugin uses deprecated ApplicationHolder class which has now been removed in Grails 2.4

Using the plugin with the current build of Grails 2.4 results in

| Error Error loading event script from file [target/work/plugins/asset-pipeline-1.6.0/scripts/_Events.groovy] startup failed:
_AssetCompile_groovy: 2: unable to resolve class org.codehaus.groovy.grails.commons.ApplicationHolder
@ line 2, column 1.
1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
_AssetCompile_groovy: 2: unable to resolve class org.codehaus.groovy.grails.commons.ApplicationHolder
 @ line 2, column 1.
1 error

    at gant.Gant.compileScript(Gant.groovy:631)
    at gant.Gant.this$2$compileScript(Gant.groovy)
    a

This is because ApplicationHolder is used a class that was deprecated a while ago and now removed in 2.4

require-once directive?

(2nd question of the day :)

If I include two assets, both have a //= require knockout, then knockout.js gets included twice in the page (when environment is development).

Is there a way to only include that kind of dependency once?

Precompiled assets aren't served from non-root context paths

When you run your app from a non-development env. (like production) with an app context that is not '/', the precompiled assets aren't served, they just 404.

This problem occurs both with grails -Dgrails.env=production run-war (probably any non-development environment) and running the built war from a servlet container (on a non ROOT context).

I've created an almost blank test app with some bootstrap assets to easily reproduce this problem, found here: mordack/root-context-test

Steps to reproduce after cloning the repo:

grails asset-precompile
grails -Dgrails.env=production run-war

After navigating to http://localhost:8080/root-context-test/ when grails has booted up, none of the precompiled assets can be accessed. The links the the resources are properly generated, but they just 404 when accessed.

If you uncomment this line in Config.groovy, the precompiled assets are served just fine as expected when you try running it through run-war.

Conflicting application mappings

These mappings probably shouldn't be in the plugin, they break application mappings:

    "/$controller/$action?/$id?"{
        constraints {
            // apply constraints here
        }
    }

    "/"(view:"/index")
    "500"(view:'/error')

Compilation issue when running with JDK 8

I understand this is somewhat a big ask given both Groovy and Grails don't officially support JDK 8. Keep it low priority.

java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

| Error Compilation error: startup failed:
/Development/redenergy/epis/work/projects/epis/plugins/asset-pipeline-1.7.1/grails-app/controllers/asset/pipeline/AssetsController.groovy: -1: Repetitive method name/signature for method 'java.lang.Object withFormat(groovy.lang.Closure)' in class 'asset.pipeline.AssetsController'.
@ line -1, column -1.
/Development/redenergy/epis/work/projects/epis/plugins/asset-pipeline-1.7.1/grails-app/controllers/asset/pipeline/AssetsController.groovy: -1: Repetitive method name/signature for method 'java.lang.Object withFormat(groovy.lang.Closure)' in class 'asset.pipeline.AssetsController'.
@ line -1, column -1.
2 errors

UTF-8 Asset is not output as UTF-8

This is me again, which reported issue #62 and #63.

It seems that the version 1.5.7 does not properly fixed the issue. I am running Windows, and the served file is still corrupted.

I found that the AssetsController still uses response.outputStream to serve the file content, which does not specify the exact character encoding.

Here is a link related to a SO question: http://stackoverflow.com/questions/1992400/how-to-send-through-servletoutputstream-characters-in-utf-8-encoding

In issue #62 I have added the following code but it is not used in the plugin version 1.5.7:

  // if request encoding is specified, then server the content using 
  if (request.characterEncoding) {
    def w = response.writer
    w.write(assetFile)
    w.flush()
  } else {
    response.outputStream << assetFile
    response.flushBuffer()
}

make the plugin a runnable application

I know this is a bit controversial, but I like when a plugin is runnable instead of using separate app and referencing it as an inline plugin. The plugin should include just enough stuff to do grails run-app, in addition to including test controllers and assets that will not be included in the packaged plugin.

Angular-ui-bootstrap template issue

Apologies if I really shouldn't be posting about this here but I can't figure this out. There was an answered stack overflow question about this so didn't think I'd get much joy on there.

I've included angular-ui-bootstrap in the assets/javascripts/application.js and put the .js in the javascripts folder. Objects in the .js file are looking for a template url like so:

templateUrl:'template/alert/alert.html'

I've tried putting the template folder in every possible place inside the assets folder but I'm still getting a 404. Is this a issue or is this easy to resolve?

Cheers,

Tom

asset tag not working

While completing #9, I noticed that the asset tag tried to map a resource to /assets/<resource name>, but it should be /<app name>/assets/<resource name>. If #9 is merged this will be fixed. Just adding this issue so users know it is being addressed.

asset-pipeline doesn't handle plugins resources

For plugins resources Grails generates /js/..., /css/... urls but asset-pipeline doesn't process them.

Adding
"/css/$id**" (controller: 'assets', action: 'index') "/js/$id**" (controller: 'assets', action: 'index')
fixed this problem. May be this is not the best solution but it works... I think this is a bug

404 retrieving javascript asset in dev mode

I'm getting a 404 when retrieving an asset like /assets/knockout.min.js.

If I change its name to "knockout-min.js" then it works fine.

I tried debugging the request and I saw this issue:

I'm not sure why the format is "application/x-javascript". OS/browser: Safari 7.0/OS-X 10.9

Grails: 2.2.4

My config.groovy declares mime type js='application/javascript'

asset:stylesheet href required, src optional

Intellij rightly complains about <asset:stylesheet /> if it is used as per the doco, with a src attribute.

eg:

image

The tag actually says that href is required and src is optional so may I suggest that the doco should be updated to use href?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.