@@ -8,18 +8,30 @@ use wordbase_api::{DictionaryId, Record, RecordKind, RecordLookup, Term, dict};
88use crate :: { Engine , IndexMap } ;
99
1010impl Engine {
11- pub fn render_to_html ( & self , records : & [ RecordLookup ] ) -> Result < String > {
11+ pub fn render_to_html (
12+ & self ,
13+ records : & [ RecordLookup ] ,
14+ config : & RenderConfig ,
15+ ) -> Result < String > {
1216 let terms = group_terms ( records) ;
1317
1418 let mut context = tera:: Context :: new ( ) ;
1519 context. insert ( "dictionaries" , & self . dictionaries ( ) . 0 ) ;
1620 context. insert ( "terms" , & terms) ;
21+ context. insert ( "config" , config) ;
1722
1823 let html = self . renderer . render ( "records.html" , & context) ?;
1924 Ok ( html)
2025 }
2126}
2227
28+ #[ derive( Debug , Clone , Serialize ) ]
29+ #[ cfg_attr( feature = "uniffi" , derive( uniffi:: Record ) ) ]
30+ pub struct RenderConfig {
31+ pub add_card_text : String ,
32+ pub add_card_js_fn : String ,
33+ }
34+
2335fn group_terms ( records : & [ RecordLookup ] ) -> Vec < RecordTerm > {
2436 // note on ordering:
2537 // by default, tera will not preserve the order of IndexMap entries,
@@ -197,8 +209,12 @@ const _: () = {
197209
198210 #[ uniffi:: export]
199211 impl Wordbase {
200- pub fn render_to_html ( & self , records : & [ RecordLookup ] ) -> FfiResult < String > {
201- Ok ( self . 0 . render_to_html ( records) ?)
212+ pub fn render_to_html (
213+ & self ,
214+ records : & [ RecordLookup ] ,
215+ translations : & RenderConfig ,
216+ ) -> FfiResult < String > {
217+ Ok ( self . 0 . render_to_html ( records, translations) ?)
202218 }
203219 }
204220} ;
0 commit comments