Consolidate pretty printing structs
This commit is contained in:
parent
05d67e404d
commit
3722ca98a0
@ -2,10 +2,6 @@ use std::io::{self, Write};
|
|||||||
|
|
||||||
use crate::{RuleSet, Stmt, Style, StyleSheet};
|
use crate::{RuleSet, Stmt, Style, StyleSheet};
|
||||||
|
|
||||||
/// Pretty print SCSS
|
|
||||||
///
|
|
||||||
/// The result should be an exact copy of the SCSS input
|
|
||||||
/// Empty rules are included
|
|
||||||
pub(crate) struct PrettyPrinter<W: Write> {
|
pub(crate) struct PrettyPrinter<W: Write> {
|
||||||
buf: W,
|
buf: W,
|
||||||
scope: usize,
|
scope: usize,
|
||||||
@ -16,6 +12,8 @@ impl<W: Write> PrettyPrinter<W> {
|
|||||||
PrettyPrinter { buf, scope: 0 }
|
PrettyPrinter { buf, scope: 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pretty print `crate::Stmt`
|
||||||
|
/// Throws away super selectors
|
||||||
fn pretty_print_stmt(&mut self, stmt: &Stmt) -> io::Result<()> {
|
fn pretty_print_stmt(&mut self, stmt: &Stmt) -> io::Result<()> {
|
||||||
let padding = vec![' '; self.scope * 2].iter().collect::<String>();
|
let padding = vec![' '; self.scope * 2].iter().collect::<String>();
|
||||||
match stmt {
|
match stmt {
|
||||||
@ -47,26 +45,20 @@ impl<W: Write> PrettyPrinter<W> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pretty_print(&mut self, s: &StyleSheet) -> io::Result<()> {
|
/// Pretty print SCSS
|
||||||
|
///
|
||||||
|
/// The result should be an exact copy of the SCSS input
|
||||||
|
/// Empty rules are included
|
||||||
|
pub fn pretty_print(&mut self, s: &StyleSheet) -> io::Result<()> {
|
||||||
for rule in &s.rules {
|
for rule in &s.rules {
|
||||||
self.pretty_print_stmt(rule)?;
|
self.pretty_print_stmt(rule)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Used solely in debugging to ensure that selectors aren't the issue
|
/// Pretty print `crate::Stmt`
|
||||||
pub(crate) struct CssPrettyPrinter<W: Write> {
|
/// Keeps super selectors
|
||||||
buf: W,
|
fn pretty_print_stmt_preserve_super_selectors(&mut self, stmt: &Stmt) -> io::Result<()> {
|
||||||
scope: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<W: Write> CssPrettyPrinter<W> {
|
|
||||||
pub(crate) fn new(buf: W) -> Self {
|
|
||||||
CssPrettyPrinter { buf, scope: 0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pretty_print_stmt(&mut self, stmt: &Stmt) -> io::Result<()> {
|
|
||||||
let padding = vec![' '; self.scope * 2].iter().collect::<String>();
|
let padding = vec![' '; self.scope * 2].iter().collect::<String>();
|
||||||
match stmt {
|
match stmt {
|
||||||
Stmt::RuleSet(RuleSet {
|
Stmt::RuleSet(RuleSet {
|
||||||
@ -104,7 +96,10 @@ impl<W: Write> CssPrettyPrinter<W> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pretty_print(&mut self, s: &StyleSheet) -> io::Result<()> {
|
/// Pretty print a special form of SCSS that shows what the full selectors are for children
|
||||||
|
/// Meant for debugging
|
||||||
|
/// Empty rules are included
|
||||||
|
pub(crate) fn pretty_print_preserve_super_selectors(&mut self, s: &StyleSheet) -> io::Result<()> {
|
||||||
for rule in &s.rules {
|
for rule in &s.rules {
|
||||||
self.pretty_print_stmt(rule)?;
|
self.pretty_print_stmt(rule)?;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user