Directly returning AMD templates from the wrapper #24

Merged
merged 2 commits into from Feb 8, 2013

Projects

None yet

6 participants

@mehcode
Contributor
mehcode commented Feb 3, 2013

If you submit a PR for this, it needs to support both types of compilation, and it should return the template directly only if namespace is set to false.

Thank you; that's a reasonable compromise. This only takes effect if you explicitly set namespace to false.

@mehcode mehcode referenced this pull request in chaplinjs/chaplin Feb 3, 2013
Closed

Compiling the brunch-chaplin boilerplate with grunt #414

@pulse00
pulse00 commented Feb 3, 2013

👍

@tkellen
Member
tkellen commented Feb 4, 2013

We need some documentation for this in docs/handlebars-options.md under the namespace option. Once that is in place I would be happy to merge/publish this. Thanks, Ryan!

@okhomenko

It would be great to have return this['JST']['template_path'] with amd: true, namespace: 'JST' because now it's just

return this['JST']

something like okhomenko/grunt-contrib-handlebars@742029a

@tkellen
Member
tkellen commented Feb 5, 2013

That's exactly what this PR does. As soon as the docs are in place we'll publish it.

@okhomenko

concordusapps/grunt-contrib-handlebars@ecc81ef#L1R121
Line 121: just returns

  return this["JST"]; 

instead of

  return this["JST"]["src/templates/item.hbs"];

So in case expand: true

output.push("return "+nsInfo.namespace+"[" + JSON.stringify(f.src.pop()) + "]" +";");

will do the job

@tkellen
Member
tkellen commented Feb 5, 2013

Sorry Oleksandr, I don't think I follow what you're saying. This pull request returns templates directly from an AMD module when namespace is set to false. Is that what you want? If so, it will be supported after this PR is merged.

@okhomenko

Sorry. I'm talking about case when we have option namespace !== false.
#23

@tkellen
Member
tkellen commented Feb 5, 2013

There must be something lost in translation here? Both methods will be supported when this PR is merged.

If you want to return an object containing all of the templates keyed by filename, set amd true and don't configure a namespace.
If you want to return the templates directly you must set amd true and namespace false

@okhomenko

Correct. Try this case:

  handlebars: {
    app: {
      options: {
        amd: true 
      },
      expand: true,
      cwd: 'src/',
      src: '**/*.hbs',
      dest: 'app/',
      ext: '.js'
    }
  }

in this case we got separate files for every .hbs with return this["JST"]

and in module we use:

define([
  'template/module_name/template_name'
], function (Template) {
  console.log(Template);
});

Template here is array of templates, but not exact template.

@tkellen
Member
tkellen commented Feb 5, 2013

Correct, and once this PR is merged, you'll be able to do:

  handlebars: {
    app: {
      options: {
        amd: true,
        namespace: false
      },
      expand: true,
      cwd: 'src/',
      src: '**/*.hbs',
      dest: 'app/',
      ext: '.js'
    }
  }

...to get return Handlebars.template(...)

@okhomenko

Yes, great, thanks. Just have tried this PR and it works good

@tkellen
Member
tkellen commented Feb 8, 2013

@mehcode We need some documentation for this in docs/handlebars-options.md under the namespace option. Once that is in place I would be happy to merge/publish this.

@mehcode
Contributor
mehcode commented Feb 8, 2013

Something like that @tkellen? Or would you like some examples as well?
Sorry for taking so long on the turn around for this.

@tkellen
Member
tkellen commented Feb 8, 2013

That'll do! Thanks :)

@tkellen tkellen merged commit 677b6ec into gruntjs:master Feb 8, 2013

1 check passed

default The Travis build passed
Details
@OliverJAsh

It would be good to get some documentation on these options:

      expand: true,
      cwd: 'src/',
      src: '**/*.hbs',
      dest: 'app/',
      ext: '.js'
@tkellen
Member
tkellen commented Feb 12, 2013

http://github.com/gruntjs/grunt/wiki/Configuring-tasks (building the files object dynamically).

@cowboy
Member
cowboy commented Feb 12, 2013

Damn, beat me to it!

@OliverJAsh

Ahh, they are Grunt options. I apologise!

Is it possible to achieve separate AMD modules – one for each template – without using these options (just using the standard files object)?

@tkellen
Member
tkellen commented Feb 12, 2013

Not unless you want to manually specify every file. The aforementioned configuration format lets you glob for a directory of files, then it builds the files object for you, mapping each one to a new destination file.

@cowboy
Member
cowboy commented Feb 12, 2013

If you look at the Configuring Tasks guide "Building the files object dynamically" section, you'll see 2 versions of src-dest file mappings, one specified manually, the other generated via grunt dynamic mapping options. You'll probably want to use the dynamic one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment