Sha256: edaa46839013fe1616c28c429a111e1245516dcf8ebc1a33dba0cf1e6bf847df

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module.exports = function(grunt) {

  grunt.initConfig({
    watch: {
      templates: {
        files: 'app/assets/templates/*.html',
        tasks: 'html2js:directives'
      }
    },

    html2js: {
      directives: ['app/assets/templates/*.html']
    }
  });

  var TPL = 'angular.module("<%= file %>", []).run(function($templateCache) {\n' + '  $templateCache.put("<%= path %>",\n    "<%= content %>");\n' + '});\n';

  var escapeContent = function(content) {
    return content.replace(/"/g, '\\"').replace(/\n/g, '" +\n    "');
  };

  grunt.registerMultiTask('html2js', 'Generate js version of html template.', function() {
    var files = grunt._watch_changed_files || grunt.file.expand(this.data);

    files.forEach(function(file) {
      var parts = file.split("/");
      var name = parts[parts.length - 1];

      grunt.file.write("app/assets/javascripts/templates/" + name + '.js', grunt.template.process(TPL, {
        file: file,
        path: "/ng/templates/" + file.split("/").pop(),
        content: escapeContent(grunt.file.read(file))
      }));
    });
  });
};

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo_browser-0.2.0.rc2 grunt.js