Skip to content

Commit

Permalink
Merge pull request #30 from yakworks/pass_location_on_attach_creation
Browse files Browse the repository at this point in the history
Pass location on attach creation
  • Loading branch information
basejump authored May 9, 2019
2 parents c3bd97d + 1b0cc1d commit 90b550f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ compile org.grails.plugins:view-tools:1.2.0
compile :view-tools:0.3-grails2
```

## Configuration
To make plugin look into grails3 folders add next line as a first line for you `BuildConfig.groovy`
```
grails.useGrails3FolderLayout = true
```

### ViewResourceLocator
**Example Bean**
```groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ class AppResourceLoader implements ResourceLoader, GrailsConfigurationAware {
* file: the File instace that we put in that directory
*/
@SuppressWarnings("ReturnsNullInsteadOfEmptyCollection")
Map createAttachmentFile(Long attachmentId, String name, String extension, Object data) {
Map createAttachmentFile(Long attachmentId, String name, String extension, Object data, String location = null) {
if (!data) return null
if(!location) location = ATTACHMENT_LOCATION_KEY
String prefix = ""
if (name) {
prefix = "${name}_"
Expand All @@ -139,7 +140,7 @@ class AppResourceLoader implements ResourceLoader, GrailsConfigurationAware {
String destFileName = extension ? "${prefix}${attachmentId}.${extension}" : "${prefix}${attachmentId}"

//setup the monthly dir for attachments
File monthDir = getMonthDirectory(ATTACHMENT_LOCATION_KEY)
File monthDir = getMonthDirectory(location)
File file = new File(monthDir, destFileName)
if (data) {
if (data instanceof File) FileUtils.moveFile(data, file)
Expand Down

0 comments on commit 90b550f

Please sign in to comment.