Skip to content

Commit

Permalink
refactor: a pure crate named xmlserde
Browse files Browse the repository at this point in the history
Before this commit, we put the work of parsing or unparsing
xml files and the work of turning xml files into readable structs
into one crate, now users can only use `xmlserde` as a pure tool
to serde xml files
  • Loading branch information
ImJeremyHe committed Jun 2, 2022
1 parent fef7852 commit 8dc97e3
Show file tree
Hide file tree
Showing 44 changed files with 412 additions and 147 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logisheets"
version = "0.2.1"
version = "0.3.0"
description = "A web spreadsheets application written in Rust and Typescript"
keywords = ["excel", "spreadsheets", "ooxml", "logisheets"]
readme = "README.md"
Expand All @@ -21,5 +21,5 @@ members = [
]

[dependencies]
logisheets_controller = {path = "crates/controller", version = "0.2.1"}
logisheets_workbook = {path = "crates/workbook", version = "0.2.1"}
logisheets_controller = {path = "crates/controller", version = "0.3.0"}
logisheets_workbook = {path = "crates/workbook", version = "0.3.0"}
10 changes: 5 additions & 5 deletions crates/controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logisheets_controller"
version = "0.2.1"
version = "0.3.0"
description = "the core of LogiSheets"
authors = ["ImJeremyHe<[email protected]>"]
edition = "2018"
Expand All @@ -22,7 +22,7 @@ unicode-segmentation = "1.8.0"
ts-rs = "6.1.2"
colorsys = "0.6.5"

logisheets_base = {version = "0.2.1", path = "./base"}
logisheets_lexer = {version = "0.2.1", path = "./lexer"}
logisheets_parser = {version = "0.2.1", path = "./parser"}
logisheets_workbook = {version = "0.2.1", path = "../workbook"}
logisheets_base = {version = "0.3.0", path = "./base"}
logisheets_lexer = {version = "0.3.0", path = "./lexer"}
logisheets_parser = {version = "0.3.0", path = "./parser"}
logisheets_workbook = {version = "0.3.0", path = "../workbook"}
4 changes: 2 additions & 2 deletions crates/controller/base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logisheets_base"
version = "0.2.1"
version = "0.3.0"
description = "some basic definitions for LogiSheets"
authors = ["ImJeremyHe<[email protected]>"]
license = "MIT"
Expand All @@ -11,4 +11,4 @@ futures = "0.3.19"
im = "15.0.0"
serde = {version = "1.0.125", features = ["derive"]}
ts-rs = "6.1.2"
logisheets_workbook = {version = "0.2.1", path = "../../workbook"}
logisheets_workbook = {version = "0.3.0", path = "../../workbook"}
2 changes: 1 addition & 1 deletion crates/controller/lexer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logisheets_lexer"
version = "0.2.1"
version = "0.3.0"
edition = "2018"
description = "the lexer for excel formula"
authors = ["ImJeremyHe<[email protected]>"]
Expand Down
6 changes: 3 additions & 3 deletions crates/controller/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logisheets_parser"
version = "0.2.1"
version = "0.3.0"
edition = "2018"
description = "the parser of excel formula"
authors = ["ImJeremyHe<[email protected]>"]
Expand All @@ -12,5 +12,5 @@ pest = "2.1.3"
pest_derive = "2.1.0"
chrono = "0.4.19"
regex = "1"
logisheets_lexer = {version = "0.2.1", path = "../lexer"}
logisheets_base = {version = "0.2.1", path = "../base"}
logisheets_lexer = {version = "0.3.0", path = "../lexer"}
logisheets_base = {version = "0.3.0", path = "../base"}
2 changes: 1 addition & 1 deletion crates/controller/src/file_loader2/external_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
let val_str = &ext_cell.v.as_ref().unwrap().value;
let cell_ref = ext_cell.r.as_ref().unwrap();
if let Some((r, c)) = parse_cell(cell_ref) {
use logisheets_workbook::prelude::simple_types::StCellType;
use logisheets_workbook::prelude::StCellType;
let val = match &ext_cell.t {
StCellType::B => {
let b = if val_str == "TRUE" || val_str == "0" {
Expand Down
2 changes: 1 addition & 1 deletion crates/controller/src/theme_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use logisheets_workbook::prelude::theme::{CtColorScheme, ThemePart};
use logisheets_workbook::prelude::{CtColorScheme, ThemePart};

#[derive(Default)]
pub struct ThemeManager {
Expand Down
19 changes: 8 additions & 11 deletions crates/workbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
authors = ["ImJeremyHe<[email protected]>"]
edition = "2018"
name = "logisheets_workbook"
version = "0.2.1"
version = "0.3.0"
license = "MIT"
description = "read and write .xlsx files"
description = "Tools for LogiSheets to unarchive and write .xlsx file"

[dependencies]
convert_case = "0.4.0"
linked-hash-map = {version = "0.5.3", features = ["serde_impl"]}
paste = "1.0.5"
xmlserde = {version = "0.3.0", path = "../xmlserde"}
logisheets_workbook_derives = {version = "0.3.0", path = "./derives"}
zip = {version = "0.6.0", default-features = false, features = ["deflate"]}
ts-rs = "6.1.2"
thiserror = "1.0.24"
quick-xml = {version = "0.22.0", features = ["serialize"]}
regex = "1"
serde = {version = "1.0.125", features = ["derive"]}
serde_json = "1.0.59"
serde_repr = "0.1"
thiserror = "1.0.24"
zip = {version = "0.6.0", default-features = false, features = ["deflate"]}
logisheets_xmlserde = {path = "./xmlserde", version = "0.2.1"}
logisheets_derives = {path = "./derives", version = "0.2.1"}
regex = "1"
4 changes: 2 additions & 2 deletions crates/workbook/derives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logisheets_derives"
version = "0.2.1"
name = "logisheets_workbook_derives"
version = "0.3.0"
description = "macros that help LogiSheets serde the xml files"
authors = ["ImJeremyHe<[email protected]>"]
license = "MIT"
Expand Down
18 changes: 0 additions & 18 deletions crates/workbook/derives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,12 @@ extern crate syn;
extern crate quote;
extern crate paste;

mod container;
mod de;
mod map_obj;
mod ser;
mod symbol;

use de::get_de_impl_block;
use map_obj::get_map_obj_impl_block;
use proc_macro::TokenStream;
use ser::get_ser_impl_block;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(XmlDeserialize, attributes(xmlserde))]
pub fn derive_xml_deserialize(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
get_de_impl_block(input).into()
}

#[proc_macro_derive(XmlSerialize, attributes(xmlserde))]
pub fn derive_xml_serialize(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
get_ser_impl_block(input).into()
}

// MapObj means this struct will be used in a hash map as a key and a value.
// It should impl Hash, Eq, PartialEq
#[proc_macro_derive(MapObj)]
Expand Down
22 changes: 13 additions & 9 deletions crates/workbook/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#[macro_use]
extern crate ts_rs;
#[macro_use]
extern crate xmlserde;
mod ooxml;
pub mod reader;
pub mod rtypes;
pub mod workbook;
pub mod writer;
use logisheets_xmlserde::*;
use thiserror::Error;
use xmlserde::*;

pub mod prelude {
pub use super::comments::*;
pub use super::complex_types::*;
pub use super::ooxml::comments::*;
pub use super::ooxml::complex_types::*;
pub use super::ooxml::simple_types::*;
pub use super::ooxml::sst::SstPart;
pub use super::ooxml::style_sheet::StylesheetPart;
pub use super::ooxml::theme::*;
pub use super::ooxml::worksheet::*;
pub use super::reader::*;
pub use super::simple_types::*;
pub use super::sst::SstPart;
pub use super::style_sheet::StylesheetPart;
pub use super::workbook::Workbook;
pub use super::worksheet::*;
pub use super::SerdeErr;
pub use logisheets_xmlserde::workbook::WorkbookPart;
pub use logisheets_xmlserde::*;
}

#[derive(Debug, Error)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::complex_types::*;
use xmlserde::{XmlDeserialize, XmlSerialize};

#[derive(Debug, XmlSerialize, XmlDeserialize)]
#[xmlserde(with_ns = b"http://schemas.openxmlformats.org/spreadsheetml/2006/main")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::defaults::*;
use super::simple_types::*;
use logisheets_workbook_derives::MapObj;

#[derive(XmlSerialize, XmlDeserialize, Default, Debug, Clone)]
pub struct CtRst {
#[xmlserde(name = b"t", ty = "child")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use xmlserde::{XmlDeserialize, XmlSerialize};

#[derive(Debug, XmlSerialize, XmlDeserialize)]
#[xmlserde(with_ns = b"http://schemas.openxmlformats.org/package/2006/content-types")]
pub struct ContentTypes {
Expand Down Expand Up @@ -39,7 +41,7 @@ mod tests {
// Used the site and the code below to check the diff manually.
// Basically pass.
// https://www.diffchecker.com/diff
use crate::test_utils::*;
use crate::ooxml::test_utils::*;
use crate::xml_serialize_with_decl;
let expected = to_tree(&in_one_line(xml));
let actual = xml_serialize_with_decl(b"Types", ct);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::complex_types::PlainTextString;
use super::complex_types::PlainTextString;

#[derive(Debug, XmlSerialize, XmlDeserialize)]
#[xmlserde(with_custom_ns(
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct CreatedModified {
#[cfg(test)]
mod tests {
use super::CoreProperties;
use crate::test_utils::*;
use crate::ooxml::test_utils::*;
use crate::xml_deserialize_from_str;
use crate::xml_serialize;
#[test]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Unparsed;
use xmlserde::{XmlDeserialize, XmlSerialize};

#[derive(Debug, XmlSerialize, XmlDeserialize)]
#[xmlserde(with_custom_ns(
Expand Down Expand Up @@ -67,14 +68,14 @@ pub struct Time {
#[cfg(test)]
mod tests {
use super::{DocPropApp, DocPropCore, DocPropCustom};
use crate::ooxml::test_utils::*;
use crate::xml_deserialize_from_str;
#[test]
fn doc_prop_core_prop_test() {
let xml = include_str!("../../examples/doc_prop_core.xml");
let r = xml_deserialize_from_str::<DocPropCore>(b"cp:coreProperties", xml);
match r {
Ok(core) => {
use crate::test_utils::*;
use crate::xml_serialize_with_decl;
let actual = xml_serialize_with_decl(b"cp:coreProperties", core);
let r = in_one_line(&xml);
Expand All @@ -90,7 +91,6 @@ mod tests {
let r = xml_deserialize_from_str::<DocPropApp>(b"Properties", xml);
match r {
Ok(core) => {
use crate::test_utils::*;
use crate::xml_serialize_with_decl;
let actual = xml_serialize_with_decl(b"Properties", core);
let r = in_one_line(&xml);
Expand All @@ -106,7 +106,6 @@ mod tests {
let r = xml_deserialize_from_str::<DocPropCustom>(b"Properties", xml);
match r {
Ok(core) => {
use crate::test_utils::*;
use crate::xml_serialize_with_decl;
let actual = xml_serialize_with_decl(b"Properties", core);
let r = in_one_line(&xml);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::defaults::*;
use crate::{
use super::{
complex_types::PlainTextString,
defaults::*,
simple_types::{StCellRef, StCellType},
};

Expand Down
15 changes: 15 additions & 0 deletions crates/workbook/src/ooxml/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub mod comments;
pub mod complex_types;
pub mod content_types;
pub mod core_properties;
pub mod defaults;
pub mod doc_props;
pub mod external_links;
pub mod relationships;
pub mod simple_types;
pub mod sst;
pub mod style_sheet;
pub mod test_utils;
pub mod theme;
pub mod workbook;
pub mod worksheet;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct CtRelationship {
#[cfg(test)]
mod tests {
use super::Relationships;
use crate::test_utils::*;
use crate::ooxml::test_utils::*;
use crate::xml_deserialize_from_str;
use crate::xml_serialize_with_decl;
#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use xmlserde::xml_serde_enum;

xml_serde_enum! {
#[derive(Debug, PartialEq, Eq)]
StAxis {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct SstPart {
#[cfg(test)]
mod tests {
use super::SstPart;
use crate::test_utils::in_one_line;
use crate::ooxml::test_utils::in_one_line;
use crate::{xml_deserialize_from_str, xml_serialize_with_decl};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::complex_types::*;
use super::complex_types::*;

#[derive(XmlSerialize, XmlDeserialize, Debug)]
#[xmlserde(with_ns = b"http://schemas.openxmlformats.org/spreadsheetml/2006/main")]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::defaults::default_zero_u8;
use crate::Unparsed;
use super::defaults::default_zero_u8;
use xmlserde::{Unparsed, XmlDeserialize, XmlSerialize};

// Ct_OfficeStyleSheet 20.1.6.2
#[derive(Debug, XmlSerialize, XmlDeserialize)]
Expand All @@ -20,7 +20,7 @@ pub struct CtBaseStyles {
#[xmlserde(name = b"a:clrScheme", ty = "child")]
pub clr_scheme: CtColorScheme,
#[xmlserde(name = b"a:fontScheme", ty = "child")]
pub font_scheme: CtFontScheme,
pub font_scheme: ThemeCtFontScheme,
#[xmlserde(name = b"a:fmtScheme", ty = "child")]
pub fmt_scheme: Unparsed,
}
Expand Down Expand Up @@ -100,7 +100,7 @@ pub struct CtSrgbColor {
}

#[derive(Debug, XmlSerialize, XmlDeserialize)]
pub struct CtFontScheme {
pub struct ThemeCtFontScheme {
#[xmlserde(name = b"name", ty = "attr")]
pub name: String,
#[xmlserde(name = b"a:majorFont", ty = "child")]
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
match r {
Ok(theme) => {
assert_eq!(theme.name, "Office 主题​​");
use crate::test_utils::*;
use crate::ooxml::test_utils::*;
use crate::xml_serialize_with_decl;
let expected = to_tree(&in_one_line(xml));
let actual = xml_serialize_with_decl(b"a:theme", theme);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::complex_types::*;
use crate::simple_types::*;
use super::complex_types::*;
use super::simple_types::*;

#[derive(Debug, XmlSerialize, XmlDeserialize)]
#[xmlserde(with_ns = b"http://schemas.openxmlformats.org/spreadsheetml/2006/main")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::complex_types::*;
use xmlserde::{XmlDeserialize, XmlSerialize};

#[derive(Debug, XmlSerialize, XmlDeserialize)]
#[xmlserde(with_ns = b"http://schemas.openxmlformats.org/spreadsheetml/2006/main")]
Expand Down
Loading

0 comments on commit 8dc97e3

Please sign in to comment.