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

Split up combinators logic#64

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
kddnewton merged 1 commit intomainfromsplit-combinators
Jun 28, 2024
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
1 change: 1 addition & 0 deletionsGemfile.lock
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@ GEM
prettier_print (>= 1.2.0)

PLATFORMS
arm64-darwin-23
x86_64-darwin-21
x86_64-linux

Expand Down
110 changes: 64 additions & 46 deletionslib/syntax_tree/css/format.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,13 +42,13 @@ def visit_delim_token(node)
q.text(node.value)
end

# Visitan IdentToken node.
defvisit_ident_token(node)
# Visita HashToken node.
defvisit_hash_token(node)
q.text(node.value)
end

# Visita HashToken node.
defvisit_hash_token(node)
# Visitan IdentToken node.
defvisit_ident_token(node)
q.text(node.value)
end

Expand All@@ -70,28 +70,79 @@ def visit_style_rule(node)
end
end

# Visit a Selectors::SubsequentSiblingCombinator node.
def visit_subsequent_sibling_combinator(node)
q.text(" ")
node.value.format(q)
q.text(" ")
end

#-------------------------------------------------------------------------
# Selector nodes
#-------------------------------------------------------------------------

# Visit a Selectors::TypeSelector node.
def visit_type_selector(node)
# Visit a Selectors::ChildCombinator node.
def visit_child_combinator(node)
q.text(" ")
node.value.format(q)
q.text(" ")
end

# Visit a Selectors::ClassSelector node.
def visit_class_selector(node)
q.text(".")
node.value.format(q)
end

# Visit a Selectors::ColumnSiblingCombinator node.
def visit_column_sibling_combinator(node)
q.text(" ")
node.value.each { |value| value.format(q) }
q.text(" ")
end

# Visit a Selectors::ComplexSelector node.
def visit_complex_selector(node)
q.group do
node.prefix.format(q) if node.prefix
node.value.format(q)
node.child_nodes.each do |child_node|
child_node.format(q)
end
end
end

# Visit a Selectors::CompoundSelector node.
def visit_compound_selector(node)
q.group do
node.child_nodes.each do |child_node|
child_node.format(q)
end
end
end

# Visit a Selectors::DescendantCombinator node.
def visit_descendant_combinator(node)
q.text(" ")
end

# Visit a Selectors::IdSelector node.
def visit_id_selector(node)
q.text("#")
node.value.format(q)
end

# Visit a Selectors::ClassSelector node.
defvisit_class_selector(node)
q.text(".")
# Visit a Selectors::NextSiblingCombinator node.
defvisit_next_sibling_combinator(node)
q.text("")
node.value.format(q)
q.text(" ")
end

# Visit a Selectors::TypeSelector node.
def visit_type_selector(node)
q.group do
node.prefix&.format(q)
node.value.format(q)
end
end

# Visit a Selectors::PseudoClassSelector node.
Expand All@@ -116,42 +167,9 @@ def visit_pseudo_element_selector(node)
node.value.format(q)
end

# Visit a Selectors::Combinator node.
def visit_combinator(node)
case node.value
when WhitespaceToken
q.text(" ")
when Array
q.text(" ")
node.value.each { |val| val.format(q) }
q.text(" ")
else
q.text(" ")
node.value.format(q)
q.text(" ")
end
end

# Visit a Selectors::ComplexSelector node.
def visit_complex_selector(node)
q.group do
node.child_nodes.each_with_index do |child_node, j|
child_node.format(q)
end
end
end

# Visit a Selectors::CompoundSelector node.
def visit_compound_selector(node)
q.group do
node.child_nodes.each do |node_|
node_.format(q)
end
end
end

# Visit a Selectors::WqName node.
def visit_wqname(node)
node.prefix.format(q) if node.prefix
node.prefix&.format(q)
node.name.format(q)
end
end
Expand Down
150 changes: 91 additions & 59 deletionslib/syntax_tree/css/pretty_print.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -350,6 +350,73 @@ def visit_whitespace_token(node)
# Selector nodes
#-------------------------------------------------------------------------

# Visit a Selectors::ChildCombinator node.
def visit_child_combinator(node)
token("child-combinator") do
q.breakable
q.pp(node.value)
end
end

# Visit a Selectors::ColumnSiblingCombinator node.
def visit_column_sibling_combinator(node)
token("column-sibling-combinator") do
q.breakable
q.pp(node.value)
end
end

# Visit a Selectors::ComplexSelector node.
def visit_complex_selector(node)
token("complex-selector") do
node.child_nodes.each do |child|
q.breakable
q.pp(child)
end
end
end

# Visit a Selectors::CompoundSelector node.
def visit_compound_selector(node)
token("compound-selector") do
q.breakable
token("type") do
q.breakable
q.pp(node.type)
end

q.breakable
q.text("(subclasses")

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

q.breakable("")
end

q.text(")")

q.breakable("")
q.text("(pseudo-elements")

if node.pseudo_elements.any?
q.nest(2) do
q.breakable
q.seplist(node.pseudo_elements) do |pseudo_element|
q.pp(pseudo_element)
end
end

q.breakable("")
end

q.text(")")
end
end

# Visit a Selectors::ClassSelector node.
def visit_class_selector(node)
token("class-selector") do
Expand All@@ -358,6 +425,14 @@ def visit_class_selector(node)
end
end

# Visit a Selectors::DescendantCombinator node.
def visit_descendant_combinator(node)
token("descendant-combinator") do
q.breakable
q.pp(node.value)
end
end

# Visit a Selectors::IdSelector node.
def visit_id_selector(node)
token("id-selector") do
Expand All@@ -366,6 +441,14 @@ def visit_id_selector(node)
end
end

# Visit a Selectors::NextSiblingCombinator node.
def visit_next_sibling_combinator(node)
token("next-sibling-combinator") do
q.breakable
q.pp(node.value)
end
end

# Visit a Selectors::PseudoClassSelector node.
def visit_pseudo_class_selector(node)
token("pseudo-class-selector") do
Expand DownExpand Up@@ -404,6 +487,14 @@ def visit_pseudo_element_selector(node)
end
end

# Visit a Selectors::SubsequentSiblingCombinator node.
def visit_subsequent_sibling_combinator(node)
token("subsequent-sibling-combinator") do
q.breakable
q.pp(node.value)
end
end

# Visit a Selectors::TypeSelector node.
def visit_type_selector(node)
token("type-selector") do
Expand All@@ -430,65 +521,6 @@ def visit_wqname(node)
end
end

# Visit a Selectors::Combinator node.
def visit_combinator(node)
token(node.class::PP_NAME) do
q.breakable
q.pp(node.value)
end
end

# Visit a Selectors::ComplexSelector node.
def visit_complex_selector(node)
token("complex-selector") do
node.child_nodes.each do |child|
q.breakable
q.pp(child)
end
end
end

# Visit a Selectors::CompoundSelector node.
def visit_compound_selector(node)
token("compound-selector") do
q.breakable
token("type") do
q.breakable
q.pp(node.type)
end

q.breakable
q.text("(subclasses")

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

q.breakable("")
end

q.text(")")

q.breakable("")
q.text("(pseudo-elements")

if node.pseudo_elements.any?
q.nest(2) do
q.breakable
q.seplist(node.pseudo_elements) do |pseudo_element|
q.pp(pseudo_element)
end
end

q.breakable("")
end

q.text(")")
end
end

private

def token(name)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp