lewp_css/lib.rs
1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4#![allow(non_camel_case_types)]
5#![allow(non_snake_case)]
6#![allow(non_upper_case_globals)]
7
8//! # lewp-css
9//!
10//! *Forked version and continued version of [css](https://github.com/lemonrock/css)*
11//!
12//! A Rust library crate for parsing, manipulating and serializing CSS stylesheets.
13//! Makes use of existing CSS parser logic from Servo.
14//! Includes forks of code from Servo because these are unpublished on <https://crates.io>.
15//! One use of this library is to minify CSS, as the serialized form it produces is minimal.
16//! Another use is provide a crate that others can use for auto-prefixing CSS and to eliminate unused CSS.
17//! The values of property declarations are currently stored as a string. Parsing property declarations is a monster job (in effect there are bespoke rules for every property). If you feel like helping...
18//!
19//!
20//! ## Usages
21//!
22//!
23//! ### Loading and Saving Stylesheets
24//!
25//! ```
26//! use ::lewp_css::Stylesheet;
27//!
28//! let some_css = "input { margin-left: 10pt; top: 20px; }".to_owned();
29//! let stylesheet = Stylesheet::parse(&some_css).expect("CSS was invalid");
30//!
31//! // Alternatively, load from a file using Stylesheet::from_file_path("/path/to/stylesheet.css").unwrap();
32//!
33//! let mut destination = String::new();
34//!
35//! // Don't write source-map and source-url comments if any are present in the stylesheet
36//! let include_source_urls = false;
37//!
38//! stylesheet.to_css(&mut destination, include_source_urls).expect("Failed to write to destination");
39//!
40//! assert_eq!(&destination, "input{margin-left: 10pt;top: 20px}");
41//!
42//! // To serialize to a Vec<u8> of bytes instead
43//! let mut bytes = stylesheet.to_bytes(false);
44//!
45//! // To serialize to a file instead
46//! //stylesheet.to_file_path("/path/to/to/stylesheet.css", false).unwrap();
47//! ```
48//!
49//!
50//! ### To parse a single CSS selector
51//!
52//! ```
53//! use ::lewp_css::parse_css_selector;
54//!
55//! let selector = parse_css_selector("P.myclass").unwrap();
56//! ```
57//!
58//!
59//! ### To match CSS selectors to HTML
60//!
61//! Use the `html5ever_ext` crate. (The function `domain::selectors::matches()` can do matching but needs a lot of HTML logic to do so).
62//!
63
64#[macro_use]
65extern crate bitflags;
66#[macro_use]
67pub extern crate cssparser;
68extern crate either;
69pub extern crate ordermap;
70extern crate phf;
71extern crate precomputed_hash;
72#[macro_use]
73extern crate quick_error;
74pub extern crate servo_arc;
75pub extern crate smallvec;
76
77/// Contains definitions of objects used in Stylesheet.
78pub mod domain;
79pub(crate) mod parsers;
80pub(crate) mod serializers;
81
82mod blocking_io_only_std_fmt_write_to_std_io_write_adaptor;
83mod custom_parse_error;
84mod parse_css_selector;
85mod stylesheet;
86mod stylesheet_error;
87
88pub use {
89 custom_parse_error::CustomParseError,
90 parse_css_selector::*,
91 stylesheet::Stylesheet,
92 stylesheet_error::*,
93};