Use a helper method for transforming CSS ASTs.
This commit is contained in:
parent
a85cd7cbd1
commit
7ccd685acb
|
|
@ -2,34 +2,12 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::CSS::Transformer do
|
describe Oga::CSS::Transformer do
|
||||||
context 'classes' do
|
context 'classes' do
|
||||||
before do
|
|
||||||
@transformer = described_class.new
|
|
||||||
end
|
|
||||||
|
|
||||||
example 'convert a class node without a node test' do
|
example 'convert a class node without a node test' do
|
||||||
@transformer.process(parse_css('.y')).should == s(
|
transform_css('.y').should == parse_xpath('*[@class="y"]')
|
||||||
:axis,
|
|
||||||
'child',
|
|
||||||
s(
|
|
||||||
:test,
|
|
||||||
nil,
|
|
||||||
'*',
|
|
||||||
s(:eq, s(:axis, 'attribute', s(:test, nil, 'class')), s(:string, 'y'))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
example 'convert a class node with a node test' do
|
example 'convert a class node with a node test' do
|
||||||
@transformer.process(parse_css('x.y')).should == s(
|
transform_css('x.y').should == parse_xpath('x[@class="y"]')
|
||||||
:axis,
|
|
||||||
'child',
|
|
||||||
s(
|
|
||||||
:test,
|
|
||||||
nil,
|
|
||||||
'x',
|
|
||||||
s(:eq, s(:axis, 'attribute', s(:test, nil, 'class')), s(:string, 'y'))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -89,5 +89,17 @@ module Oga
|
||||||
rescue Racc::ParseError => error
|
rescue Racc::ParseError => error
|
||||||
return error.message
|
return error.message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Parses and transforms a CSS AST into an XPath AST.
|
||||||
|
#
|
||||||
|
# @param [String] css
|
||||||
|
# @return [AST::Node]
|
||||||
|
#
|
||||||
|
def transform_css(css)
|
||||||
|
ast = parse_css(css)
|
||||||
|
|
||||||
|
return Oga::CSS::Transformer.new.process(ast)
|
||||||
|
end
|
||||||
end # ParsingHelpers
|
end # ParsingHelpers
|
||||||
end # Oga
|
end # Oga
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue