cgross / grunt-dom-munger

Grunt task to read and manipulate HTML with CSS selectors.
MIT License
93 stars 40 forks source link

Extend for a Source Map onto the writeto variable #33

Open D1no opened 9 years ago

D1no commented 9 years ago

Adds a source map of retrieved values according to the processed source, to make use of a source arrays. Extends to {writeto}SrcMap. Fixes #32

Example

grunt.initConfig({
        dom_munger: {
            your_target: {
                options: {
                    read: {
                        selector: 'script',
                        attribute: 'src',
                        // ->
                        writeto: 'jsRefs',
                        // <-
                        isPath: true
                    }
                },
                // Going through multiple html files, collecting javascript references
                src: ['html/*.html']
            },
        },
        log: {}
    });

Array of last processed document (jsRefs):

grunt.config.process(<%= dom_munger.data.jsRefs %>)

   [ 'html/assets/javascript5.js',
     'html/assets/javascript6.js' ]

Object source map with arrays of last processed document (jsRefsSrcMap):

grunt.config.process(<%= dom_munger.data.jsRefsSrcMap %>)

{ 'html/first.html': 
   [ 'html/assets/javascript1.js',
     'html/assets/javascript2.js' ],
  'html/second.html': 
   [ 'html/assets/javascript3.js',
     'html/assets/javascript4.js' ],
  'html/third.html': 
   [ 'html/assets/javascript5.js',
     'html/assets/javascript6.js' ]
}