pub struct Stylesheet {
pub rules: CssRules,
pub source_map_url: Option<String>,
pub source_url: Option<String>,
}
Expand description
Represents an entire CSS stylesheet. The values of property declarations are currently stored as a string. Parsing property declarations is a monster job. If you feel like helping…
Fields§
§rules: CssRules
The stylesheet’s rules.
source_map_url: Option<String>
An optional source map for this stylesheet.
source_url: Option<String>
An optional source URL for this stylesheet.
Implementations§
Source§impl Stylesheet
impl Stylesheet
Sourcepub fn to_file_path<P: AsRef<Path>>(
&self,
stylesheet_file_path: P,
include_source_urls: bool,
) -> Result<(), StylesheetError>
pub fn to_file_path<P: AsRef<Path>>( &self, stylesheet_file_path: P, include_source_urls: bool, ) -> Result<(), StylesheetError>
Serializes a Stylesheet to a file path, optionally including source-map and source-url comments.
Will create or truncate stylesheet_file_path
as required.
Convenience method wrapped to_css()
.
Sourcepub fn to_css_string(&self, include_source_urls: bool) -> String
pub fn to_css_string(&self, include_source_urls: bool) -> String
Serializes a Stylesheet as a string, optionally including source-map and source-url comments.
Convenience method wrapped to_css()
.
Sourcepub fn to_bytes(&self, include_source_urls: bool) -> Vec<u8> ⓘ
pub fn to_bytes(&self, include_source_urls: bool) -> Vec<u8> ⓘ
Serializes a Stylesheet to a vector of UTF-8 encoded bytes.
Convenience method wrapped to_css_string()
.
Sourcepub fn to_css<W: Write>(
&self,
destination: &mut W,
include_source_urls: bool,
) -> Result
pub fn to_css<W: Write>( &self, destination: &mut W, include_source_urls: bool, ) -> Result
Serializes a Stylesheet, optionally including source-map and source-url comments.
Sourcepub fn from_file_path<P: AsRef<Path>>(
html_document_file_path: P,
) -> Result<Self, StylesheetError>
pub fn from_file_path<P: AsRef<Path>>( html_document_file_path: P, ) -> Result<Self, StylesheetError>
Loads and parses a Stylesheet.
Sourcepub fn parse(css: &str) -> Result<Self, ParseError<'_, CustomParseError<'_>>>
pub fn parse(css: &str) -> Result<Self, ParseError<'_, CustomParseError<'_>>>
Parses a string of CSS to produce a stylesheet. Can be used with the contents of a CSS file. Assumes the string is UTF-8 encoded. Does not use a stream of bytes as parsing CSS involves going backwards and forwards a lot… CSS parsing is somewhat evil and is not particularly efficient. The parser does apply a few small modifications to the incoming CSS, normalizing some pseudo-class, psuedo-element and media query names. The parser does not parse properties as such, simply keeping them as a CSS string. Hopefully it will one day - there are only 200 odd specialist rules to implement.
Trait Implementations§
Source§impl Clone for Stylesheet
impl Clone for Stylesheet
Source§fn clone(&self) -> Stylesheet
fn clone(&self) -> Stylesheet
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more