ass_editor/commands/macros/style_macros.rs
1//! Style and script-info editing macros (`edit_style!`, `script_info!`).
2
3/// Macro for editing styles
4///
5/// # Examples
6///
7/// ```
8/// use ass_editor::{EditorDocument, edit_style, StyleBuilder};
9///
10/// let content = "[V4+ Styles]\nStyle: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,2,10,10,10,1";
11/// let mut doc = EditorDocument::from_content(content).unwrap();
12///
13/// // Note: edit_style! macro has different syntax than shown
14/// let style = StyleBuilder::new()
15/// .name("Default")
16/// .font("Arial")
17/// .size(24)
18/// .build()
19/// .unwrap();
20///
21/// // The actual method to update styles would be different
22/// // This is just an example of the intended usage
23/// ```
24#[macro_export]
25macro_rules! edit_style {
26 ($doc:expr, $name:expr, { $($field:ident = $value:expr),+ $(,)? }) => {{
27 let style = $crate::StyleBuilder::new()
28 .name($name)
29 $(.$field($value))*
30 .build()?;
31 $doc.edit_style_line($name, &style)
32 }};
33}
34
35/// Macro for script info field updates
36///
37/// # Examples
38///
39/// ```
40/// use ass_editor::{EditorDocument, script_info, Position};
41///
42/// let mut doc = EditorDocument::from_content("[Script Info]\nTitle: \nAuthor: ").unwrap();
43///
44/// // Set script info fields - they must already exist in the document
45/// doc.set_script_info_field("Title", "My Movie").unwrap();
46/// doc.set_script_info_field("Author", "John Doe").unwrap();
47///
48/// assert!(doc.text().contains("Title: My Movie"));
49/// assert!(doc.text().contains("Author: John Doe"));
50/// ```
51#[macro_export]
52macro_rules! script_info {
53 ($doc:expr, { $($key:expr => $value:expr),+ $(,)? }) => {{
54 $(
55 $doc.set_script_info_field($key, $value)?;
56 )+
57 Ok::<(), $crate::EditorError>(())
58 }};
59}