Skip to content

Instantly share code, notes, and snippets.

@thomasfr
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save thomasfr/ce99404a4fe4f0335242 to your computer and use it in GitHub Desktop.

Select an option

Save thomasfr/ce99404a4fe4f0335242 to your computer and use it in GitHub Desktop.

Revisions

  1. Thomas Fritz revised this gist Mar 19, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion grunt-replace.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ options: {
    patterns: [
    {
    src: ['assets/js/**/*.js', 'assets/css/**/*.css',],
    match: /@@([^@]+?)@@/g,
    search: /@@([^@]+?)@@/g,
    replace: function(matched, part, offset, string) {
    if(summary[part]) {
    return summary[part];
  2. Thomas Fritz revised this gist Mar 19, 2015. 1 changed file with 15 additions and 4 deletions.
    19 changes: 15 additions & 4 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    var summary = {
    '/js/custom/index.js' : '/js/custom/index.a67bcd.js',
    '/js/custom/facilitySearch.js' : '/js/custom/facilitySearch.k89han.js',
    '/img/foo/bar/eversport.png' : '/img/foo/bar/eversport.9iasdui.png',
    };
    var match = /@@([^@]+?)@@/g;
    var string = `
    var search = /@@([^@]+?)@@/g;

    var htmlString = `
    block append scripts
    script(src="@@/js/custom/index.js@@")
    <script src="@@/js/custom/boostrap.js@@"></script>
    @@ -13,11 +15,20 @@ var string = `
    <script src="@@/js/custom/facilitySearch.js@@"></script>
    `;

    string.replace(match, function(matched, part, offset, string) {
    var cssString = `
    body {
    background-image: url('@@/img/foo/bar/eversport.png@@');
    }
    `;

    var replace = function(matched, part, offset, string) {
    if(summary[part]) {
    return summary[part];
    }
    else {
    return part;
    }
    });
    };

    htmlString.replace(search, replace);
    cssString.replace(search, replace);
  3. Thomas Fritz created this gist Mar 19, 2015.
    16 changes: 16 additions & 0 deletions grunt-replace.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    options: {
    patterns: [
    {
    src: ['assets/js/**/*.js', 'assets/css/**/*.css',],
    match: /@@([^@]+?)@@/g,
    replace: function(matched, part, offset, string) {
    if(summary[part]) {
    return summary[part];
    }
    else {
    return part;
    }
    }
    }
    ]
    }
    23 changes: 23 additions & 0 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    var summary = {
    '/js/custom/index.js' : '/js/custom/index.a67bcd.js',
    '/js/custom/facilitySearch.js' : '/js/custom/facilitySearch.k89han.js',
    };
    var match = /@@([^@]+?)@@/g;
    var string = `
    block append scripts
    script(src="@@/js/custom/index.js@@")
    <script src="@@/js/custom/boostrap.js@@"></script>
    <p>
    <h1>Hallo Welt</h1>
    </p>
    <script src="@@/js/custom/facilitySearch.js@@"></script>
    `;

    string.replace(match, function(matched, part, offset, string) {
    if(summary[part]) {
    return summary[part];
    }
    else {
    return part;
    }
    });