jacquard_api/blog_pckt/block/
code_block.rs1use jacquard_common::CowStr;
9
10#[allow(unused_imports)]
11use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
12use jacquard_derive::{IntoStatic, lexicon};
13use jacquard_lexicon::lexicon::LexiconDoc;
14use jacquard_lexicon::schema::LexiconSchema;
15
16#[allow(unused_imports)]
17use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
18use serde::{Serialize, Deserialize};
19
20#[lexicon]
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
22#[serde(rename_all = "camelCase")]
23pub struct CodeBlock<'a> {
24 #[serde(skip_serializing_if = "Option::is_none")]
26 #[serde(borrow)]
27 pub language: Option<CowStr<'a>>,
28 #[serde(borrow)]
30 pub plaintext: CowStr<'a>,
31}
32
33impl<'a> LexiconSchema for CodeBlock<'a> {
34 fn nsid() -> &'static str {
35 "blog.pckt.block.codeBlock"
36 }
37 fn def_name() -> &'static str {
38 "main"
39 }
40 fn lexicon_doc() -> LexiconDoc<'static> {
41 lexicon_doc_blog_pckt_block_codeBlock()
42 }
43 fn validate(&self) -> Result<(), ConstraintError> {
44 if let Some(ref value) = self.language {
45 #[allow(unused_comparisons)]
46 if <str>::len(value.as_ref()) > 50usize {
47 return Err(ConstraintError::MaxLength {
48 path: ValidationPath::from_field("language"),
49 max: 50usize,
50 actual: <str>::len(value.as_ref()),
51 });
52 }
53 }
54 Ok(())
55 }
56}
57
58fn lexicon_doc_blog_pckt_block_codeBlock() -> LexiconDoc<'static> {
59 #[allow(unused_imports)]
60 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
61 use jacquard_lexicon::lexicon::*;
62 use alloc::collections::BTreeMap;
63 LexiconDoc {
64 lexicon: Lexicon::Lexicon1,
65 id: CowStr::new_static("blog.pckt.block.codeBlock"),
66 defs: {
67 let mut map = BTreeMap::new();
68 map.insert(
69 SmolStr::new_static("main"),
70 LexUserType::Object(LexObject {
71 required: Some(vec![SmolStr::new_static("plaintext")]),
72 properties: {
73 #[allow(unused_mut)]
74 let mut map = BTreeMap::new();
75 map.insert(
76 SmolStr::new_static("language"),
77 LexObjectProperty::String(LexString {
78 description: Some(
79 CowStr::new_static(
80 "Programming language for syntax highlighting",
81 ),
82 ),
83 max_length: Some(50usize),
84 ..Default::default()
85 }),
86 );
87 map.insert(
88 SmolStr::new_static("plaintext"),
89 LexObjectProperty::String(LexString {
90 description: Some(CowStr::new_static("The code content")),
91 ..Default::default()
92 }),
93 );
94 map
95 },
96 ..Default::default()
97 }),
98 );
99 map
100 },
101 ..Default::default()
102 }
103}