Skip to content

Commit

Permalink
Compatibility with asset-pipeline 2.0
Browse files Browse the repository at this point in the history
I make some minor changes for compatibility with asset-pipeline 2.0
after including pull request #2.  I update the README.md file, authors
in the source files, and version statements.
  • Loading branch information
dellermann committed Dec 5, 2014
1 parent 3121910 commit cefbcbe
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 38 deletions.
13 changes: 4 additions & 9 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry excluding="BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy" kind="src" path=".link_to_grails_plugins/asset-pipeline-1.9.9/grails-app/conf">
<classpathentry excluding="BuildConfig.groovy|*DataSource.groovy|UrlMappings.groovy|Config.groovy|BootStrap.groovy|spring/resources.groovy" kind="src" path=".link_to_grails_plugins/asset-pipeline-2.0.13/grails-app/conf">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-1.9.9/grails-app/controllers">
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-2.0.13/grails-app/services">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-1.9.9/grails-app/services">
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-2.0.13/grails-app/taglib">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-1.9.9/grails-app/taglib">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-1.9.9/src/groovy">
<classpathentry kind="src" path=".link_to_grails_plugins/asset-pipeline-2.0.13/src/groovy">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/*.zip.sha1
/plugin.xml
/target/
/web-app/WEB-INF/
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<link>
<name>.link_to_grails_plugins</name>
<type>2</type>
<locationURI>GRAILS_ROOT/2.4.3/projects/I18nAssetPipeline/plugins</locationURI>
<location>/home/dellermann/projects/i18n-asset-pipeline/target/plugins</location>
</link>
</linkedResources>
</projectDescription>
6 changes: 1 addition & 5 deletions I18nAssetPipelineGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
*/


import asset.pipeline.AssetHelper
import asset.pipeline.i18n.I18nAssetFile


class I18nAssetPipelineGrailsPlugin {
def version = '0.9.0'
def version = '1.0.0'
def grailsVersion = '2.2 > *'
def title = 'I18n Asset Pipeline Plugin'
def author = 'Daniel Ellermann'
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ client-side i18n.
For more information on how to use asset-pipeline, visit
[asset-pipeline project page][asset-pipeline].

Version information
-------------------

Because `asset-pipeline` 2.0.0 introduced a new API and isn't backward
compatible, you must use the following versions of this plugin:

* for `asset-pipeline` up to version 1.9.9 use version 0.9.0 of this plugin
* for `asset-pipeline` version 2.0.0 or higher use version 1.0.0 of this plugin

Usage
-----

Expand Down Expand Up @@ -75,7 +84,6 @@ To DRY, add a file `_messages.i18n` to `grails-app/assets/javascripts`:
# List of message codes that should be available on client-side.
#
# Add your messages codes here:
default.btn.cancel
default.btn.ok
Expand Down Expand Up @@ -114,7 +122,7 @@ Examples:
```

```html
<asset:i18n locale="${locale}" />
<asset:i18n name="texts" locale="${locale}" />
```

Author
Expand Down
7 changes: 7 additions & 0 deletions grails-app/taglib/asset/pipeline/I18nTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ package asset.pipeline
import org.codehaus.groovy.grails.commons.GrailsApplication


/**
* Class {@code I18nTagLib} contains tags that help loading client-side i18n
* files.
*
* @author Daniel Ellermann
* @version 1.0
*/
class I18nTagLib {

//-- Class variables ------------------------
Expand Down
19 changes: 9 additions & 10 deletions src/groovy/asset/pipeline/i18n/I18nAssetFile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import java.util.regex.Pattern
* keys to localized messages.
*
* @author Daniel Ellermann
* @version 0.9.0
* @author David Estes
* @version 1.0
*/
class I18nAssetFile extends AbstractAssetFile {

Expand All @@ -43,16 +44,19 @@ class I18nAssetFile extends AbstractAssetFile {
static final String compiledExtension = 'js'
static processors = [I18nProcessor]
Pattern directivePattern = ~/(?m)#=(.*)/
//-- Public methods -------------------------


//-- Public methods -------------------------

@Override
String processedStream(AssetCompiler precompiler) {
def skipCache = precompiler ?: (!processors || processors.size() == 0)

String fileText
if(baseFile?.encoding || encoding) {
fileText = inputStream?.getText(baseFile?.encoding ? baseFile.encoding : encoding)
fileText = inputStream?.getText(
baseFile?.encoding ? baseFile.encoding : encoding
)
} else {
fileText = inputStream?.text
}
Expand All @@ -61,9 +65,7 @@ class I18nAssetFile extends AbstractAssetFile {

def md5 = AssetHelper.getByteDigest(fileText.bytes)
if (!skipCache) {
def cache = CacheManager.findCache(
path, md5, baseFile?.path
)
def cache = CacheManager.findCache(path, md5, baseFile?.path)
if (cache) {
return cache
}
Expand All @@ -75,10 +77,7 @@ class I18nAssetFile extends AbstractAssetFile {
}

if (!skipCache) {
CacheManager.createCache(
path, md5, fileText,
baseFile?.path
)
CacheManager.createCache(path, md5, fileText, baseFile?.path)
}

fileText
Expand Down
26 changes: 18 additions & 8 deletions src/groovy/asset/pipeline/i18n/I18nPreprocessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package asset.pipeline.i18n

import asset.pipeline.AssetHelper
import asset.pipeline.AssetFile
import asset.pipeline.AssetHelper
import groovy.transform.CompileStatic
import java.util.regex.Matcher
import java.util.regex.Pattern
Expand All @@ -31,7 +31,8 @@ import java.util.regex.Pattern
* which are used in the asset pipeline.
*
* @author Daniel Ellermann
* @version 0.9.0
* @author David Estes
* @version 1.0
*/
@CompileStatic
class I18nPreprocessor {
Expand Down Expand Up @@ -79,8 +80,11 @@ class I18nPreprocessor {
* Pre-processes an i18n file by removing empty lines and comment lines and
* resolving all imports.
*
* @param input the content of the i18n file
* @return the pre-processed content
* @param input the content of the i18n file
* @param fileHistory the history of all import files that have been
* processed already; this is needed to handle
* circular dependencies
* @return the pre-processed content
*/
protected String preprocess(String input, Set<AssetFile> fileHistory) {
StringBuffer buf = new StringBuffer(input.length())
Expand All @@ -102,15 +106,21 @@ class I18nPreprocessor {
/**
* Loads the import file with the file name and processes its content.
*
* @param fileName the name of the import file
* @return the pre-processed content of the import file
* @param fileName the name of the import file
* @param fileHistory the history of all import files that have been
* processed already; this is needed to handle
* circular dependencies
* @return the pre-processed content of the import file
*/
protected String resolveImport(String fileName, Set<AssetFile> fileHistory) {
protected String resolveImport(String fileName,
Set<AssetFile> fileHistory)
{
if (!fileName.endsWith('.i18n')) {
fileName += '.i18n'
}

AssetFile importFile = (AssetFile) AssetHelper.fileForFullName(fileName)
AssetFile importFile =
(AssetFile) AssetHelper.fileForFullName(fileName)
if (importFile == null || importFile in fileHistory) {
return ''
}
Expand Down
5 changes: 2 additions & 3 deletions src/groovy/asset/pipeline/i18n/I18nProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ package asset.pipeline.i18n
import asset.pipeline.AbstractProcessor
import asset.pipeline.AssetCompiler
import asset.pipeline.AssetFile
import asset.pipeline.AssetHelper
import groovy.transform.CompileStatic
import java.util.regex.Matcher
import java.util.regex.Pattern
import org.springframework.core.io.DefaultResourceLoader
import org.springframework.core.io.Resource
import org.springframework.core.io.ResourceLoader
Expand Down Expand Up @@ -55,7 +53,8 @@ import org.springframework.core.io.ResourceLoader
* </ul>
*
* @author Daniel Ellermann
* @version 0.9.0
* @author David Estes
* @version 1.0
*/
class I18nProcessor extends AbstractProcessor {

Expand Down

0 comments on commit cefbcbe

Please sign in to comment.