Преглед изворни кода

grunt-peg.js: use this.options introduced in grunt 0.4

Manfred Kroehnert пре 11 година
родитељ
комит
2b34af5ce6
2 измењених фајлова са 20 додато и 16 уклоњено
  1. 5 3
      Gruntfile.js
  2. 15 13
      grunt/tasks/grunt-peg.js

+ 5 - 3
Gruntfile.js

@@ -17,11 +17,13 @@ module.exports = function(grunt) {
 
     peg: {
       amber_parser: {
+        options: {
+          trackLineAndColumn: true,
+          cache: true,
+          export_var: 'smalltalk.parser'
+        },
         src: 'js/parser.pegjs',
         dest: 'js/parser.js',
-        trackLineAndColumn: true,
-        cache: true,
-        export_var: 'smalltalk.parser'
       }
     },
 

+ 15 - 13
grunt/tasks/grunt-peg.js

@@ -3,25 +3,27 @@ module.exports = function(grunt) {
   var PEG = require('pegjs');
 
   /**
-     Full config looks like this:
+    Full config looks like this:
     pegjs: {
        my_parser: {
-         src: 'parser.pegjs',        // REQUIRED
-         dest: 'parser.js',          // REQUIRED
-         trackLineAndColumn: true,      // optional (default: false)
-         cache: true,                   // optional (default: false)
-         export_var: 'smalltalk.parser' // optional (default: module.exports)
+         options: {                       // optional
+           trackLineAndColumn: true,      // default: false
+           cache: true,                   // default: false
+           export_var: 'smalltalk.parser' // default: module.exports
+         },
+         src: 'parser.pegjs',
+         dest: 'parser.js',
        }
      },
    */
   grunt.registerMultiTask('peg', 'Generate JavaScript parser from PEG.js grammar description', function() {
-    var pegOptions = {
-      cache: this.data.cache || false,
-      trackLineAndColumn: this.data.trackLineAndColumn || false
-    };
-    var export_var = this.data.export_var || 'module.exports';
-    var parser = PEG.buildParser(grunt.file.read(this.data.src), pegOptions);
-    var content = export_var + ' = ' + parser.toSource() + ';\n';
+    var options = this.options({
+      cache: false,
+      trackLineAndColumn: false,
+      export_var: 'module.exports'
+    });
+    var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
+    var content = options.export_var + ' = ' + parser.toSource() + ';\n';
     grunt.file.write(this.data.dest, content);
   });
 };