Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

module option #10

Closed
geddski opened this Issue Mar 5, 2013 · 6 comments

Comments

Projects
None yet
3 participants
Contributor

geddski commented Mar 5, 2013

What about this idea: instead of creating app.templates module, just let people specify the name of the module to add templates to:

ngtemplates: {
      app: {
        src: ['app/templates/**/*.html'],
        dest: 'app/templates.js',
        module: 'app'
      }
    },

That way you wouldn't have to specify a dependency:

angular.module('app', []);

The benefit of this is you don't have to run a build before being able to use your app.

Owner

ericclemmons commented Mar 5, 2013

Hi! I don't know if I understand well enough, but I do know you can change app to whatever you'd like:

ngtemplates: {
  mymodule: {
    src: ['app/templates/**/*.html'],
    dest: 'mymodule/templates.js'
  }
},

This will create mymodule.templates. I can update the README if that helps.

As for the last line about "don't have to run a build", are you saying that you only want to use the templates as the app, without a "parent" module?

Thanks for opening an issue, btw!

Contributor

geddski commented Mar 5, 2013

Right, I get how it currently works. I mean instead of creating a new module named <module-name>.templates, the plugin could add the templates to the module.

So for example, say I have an angular module named app:

angular.module('app', []);

Now I tell the grunt plugin to add all my templates to it (rather than to a separate module):

ngtemplates: {
    app: {
        src: ['app/templates/**/*.html'],
        dest: 'app/templates.js',
        module: 'app'
      }
  }

And now app/templates.js would look like this:

angular.module("app").run(["$templateCache", function($templateCache) {

  $templateCache.put("app/templates/partial1.html",
    "<h1>Users</h1>"...
  );

  $templateCache.put("app/templates/partial2.html",
    "<p>This is the partial for view 2.</p>"...
  );

}]);

Does that make sense? So it adds the templates to my app module, rather than to a separate module that I need to declare as a dependency to my module.

Owner

ericclemmons commented Mar 5, 2013

Ooh!! I see! I like that a lot better! :D

The one downside is that you'd have to ensure the template is included after the fact (whereas app.templates can be included before or after other module files), but I think that's a trivial downside.

kwhitley commented Mar 5, 2013

I like this!

👍 @GEDDesign

Contributor

geddski commented Mar 5, 2013

Wow that was fast! Rock on dudes. This is a great improvement.

Owner

ericclemmons commented Mar 6, 2013

Thanks for the PR! Take a look @ some of my other grunt projects & open up issues if you see anything!

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