Skip to content

Commit

Permalink
just modify the selector
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 17, 2015
1 parent 0e9eb7f commit 204cb1c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 6 additions & 9 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -101,20 +101,17 @@ sub _compile {
# Pseudo-class
elsif ($css =~ /\G:([\w\-]+)(?:\(((?:\([^)]+\)|[^)])+)\))?/gcs) {
my ($name, $args) = (lc $1, $2);
push @$last, my $pc = ['pc', $name];

# ":not" (contains more selectors)
if ($name eq 'not') { push @$last, ['pc', $name, _compile($args)] }
$pc->[2] = _compile($args) if $name eq 'not';

# ":first-*" or ":last-*" (rewrite to ":nth-*")
elsif ($name =~ s/^(?:(first)|last)-//) {
push @$last,
['pc', $1 ? ("nth-$name", [0, 1]) : ("nth-last-$name", [-1, 1])];
}
@$pc[1, 2] = $1 ? ("nth-$2", [0, 1]) : ("nth-last-$2", [-1, 1])
if $name =~ /^(?:(first)|last)-(.+)$/;

# "nth-*"
elsif ($name =~ /^nth-/) { push @$last, ['pc', $name, _equation($args)] }

else { push @$last, ['pc', $name] }
# "nth-*" (with An+B notation)
$pc->[2] = _equation($args) if $name =~ /^nth-/;
}

# Tag
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojolicious/Plugin/Mount.pm
Expand Up @@ -12,10 +12,8 @@ sub register {

# Extract host
my $host;
if ($path =~ m!^(\*\.)?([^/]+)(/.*)?$!) {
$host = $1 ? qr/^(?:.*\.)?\Q$2\E$/i : qr/^\Q$2\E$/i;
$path = $3;
}
($host, $path) = ($1 ? qr/^(?:.*\.)?\Q$2\E$/i : qr/^\Q$2\E$/i, $3)
if $path =~ m!^(\*\.)?([^/]+)(/.*)?$!;

my $route = $app->routes->route($path)->detour(app => $embed);
return $host ? $route->over(host => $host) : $route;
Expand Down

0 comments on commit 204cb1c

Please sign in to comment.