Struct parcel_css::stylesheet::StyleSheet
source · [−]pub struct StyleSheet<'i, 'o> {
pub rules: CssRuleList<'i>,
pub sources: Vec<String>,
/* private fields */
}
Expand description
A CSS style sheet, representing a .css
file or inline <style>
element.
Style sheets can be parsed from a string, constructed from scratch, or created using a Bundler. Then, they can be minified and transformed for a set of target browsers, and serialied to a string.
Example
use parcel_css::stylesheet::{
StyleSheet, ParserOptions, MinifyOptions, PrinterOptions
};
// Parse a style sheet from a string.
let mut stylesheet = StyleSheet::parse(
"test.css",
r#"
.foo {
color: red;
}
.bar {
color: red;
}
"#,
ParserOptions::default()
).unwrap();
// Minify the stylesheet.
stylesheet.minify(MinifyOptions::default()).unwrap();
// Serialize it to a string.
let res = stylesheet.to_css(PrinterOptions::default()).unwrap();
assert_eq!(res.code, ".foo, .bar {\n color: red;\n}\n");
Fields
rules: CssRuleList<'i>
A list of top-level rules within the style sheet.
sources: Vec<String>
A list of file names for all source files included within the style sheet.
Sources are referenced by index in the loc
property of each rule.
Implementations
sourceimpl<'i, 'o> StyleSheet<'i, 'o>
impl<'i, 'o> StyleSheet<'i, 'o>
sourcepub fn new(
sources: Vec<String>,
rules: CssRuleList<'i>,
options: ParserOptions<'o>
) -> StyleSheet<'i, 'o>
pub fn new(
sources: Vec<String>,
rules: CssRuleList<'i>,
options: ParserOptions<'o>
) -> StyleSheet<'i, 'o>
Creates a new style sheet with the given source filenames and rules.
sourcepub fn parse(
filename: &str,
code: &'i str,
options: ParserOptions<'o>
) -> Result<Self, Error<ParserError<'i>>>
pub fn parse(
filename: &str,
code: &'i str,
options: ParserOptions<'o>
) -> Result<Self, Error<ParserError<'i>>>
Parse a style sheet from a string.
sourcepub fn minify(
&mut self,
options: MinifyOptions
) -> Result<(), Error<MinifyErrorKind>>
pub fn minify(
&mut self,
options: MinifyOptions
) -> Result<(), Error<MinifyErrorKind>>
Minify and transform the style sheet for the provided browser targets.
sourcepub fn to_css(
&self,
options: PrinterOptions<'_>
) -> Result<ToCssResult, Error<PrinterErrorKind>>
pub fn to_css(
&self,
options: PrinterOptions<'_>
) -> Result<ToCssResult, Error<PrinterErrorKind>>
Serialize the style sheet to a CSS string.
Trait Implementations
Auto Trait Implementations
impl<'i, 'o> RefUnwindSafe for StyleSheet<'i, 'o>
impl<'i, 'o> Send for StyleSheet<'i, 'o>
impl<'i, 'o> Sync for StyleSheet<'i, 'o>
impl<'i, 'o> Unpin for StyleSheet<'i, 'o>
impl<'i, 'o> UnwindSafe for StyleSheet<'i, 'o>
Blanket Implementations
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more