twitter_card/
summary.rs

1use super::*;
2
3/// Create a summary card.
4#[derive(Debug, Clone)]
5pub struct Summary {
6  strings: Vec<String>,
7}
8
9impl Summary {
10  /// Create a new instance.
11  pub fn builder() -> Self {
12    Self {
13      strings: vec![create_card("summary")],
14    }
15  }
16
17  /// @username of website. Either twitter:site or twitter:site:id is required.
18  #[inline]
19  pub fn site(mut self, site: &str) -> Self {
20    self.strings.push(create_site(site));
21    self
22  }
23
24  /// Same as twitter:site, but the user’s Twitter ID. Either twitter:site or
25  /// twitter:site:id is required.
26  #[inline]
27  pub fn site_id(mut self, content: &str) -> Self {
28    self.strings.push(create_site_id(content));
29    self
30  }
31
32  /// Twitter user ID of content creator.
33  #[inline]
34  pub fn creator_id(mut self, content: &str) -> Self {
35    self.strings.push(create_creator_id(content));
36    self
37  }
38
39  /// Description of content.
40  ///
41  /// ## Panics.
42  /// Panics if the description is more than 200 characters.
43  #[inline]
44  pub fn desc(mut self, content: &str) -> Self {
45    self.strings.push(create_desc(content));
46    self
47  }
48
49  /// Title of content.
50  ///
51  /// ## Panics.
52  /// Panics if the description is more than 70 characters.
53  #[inline]
54  pub fn title(mut self, content: &str) -> Self {
55    self.strings.push(create_title(content));
56    self
57  }
58
59  /// URL of image to use in the card. Images must be less than 5MB in size.
60  /// JPG, PNG, WEBP and GIF formats are supported. Only the first frame of an
61  /// animated GIF will be used. SVG is not supported.
62  #[inline]
63  pub fn image(mut self, content: &str) -> Self {
64    self.strings.push(create_image(content));
65    self
66  }
67
68  /// A text description of the image conveying the essential nature of an image
69  /// to users who are visually impaired. Maximum 420 characters.
70  ///
71  /// ## Panics.
72  /// Panics if the description is more than 420 characters.
73  #[inline]
74  pub fn image_alt(mut self, content: &str) -> Self {
75    self.strings.push(create_image_alt(content));
76    self
77  }
78}
79
80impl TwitterCard for Summary {
81  #[inline]
82  fn build(self) -> String {
83    self.strings.join("\n")
84  }
85}