Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parse pseudo-class function arguments#62

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletionlib/syntax_tree/css/format.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,6 +100,16 @@ def visit_pseudo_class_selector(node)
node.value.format(q)
end

# Visit a Selectors::PseudoClassFunction node.
def visit_pseudo_class_function(node)
q.text(node.name)
q.text("(")
q.seplist(node.arguments, -> { q.text(", ") }) do |selector|
selector.format(q)
end
q.text(")")
end

# Visit a Selectors::PseudoElementSelector node.
def visit_pseudo_element_selector(node)
q.text(":")
Expand DownExpand Up@@ -127,7 +137,6 @@ def visit_compound_selector(node)
node.child_nodes.each do |node_|
node_.format(q)
end
# TODO: pseudo-elements
end
end

Expand Down
18 changes: 15 additions & 3 deletionslib/syntax_tree/css/pretty_print.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -380,10 +380,19 @@ def visit_pseudo_class_function(node)
q.breakable
q.pp(node.name)

q.breakable
q.text("(arguments")

if node.arguments.any?
q.breakable
q.seplist(node.arguments) { |argument| q.pp(argument) }
q.nest(2) do
q.breakable
q.seplist(node.arguments) { |argument| q.pp(argument) }
end

q.breakable("")
end

q.text(")")
end
end

Expand DownExpand Up@@ -443,7 +452,10 @@ def visit_complex_selector(node)
def visit_compound_selector(node)
token("compound-selector") do
q.breakable
q.pp(node.type)
token("type") do
q.breakable
q.pp(node.type)
end

q.breakable
q.text("(subclasses")
Expand Down
3 changes: 2 additions & 1 deletionlib/syntax_tree/css/selectors.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -509,7 +509,8 @@ def pseudo_class_selector
PseudoClassSelector.new(value: consume(IdentToken))
in Function
node = consume(Function)
function = PseudoClassFunction.new(name: node.name, arguments: node.value)
arguments = Selectors.new(node.value).parse
function = PseudoClassFunction.new(name: node.name, arguments: arguments)
PseudoClassSelector.new(value: function)
else
raise MissingTokenError, "Expected pseudo class selector to produce something"
Expand Down
37 changes: 35 additions & 2 deletionstest/selectors_test.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,7 +82,7 @@ class SelectorsTest < Minitest::Spec
end
end

it "parses a compound selector with a pseudo-class" do
it "parses a compound selector with a pseudo-class selector" do
actual = parse_selectors("div.flex:hover")

assert_pattern do
Expand All@@ -98,6 +98,33 @@ class SelectorsTest < Minitest::Spec
end
end

it "parses a compound selector with a pseudo-class function" do
actual = parse_selectors(".flex:not(div, span.wide, .hidden)")

assert_pattern do
actual => [
Selectors::CompoundSelector[
type: nil,
subclasses: [
Selectors::ClassSelector[value: { value: "flex" }],
Selectors::PseudoClassSelector[
value: Selectors::PseudoClassFunction[
name: "not",
arguments: [
Selectors::TypeSelector[value: { name: { value: "div" } }],
Selectors::CompoundSelector[
Selectors::TypeSelector[value: { name: { value: "span" } }],
Selectors::ClassSelector[value: { value: "wide" }],
],
],
],
],
],
]
]
end
end

it "parses a compound selector with pseudo-elements and pseudo-classes" do
actual = parse_selectors("div.flex:hover::first-line:last-child:active::first-letter")

Expand DownExpand Up@@ -208,7 +235,6 @@ class SelectorsTest < Minitest::Spec
]
end
end

end

describe "formatting" do
Expand All@@ -227,6 +253,13 @@ class SelectorsTest < Minitest::Spec
)
end

it "with a pseudo-class function" do
assert_selector_format(
".flex:not(div, span.wide, .hidden)",
".flex:not(div, span.wide, .hidden)",
)
end

it "with class selectors" do
assert_selector_format(
"div.flex.text-xl",
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp