Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for replace with callback function in documentation #77

Comments

@blaues0cke
Copy link

Missed this and had to grab the code from some pull requests. Will do this maybe later by myself. I used this to replace a placeholder everytime it gets matched with another class name:

var wallpapers = [
    'form',
    'drops',
    'circles',
    'fire',
    'flowers'
];
var wallpaperKey = 0;

subStream = subStream.pipe(plugins.replace('NEXTWALLPAPERCLASS', function ()
{
    var currentWallpaper = wallpapers[wallpaperKey];

    ++wallpaperKey;

    if (wallpaperKey >= wallpapers.length)
    {
        wallpaperKey = 0;
    }

    return 'wallpaper-' + currentWallpaper;
}));

So this will make:

<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>
<div class="NEXTWALLPAPERCLASS">Foo</div>

To:

<div class="form">Foo</div>
<div class="drops">Foo</div>
<div class="circles">Foo</div>
<div class="fire">Foo</div>
<div class="flowers">Foo</div>
@lazd
Copy link
Owner

lazd commented Mar 27, 2017

Yeah this is definitely missing. I'd accept a PR with a very clear and simple example.

@lazd lazd closed this as completed in 38be689 Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment