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

Inline filters #59

Closed
wants to merge 1 commit into from
Closed

Inline filters #59

wants to merge 1 commit into from

Conversation

@matej21
Copy link
Contributor

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

foxycode commented Mar 18, 2015

👍

@matej21

This comment has been minimized.

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.

@dg dg force-pushed the nette:master branch from 603d787 to b9c165f May 22, 2015
@matej21 matej21 changed the title [PROOF OF CONCEPT] Inline filters Inline filters May 27, 2015
@dg dg force-pushed the nette:master branch 6 times, most recently from 275379c to 4cdcd65 Jun 18, 2015
@dg dg force-pushed the nette:master branch from e55ac11 to 29929e5 Jul 12, 2015
@dg dg force-pushed the nette:master branch 6 times, most recently from 7a0b003 to 89ae5db Oct 5, 2015
@dg dg force-pushed the nette:master branch 3 times, most recently from 08e21e6 to e23f9de Nov 5, 2015
@dg dg force-pushed the nette:master branch from ad57b9e to 8645679 Feb 20, 2016
@dg dg force-pushed the nette:master branch 3 times, most recently from 4ca485f to efac014 Mar 17, 2016
@matej21 matej21 force-pushed the matej21:feature/inline_filters branch from e5dd124 to ed8d395 Apr 16, 2016
@dg dg force-pushed the nette:master branch 2 times, most recently from ef2f4b7 to f42fbe9 Apr 21, 2016
@matej21 matej21 force-pushed the matej21:feature/inline_filters branch from ed8d395 to e1707a7 Apr 22, 2016
@matej21

This comment has been minimized.

Copy link
Contributor Author

matej21 commented Apr 22, 2016

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

@dg

This comment has been minimized.

Copy link
Member

dg commented Apr 23, 2016

Great, thanks!

@dg dg closed this in 5911348 Apr 23, 2016
dg added a commit that referenced this pull request Apr 23, 2016
dg added a commit that referenced this pull request Apr 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.