Skip to content

Instantly share code, notes, and snippets.

@wouterj
Last active August 29, 2015 14:01

Revisions

  1. wouterj revised this gist May 10, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions issue_3826.php
    Original file line number Diff line number Diff line change
    @@ -37,12 +37,12 @@ function remove_dollars(Editor $editor, File $file) {
    $editor->moveDown($file);

    while ((bool) preg_match('/^ /', $line = $lines[$file->getCurrentLineNumber()]) || '' === $line) {
    if ('app' === substr(trim($line), 0, 3)) {
    $editor->replaceWith($file, '/app/', 'php app');
    if ('' !== $line) {
    $editor->replaceWith($file, '/\$ /', '');
    }

    $editor->moveDown($file);
    }

    remove_dollars($editor, $file);
    }
    }
  2. wouterj revised this gist May 10, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion issue_3826.php
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@

    require_once __DIR__.'/../vendor/autoload.php';

    use Wj\fn as f;
    use Gnugat\Redaktilo\Filesystem;
    use Gnugat\Redaktilo\Editor;
    use Gnugat\Redaktilo\File;
  3. wouterj created this gist May 10, 2014.
    49 changes: 49 additions & 0 deletions issue_3826.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    <?php

    require_once __DIR__.'/../vendor/autoload.php';

    use Wj\fn as f;
    use Gnugat\Redaktilo\Filesystem;
    use Gnugat\Redaktilo\Editor;
    use Gnugat\Redaktilo\File;
    use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;

    $symfonyFilesystem = new SymfonyFilesystem();
    $filesystem = new Filesystem($symfonyFilesystem);
    $editor = new Editor($filesystem);

    $files = new \RegexIterator(
    new \RecursiveIteratorIterator(
    new \RecursiveDirectoryIterator(__DIR__.'/../')
    ), '/\.rst(?:\.inc)?$/',
    \RegexIterator::MATCH
    );

    foreach ($files as $filename) {
    $file = $editor->open($filename);

    try {
    remove_dollars($editor, $file);
    } catch (\Exception $e) {
    }

    echo $filename, PHP_EOL;

    $editor->save($file);
    }

    function remove_dollars(Editor $editor, File $file) {
    $editor->jumpDownTo($file, '.. code-block:: bash');
    $lines = $file->readlines();
    $editor->moveDown($file);

    while ((bool) preg_match('/^ /', $line = $lines[$file->getCurrentLineNumber()]) || '' === $line) {
    if ('app' === substr(trim($line), 0, 3)) {
    $editor->replaceWith($file, '/app/', 'php app');
    }

    $editor->moveDown($file);
    }

    remove_dollars($editor, $file);
    }