Skip to main content

docx_rs/documents/elements/
style_ext.rs

1//! Fork-only extension builders for [`Style`].
2//!
3//! Kept in a dedicated file that upstream `bokuweb/docx-rs` never edits, so
4//! rebasing onto new releases produces zero conflicts here. Every method is a
5//! pure delegation over the crate's own public API. See `FORK_CHANGES.md`.
6
7use super::*;
8
9impl Style {
10    /// Applies shading to the style's run properties (`<w:rPr><w:shd/>`).
11    ///
12    /// Convenience delegator so callers never mutate the public
13    /// `run_property` field directly.
14    ///
15    /// ```
16    /// use docx_rs::*;
17    /// let s = Style::new("MDTag", StyleType::Character)
18    ///     .shading(Shading::new().shd_type(ShdType::Clear).fill("EEEEEE").color("auto"));
19    /// assert!(String::from_utf8(s.build()).unwrap().contains(r#"w:fill="EEEEEE""#));
20    /// ```
21    pub fn shading(mut self, shading: Shading) -> Self {
22        self.run_property = self.run_property.shading(shading);
23        self
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    // `super::*` only carries `elements`-level re-exports (e.g. `Shading`), not
31    // `ShdType`/`StyleType` (crate::types) or the `BuildXML` trait (needed for
32    // `.build()`), since neither is re-exported through `style.rs`/`shading.rs`.
33    // Imported explicitly here rather than widening the module-level `use
34    // super::*;` above, which must stay minimal per the fork's isolation
35    // convention (see module doc comment).
36    use crate::{documents::BuildXML, ShdType, StyleType};
37
38    #[test]
39    fn style_shading_delegates_to_run_property() {
40        let s = Style::new("MDTag", StyleType::Character)
41            .name("MD Tag")
42            .shading(
43                Shading::new()
44                    .shd_type(ShdType::Clear)
45                    .fill("EEEEEE")
46                    .color("auto"),
47            );
48        let xml = String::from_utf8(s.build()).unwrap();
49        assert!(xml.contains(r#"w:fill="EEEEEE""#), "got: {xml}");
50        assert!(xml.contains(r#"w:val="clear""#), "got: {xml}");
51    }
52}