3

I'm creating a system that can read through any file (php, jsp, html, etc), locate block tags, and do a replacement based on the information in the block tag.

Code I would write into my file:

<!-- build:<name> -->
    {
        "testObject": {
             "name": "jonathan",
             "number": 3,
             "male": true
         }
    }
<!-- endBuild -->

Desired replacement:

<h1>Jonathan</h1>
<p>is a male and is positioned at #3.</p>

As you may notice, I've used components of gulp-html-replace. I've researched gulp-data and know how to use gulp.src and gulp.dest to build out files. Just missing the read, build, and replace the object step. Ideally this will work on multiple object instances throughout the document. Thanks.

toad
  • 400
  • 2
  • 13

1 Answers1

3

Because Gulp uses a pipe system and all the files become streams, you can write your own pipe/plug-in to process files in very specific ways. Check out Gulp Writing Plugins, section Modifying file content.

Notable Mention

gulp-replace might actually do the trick

Wilmer SH
  • 1,417
  • 12
  • 20
  • I think you're on to something here. gulp-replace allows a regex search parameter and stores it for use. I'm going to try it out with just that plugin before trying to build up one. Thanks! – toad Mar 31 '16 at 15:15
  • 1
    gulp-replace also uses a string as input in addition to regex. – Wilmer SH Mar 31 '16 at 15:22
  • Yeah, I saw that too. Since my objects will change throughout the page, I think regex is the way to go for this use case. – toad Mar 31 '16 at 15:31
  • Awesomeness. If you can, mark this as the right answer. Cheers. – Wilmer SH Mar 31 '16 at 15:35