367 lines
9.1 KiB
Rust
367 lines
9.1 KiB
Rust
use heromodels_core::BaseModelData;
|
|
use heromodels_derive::model;
|
|
use rhai::{CustomType, TypeBuilder};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// Represents an Image library item.
|
|
#[model]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
|
pub struct Image {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
/// Title of the image
|
|
#[index]
|
|
pub title: String,
|
|
/// Optional description of the image
|
|
pub description: Option<String>,
|
|
/// URL of the image
|
|
pub url: String,
|
|
/// Width of the image in pixels
|
|
pub width: u32,
|
|
/// Height of the image in pixels
|
|
pub height: u32,
|
|
}
|
|
|
|
impl Default for Image {
|
|
fn default() -> Self {
|
|
Self {
|
|
base_data: BaseModelData::new(),
|
|
title: String::new(),
|
|
description: None,
|
|
url: String::new(),
|
|
width: 0,
|
|
height: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Image {
|
|
/// Creates a new `Image` with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Gets the ID of the image.
|
|
pub fn id(&self) -> u32 {
|
|
self.base_data.id
|
|
}
|
|
|
|
/// Sets the title of the image.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the description of the image.
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
|
|
/// Sets the URL of the image.
|
|
pub fn url(mut self, url: impl Into<String>) -> Self {
|
|
self.url = url.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the width of the image.
|
|
pub fn width(mut self, width: u32) -> Self {
|
|
self.width = width;
|
|
self
|
|
}
|
|
|
|
/// Sets the height of the image.
|
|
pub fn height(mut self, height: u32) -> Self {
|
|
self.height = height;
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Represents a PDF document library item.
|
|
#[model]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
|
pub struct Pdf {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
/// Title of the PDF
|
|
#[index]
|
|
pub title: String,
|
|
/// Optional description of the PDF
|
|
pub description: Option<String>,
|
|
/// URL of the PDF file
|
|
pub url: String,
|
|
/// Number of pages in the PDF
|
|
pub page_count: u32,
|
|
}
|
|
|
|
impl Default for Pdf {
|
|
fn default() -> Self {
|
|
Self {
|
|
base_data: BaseModelData::new(),
|
|
title: String::new(),
|
|
description: None,
|
|
url: String::new(),
|
|
page_count: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Pdf {
|
|
/// Creates a new `Pdf` with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Gets the ID of the image.
|
|
pub fn id(&self) -> u32 {
|
|
self.base_data.id
|
|
}
|
|
|
|
/// Sets the title of the PDF.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the description of the PDF.
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
|
|
/// Sets the URL of the PDF.
|
|
pub fn url(mut self, url: impl Into<String>) -> Self {
|
|
self.url = url.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the page count of the PDF.
|
|
pub fn page_count(mut self, page_count: u32) -> Self {
|
|
self.page_count = page_count;
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Represents a Markdown document library item.
|
|
#[model]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
|
pub struct Markdown {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
/// Title of the document
|
|
#[index]
|
|
pub title: String,
|
|
/// Optional description of the document
|
|
pub description: Option<String>,
|
|
/// The markdown content
|
|
pub content: String,
|
|
}
|
|
|
|
impl Markdown {
|
|
/// Creates a new `Markdown` document with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Gets the ID of the image.
|
|
pub fn id(&self) -> u32 {
|
|
self.base_data.id
|
|
}
|
|
|
|
/// Sets the title of the document.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the description of the document.
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
|
|
/// Sets the content of the document.
|
|
pub fn content(mut self, content: impl Into<String>) -> Self {
|
|
self.content = content.into();
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Represents a table of contents entry for a book.
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
|
pub struct TocEntry {
|
|
/// Title of the chapter/section
|
|
pub title: String,
|
|
/// Page number (index in the pages array)
|
|
pub page: u32,
|
|
/// Optional subsections
|
|
pub subsections: Vec<TocEntry>,
|
|
}
|
|
|
|
impl TocEntry {
|
|
/// Creates a new `TocEntry` with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Sets the title of the TOC entry.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the page number of the TOC entry.
|
|
pub fn page(mut self, page: u32) -> Self {
|
|
self.page = page;
|
|
self
|
|
}
|
|
|
|
/// Adds a subsection to the TOC entry.
|
|
pub fn add_subsection(mut self, subsection: TocEntry) -> Self {
|
|
self.subsections.push(subsection);
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Represents a Book library item (collection of markdown pages with TOC).
|
|
#[model]
|
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, CustomType, Default)]
|
|
pub struct Book {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
/// Title of the book
|
|
#[index]
|
|
pub title: String,
|
|
/// Optional description of the book
|
|
pub description: Option<String>,
|
|
/// Table of contents
|
|
pub table_of_contents: Vec<TocEntry>,
|
|
/// Pages content (markdown strings)
|
|
pub pages: Vec<String>,
|
|
}
|
|
|
|
impl Book {
|
|
/// Creates a new `Book` with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Gets the ID of the book.
|
|
pub fn id(&self) -> u32 {
|
|
self.base_data.id
|
|
}
|
|
|
|
/// Sets the title of the book.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the description of the book.
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
|
|
/// Adds a page to the book.
|
|
pub fn add_page(mut self, content: impl Into<String>) -> Self {
|
|
self.pages.push(content.into());
|
|
self
|
|
}
|
|
|
|
/// Adds a TOC entry to the book.
|
|
pub fn add_toc_entry(mut self, entry: TocEntry) -> Self {
|
|
self.table_of_contents.push(entry);
|
|
self
|
|
}
|
|
|
|
/// Sets the table of contents.
|
|
pub fn table_of_contents(mut self, toc: Vec<TocEntry>) -> Self {
|
|
self.table_of_contents = toc;
|
|
self
|
|
}
|
|
|
|
/// Sets all pages at once.
|
|
pub fn pages(mut self, pages: Vec<String>) -> Self {
|
|
self.pages = pages;
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Represents a Slideshow library item (collection of images for slideshow).
|
|
#[model]
|
|
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, CustomType)]
|
|
pub struct Slideshow {
|
|
/// Base model data
|
|
pub base_data: BaseModelData,
|
|
/// Title of the slideshow
|
|
#[index]
|
|
pub title: String,
|
|
/// Optional description of the slideshow
|
|
pub description: Option<String>,
|
|
/// List of slides
|
|
pub slides: Vec<Slide>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Default, Deserialize, PartialEq, CustomType)]
|
|
pub struct Slide {
|
|
pub image_url: String,
|
|
pub title: Option<String>,
|
|
pub description: Option<String>,
|
|
}
|
|
|
|
impl Slide {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
image_url: String::new(),
|
|
title: None,
|
|
description: None,
|
|
}
|
|
}
|
|
|
|
pub fn url(mut self, url: impl Into<String>) -> Self {
|
|
self.image_url = url.into();
|
|
self
|
|
}
|
|
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = Some(title.into());
|
|
self
|
|
}
|
|
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
}
|
|
|
|
impl Slideshow {
|
|
/// Creates a new `Slideshow` with default values.
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
/// Gets the ID of the slideshow.
|
|
pub fn id(&self) -> u32 {
|
|
self.base_data.id
|
|
}
|
|
|
|
/// Sets the title of the slideshow.
|
|
pub fn title(mut self, title: impl Into<String>) -> Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
/// Sets the description of the slideshow.
|
|
pub fn description(mut self, description: impl Into<String>) -> Self {
|
|
self.description = Some(description.into());
|
|
self
|
|
}
|
|
|
|
/// Adds a slide with URL and optional title.
|
|
pub fn add_slide(mut self, slide: Slide) -> Self {
|
|
self.slides.push(slide);
|
|
self
|
|
}
|
|
}
|