chunksnbits / grunt-template-render

Grunt template rendering with partial and translation support
MIT License
1 stars 0 forks source link

Cannot process more than one file #3

Open Codeschmied opened 7 years ago

Codeschmied commented 7 years ago

Both files work fine on their own, but as soon as I include both in my files-object, i get an error message (see below)

template: {
            build: {
                options: {
                    cwd:"app/pages/"
                },
                files: {
                    'app/slaveGame.html': ['app/src/slaveGame.tpl.html'],
                    'app/index.html': ['app/src/index.tpl.html']
                }
            }
        }

this is my filestructure:

root{
  'gruntfile.js',
  app{
            src{
               'slaveGame.tpl.html'
               'index.tpl.html'
            }
          pages:{
            'templates.html'
           }
    }
}

File "app\pages\templates.html" changed. Running "template:build" (template) task File app/slaveGame.html created. Warning: Source file app/pages/undefined not found. Use --force to continue.

chunksnbits commented 7 years ago

Hi,

looks correct at first glance and this is kinda hard to figure out without being able to access the sources / file structure.

From the error message I would guess it is an issue within any of the templates (most likely the index.html since the other seems to run find), i.e., please recheck all <%= render('path/to/content.tpl.html') %> statements.

Alternatively: Could you try to split the template into 2 subtasks, like:

template: {
  options: {
    cwd:"app/pages/"
  },
  slaveGame: {
    files: {
      'app/slaveGame.html': ['app/src/slaveGame.tpl.html']
    }
  },
  root: {
    files: {
      'app/index.html': ['app/src/index.tpl.html']
    }
}
Codeschmied commented 7 years ago

As I said, the error does not depend on any file. All files have their render-tag correct. The error occurs when I include both files. The order does not matter, the error comes after the first file has been processed. I tried your subtask approach. The subtasks seem to not be interpreted. The tool does not try to process them. Could you maybe build a running example that has more than one file?

zakzag commented 7 years ago

Codesmied, you're right, quickfix: go into templates.js, look for "var originalOptions = evaluateFunctions(options);" in line #97, move it from the including .each as it not necessary to evaluate them in each iteration, so it shoud look like: `
var originalOptions = evaluateFunctions(options); // Iterate over all specified file groups. this.files.forEach(function(file) { var translations = options.translations || {'default': {}}; // Iterate over all translations provided _.each(translations, function(currentTranslation, language) {

`