Skip to content

Conversation

@matej21
Copy link
Contributor

@matej21 matej21 commented Feb 22, 2015

Motivation:
Sometimes I need to apply the filter only on a part of macro arguments.

Current state:

{link default foo => $template->mod2($template->mod($name, 123))}

Proposal:

{link this slug => ($name|mod:123|mod2)}

You can also use inline filters on arguments of other filters

{$foo|replace:'foo':($replacement|lower)}

@dg dg added this to the v2.4 milestone Mar 9, 2015
@dg
Copy link
Member

dg commented Mar 14, 2015

BTW I tried it once implement this way:

    public function smartModifiersFilter(MacroTokens $tokens)
    {
        $inside = NULL;
        $brackets = array();
        $res = new MacroTokens;
        while ($tokens->nextToken()) {
            if ($tokens->isCurrent('(')) {
                $brackets[] = $res->position;

            } elseif ($tokens->isCurrent(')')) {
                if (array_pop($brackets) === $inside) {
                    $res->append(')');
                }

            } elseif ($tokens->isCurrent('|')) {
                if ($inside === end($brackets)) {
                    $res->append(')');
                }
                $name = $tokens->nextValue(MacroTokens::T_SYMBOL);
                if ($name === 'escape') {
                    $res = $this->escapeFilter($res, end($brackets));
                    $tokens->nextToken(')');
                    $inside = NULL;
                    continue;
                }

                $res->append('$template->' . $name . '(', end($brackets));
                $tokens->nextToken(',', ':');
                if ($tokens->isNext() && !$tokens->isNext(')', '|')) {
                    $res->append(',');
                }
                $inside = end($brackets);
                continue;

            } elseif ($tokens->isCurrent(':') && $inside === end($brackets)) {
                $res->append(',');
                continue;
            }

            $res->append($tokens->currentToken());
        }

        if ($inside !== NULL) {
            $res->append(')');
        }
        return $res;
    }

@foxycode
Copy link

👍

@matej21
Copy link
Contributor Author

matej21 commented Apr 22, 2015

Could anyone test that regexp on windows? There are some issues and I think this regexp modification might make it even worse.

@matej21 matej21 changed the title [PROOF OF CONCEPT] Inline filters Inline filters May 27, 2015
@dg dg force-pushed the master branch 6 times, most recently from 275379c to 4cdcd65 Compare June 19, 2015 12:26
@dg dg force-pushed the master branch 6 times, most recently from 7a0b003 to 89ae5db Compare October 12, 2015 17:32
@dg dg force-pushed the master branch 3 times, most recently from 08e21e6 to e23f9de Compare November 7, 2015 01:32
@dg dg force-pushed the master branch 3 times, most recently from 4ca485f to efac014 Compare March 17, 2016 23:38
@matej21 matej21 force-pushed the feature/inline_filters branch from e5dd124 to ed8d395 Compare April 16, 2016 16:01
@dg dg force-pushed the master branch 2 times, most recently from ef2f4b7 to f42fbe9 Compare April 21, 2016 13:01
@matej21 matej21 force-pushed the feature/inline_filters branch from ed8d395 to e1707a7 Compare April 22, 2016 13:14
@matej21
Copy link
Contributor Author

matej21 commented Apr 22, 2016

Could you please review it? I squashed it and I think it is ready :)

@dg
Copy link
Member

dg commented Apr 23, 2016

Great, thanks!

@dg dg closed this in 5911348 Apr 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants