Parsing support for the :last-child pseudo class.

This commit is contained in:
Yorick Peterse 2014-11-03 22:58:08 +01:00
parent b4fec3cc8c
commit 7a606a11d3
2 changed files with 24 additions and 0 deletions
lib/oga/css
spec/oga/css/parser/pseudo_classes

View File

@ -501,6 +501,19 @@ end
)
end
##
# Generates the AST for the `:last-child` selector.
#
# @return [AST::Node]
#
def on_pseudo_class_last_child
return s(
:eq,
s(:call, 'count', s(:axis, 'following-sibling', s(:test, nil, '*'))),
s(:int, 0)
)
end
private
##

View File

@ -0,0 +1,11 @@
require 'spec_helper'
describe Oga::CSS::Parser do
context ':last-child pseudo class' do
example 'parse the :last-child pseudo class' do
parse_css(':last-child').should == parse_xpath(
'descendant-or-self::*[count(following-sibling::*) = 0]'
)
end
end
end