-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c9458d3
commit 7c940e4
Showing
15 changed files
with
838 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 30 additions & 3 deletions
33
crates/biome_css_formatter/src/css/auxiliary/page_at_rule_block.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssPageAtRuleBlock; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssPageAtRuleBlock, CssPageAtRuleBlockFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssPageAtRuleBlock; | ||
impl FormatNodeRule<CssPageAtRuleBlock> for FormatCssPageAtRuleBlock { | ||
fn fmt_fields(&self, node: &CssPageAtRuleBlock, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssPageAtRuleBlockFields { | ||
l_curly_token, | ||
items, | ||
r_curly_token, | ||
} = node.as_fields(); | ||
|
||
// When the list is empty, we still print a hard line to put the | ||
// closing curly on the next line. | ||
if items.is_empty() { | ||
write!( | ||
f, | ||
[ | ||
l_curly_token.format(), | ||
hard_line_break(), | ||
r_curly_token.format() | ||
] | ||
) | ||
} else { | ||
write!( | ||
f, | ||
[ | ||
l_curly_token.format(), | ||
block_indent(&items.format()), | ||
r_curly_token.format() | ||
] | ||
) | ||
} | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
crates/biome_css_formatter/src/css/auxiliary/page_selector_pseudo.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssPageSelectorPseudo; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssPageSelectorPseudo, CssPageSelectorPseudoFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssPageSelectorPseudo; | ||
impl FormatNodeRule<CssPageSelectorPseudo> for FormatCssPageSelectorPseudo { | ||
fn fmt_fields(&self, node: &CssPageSelectorPseudo, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssPageSelectorPseudoFields { | ||
colon_token, | ||
selector, | ||
} = node.as_fields(); | ||
|
||
write!(f, [colon_token.format(), selector.format()]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
crates/biome_css_formatter/src/css/lists/declaration_or_at_rule_list.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssDeclarationOrAtRuleList; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssDeclarationOrAtRuleList; | ||
impl FormatRule<CssDeclarationOrAtRuleList> for FormatCssDeclarationOrAtRuleList { | ||
type Context = CssFormatContext; | ||
fn fmt(&self, node: &CssDeclarationOrAtRuleList, f: &mut CssFormatter) -> FormatResult<()> { | ||
f.join().entries(node.iter().formatted()).finish() | ||
// This is one of the few cases where we _do_ want to respect empty | ||
// lines from the input, so we can use `join_nodes_with_hardline`. | ||
let mut join = f.join_nodes_with_hardline(); | ||
|
||
for declaration_or_at_rule in node { | ||
join.entry( | ||
declaration_or_at_rule.syntax(), | ||
&format_or_verbatim(declaration_or_at_rule.format()), | ||
); | ||
} | ||
|
||
join.finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
crates/biome_css_formatter/src/css/selectors/page_selector.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssPageSelector; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssPageSelector, CssPageSelectorFields}; | ||
use biome_formatter::{format_args, write}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssPageSelector; | ||
impl FormatNodeRule<CssPageSelector> for FormatCssPageSelector { | ||
fn fmt_fields(&self, node: &CssPageSelector, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssPageSelectorFields { ty, pseudos } = node.as_fields(); | ||
|
||
write!(f, [group(&format_args![ty.format(), pseudos.format()])]) | ||
} | ||
} |
16 changes: 13 additions & 3 deletions
16
crates/biome_css_formatter/src/css/statements/margin_at_rule.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssMarginAtRule; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssMarginAtRule, CssMarginAtRuleFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssMarginAtRule; | ||
impl FormatNodeRule<CssMarginAtRule> for FormatCssMarginAtRule { | ||
fn fmt_fields(&self, node: &CssMarginAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssMarginAtRuleFields { | ||
at_token, | ||
name, | ||
block, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[at_token.format(), name.format(), space(), block.format()] | ||
) | ||
} | ||
} |
22 changes: 19 additions & 3 deletions
22
crates/biome_css_formatter/src/css/statements/page_at_rule.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
use crate::prelude::*; | ||
use biome_css_syntax::CssPageAtRule; | ||
use biome_rowan::AstNode; | ||
use biome_css_syntax::{CssPageAtRule, CssPageAtRuleFields}; | ||
use biome_formatter::write; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub(crate) struct FormatCssPageAtRule; | ||
impl FormatNodeRule<CssPageAtRule> for FormatCssPageAtRule { | ||
fn fmt_fields(&self, node: &CssPageAtRule, f: &mut CssFormatter) -> FormatResult<()> { | ||
format_verbatim_node(node.syntax()).fmt(f) | ||
let CssPageAtRuleFields { | ||
page_token, | ||
selectors, | ||
block, | ||
} = node.as_fields(); | ||
|
||
write!( | ||
f, | ||
[ | ||
page_token.format(), | ||
space(), | ||
group(&indent(&selectors.format())), | ||
space(), | ||
block.format() | ||
] | ||
) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
crates/biome_css_formatter/tests/specs/css/atrule/page.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
@page{ } | ||
@page { | ||
|
||
|
||
} | ||
@page{margin: 1cm;} | ||
@page | ||
{ | ||
margin: 1cm;} | ||
@page :first {margin: 2cm;} | ||
@page | ||
:first | ||
{ | ||
|
||
margin: 2cm; | ||
|
||
} | ||
|
||
@page :left {} | ||
@page LandscapeTable {} | ||
@page CompanyLetterHead:first {} /* identifier and pseudo page. */ | ||
@page:first {} | ||
@page toc, index {} | ||
@page | ||
toc, | ||
index | ||
{} | ||
|
||
@page :blank:first { } | ||
|
||
@page { | ||
|
||
@top-left {} | ||
|
||
|
||
@bottom-center {} | ||
} | ||
|
||
@page :left { @left-middle {}} | ||
|
||
@page :right { | ||
|
||
@right-middle | ||
{ | ||
|
||
}} | ||
|
||
@page :first | ||
{ | ||
@bottom-left-corner {} | ||
@bottom-right-corner { | ||
|
||
} | ||
} | ||
|
||
@page :first { | ||
color: green; | ||
|
||
@top-left {content: "foo"; | ||
|
||
|
||
color: blue; | ||
} @top-right { content: "bar"; } | ||
} | ||
@page :first { | ||
color: green; | ||
|
||
@top-left { content: "foo"; color: blue; } @top-right { content: "bar"; } | ||
|
||
margin: 20px; | ||
} | ||
|
||
@page :FIRST {} | ||
@page :LEFT {} |
Oops, something went wrong.