Fix width type case (#453)

* fix: add camelcase to width type

* update
main
bokuweb 2022-03-25 13:20:09 +09:00 committed by GitHub
parent f58fbacdcf
commit 54990d5eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 1446 additions and 1449 deletions

View File

@ -190,7 +190,7 @@ mod tests {
let t = Table::new(vec![]).set_grid(vec![100, 200, 300]); let t = Table::new(vec![]).set_grid(vec![100, 200, 300]);
assert_eq!( assert_eq!(
serde_json::to_string(&t).unwrap(), serde_json::to_string(&t).unwrap(),
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"DXA"},"left":{"val":55,"widthType":"DXA"},"bottom":{"val":0,"widthType":"DXA"},"right":{"val":55,"widthType":"DXA"}},"indent":null,"style":null,"layout":null}}"# r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":null,"style":null,"layout":null}}"#
); );
} }
} }

View File

@ -21,7 +21,7 @@ impl Default for CellMargin {
fn default() -> CellMargin { fn default() -> CellMargin {
CellMargin { CellMargin {
val: 55, val: 55,
width_type: WidthType::DXA, width_type: WidthType::Dxa,
} }
} }
} }
@ -40,12 +40,12 @@ impl Default for TableCellMargins {
TableCellMargins { TableCellMargins {
top: CellMargin { top: CellMargin {
val: 0, val: 0,
width_type: WidthType::DXA, width_type: WidthType::Dxa,
}, },
left: CellMargin::default(), left: CellMargin::default(),
bottom: CellMargin { bottom: CellMargin {
val: 0, val: 0,
width_type: WidthType::DXA, width_type: WidthType::Dxa,
}, },
right: CellMargin::default(), right: CellMargin::default(),
} }
@ -59,10 +59,10 @@ impl TableCellMargins {
pub fn margin(self, top: usize, right: usize, bottom: usize, left: usize) -> TableCellMargins { pub fn margin(self, top: usize, right: usize, bottom: usize, left: usize) -> TableCellMargins {
TableCellMargins { TableCellMargins {
top: CellMargin::new(top, WidthType::DXA), top: CellMargin::new(top, WidthType::Dxa),
left: CellMargin::new(left, WidthType::DXA), left: CellMargin::new(left, WidthType::Dxa),
bottom: CellMargin::new(bottom, WidthType::DXA), bottom: CellMargin::new(bottom, WidthType::Dxa),
right: CellMargin::new(right, WidthType::DXA), right: CellMargin::new(right, WidthType::Dxa),
} }
} }

View File

@ -166,10 +166,10 @@ mod tests {
let c = TableCellProperty::new() let c = TableCellProperty::new()
.vertical_merge(VMergeType::Continue) .vertical_merge(VMergeType::Continue)
.grid_span(3) .grid_span(3)
.width(200, WidthType::DXA); .width(200, WidthType::Dxa);
assert_eq!( assert_eq!(
serde_json::to_string(&c).unwrap(), serde_json::to_string(&c).unwrap(),
r#"{"width":{"width":200,"widthType":"DXA"},"borders":null,"gridSpan":3,"verticalMerge":"continue","verticalAlign":null,"textDirection":null,"shading":null}"# r#"{"width":{"width":200,"widthType":"dxa"},"borders":null,"gridSpan":3,"verticalMerge":"continue","verticalAlign":null,"textDirection":null,"shading":null}"#
); );
} }

View File

@ -20,7 +20,7 @@ impl TableCellWidth {
impl BuildXML for TableCellWidth { impl BuildXML for TableCellWidth {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
XMLBuilder::new() XMLBuilder::new()
.table_cell_width(self.width as i32, WidthType::DXA) .table_cell_width(self.width as i32, WidthType::Dxa)
.build() .build()
} }
} }
@ -35,7 +35,7 @@ mod tests {
#[test] #[test]
fn test_table_width() { fn test_table_width() {
let b = TableCellWidth::new(20, WidthType::DXA).build(); let b = TableCellWidth::new(20, WidthType::Dxa).build();
assert_eq!( assert_eq!(
str::from_utf8(&b).unwrap(), str::from_utf8(&b).unwrap(),
r#"<w:tcW w:w="20" w:type="dxa" />"# r#"<w:tcW w:w="20" w:type="dxa" />"#

View File

@ -17,7 +17,7 @@ impl BuildXML for TableGrid {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
let mut base = XMLBuilder::new().open_table_grid(); let mut base = XMLBuilder::new().open_table_grid();
for g in &self.grid { for g in &self.grid {
base = base.grid_column(*g as i32, WidthType::DXA); base = base.grid_column(*g as i32, WidthType::Dxa);
} }
base.close().build() base.close().build()
} }

View File

@ -20,7 +20,7 @@ impl TableIndent {
impl BuildXML for TableIndent { impl BuildXML for TableIndent {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
XMLBuilder::new() XMLBuilder::new()
.table_indent(self.width, WidthType::DXA) .table_indent(self.width, WidthType::Dxa)
.build() .build()
} }
} }
@ -35,7 +35,7 @@ mod tests {
#[test] #[test]
fn test_table_indent() { fn test_table_indent() {
let b = TableIndent::new(20, WidthType::DXA).build(); let b = TableIndent::new(20, WidthType::Dxa).build();
assert_eq!( assert_eq!(
str::from_utf8(&b).unwrap(), str::from_utf8(&b).unwrap(),
r#"<w:tblInd w:w="20" w:type="dxa" />"# r#"<w:tblInd w:w="20" w:type="dxa" />"#

View File

@ -46,7 +46,7 @@ impl TableProperty {
} }
pub fn indent(mut self, v: i32) -> TableProperty { pub fn indent(mut self, v: i32) -> TableProperty {
self.indent = Some(TableIndent::new(v, WidthType::DXA)); self.indent = Some(TableIndent::new(v, WidthType::Dxa));
self self
} }
@ -160,7 +160,7 @@ mod tests {
let p = TableProperty::new().indent(100); let p = TableProperty::new().indent(100);
assert_eq!( assert_eq!(
serde_json::to_string(&p).unwrap(), serde_json::to_string(&p).unwrap(),
r#"{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"DXA"},"left":{"val":55,"widthType":"DXA"},"bottom":{"val":0,"widthType":"DXA"},"right":{"val":55,"widthType":"DXA"}},"indent":{"width":100,"widthType":"DXA"},"style":null,"layout":null}"# r#"{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":{"width":100,"widthType":"dxa"},"style":null,"layout":null}"#
); );
} }
} }

View File

@ -20,7 +20,7 @@ impl TableWidth {
impl BuildXML for TableWidth { impl BuildXML for TableWidth {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
XMLBuilder::new() XMLBuilder::new()
.table_width(self.width as i32, WidthType::DXA) .table_width(self.width as i32, WidthType::Dxa)
.build() .build()
} }
} }
@ -35,7 +35,7 @@ mod tests {
#[test] #[test]
fn test_table_width() { fn test_table_width() {
let b = TableWidth::new(20, WidthType::DXA).build(); let b = TableWidth::new(20, WidthType::Dxa).build();
assert_eq!( assert_eq!(
str::from_utf8(&b).unwrap(), str::from_utf8(&b).unwrap(),
r#"<w:tblW w:w="20" w:type="dxa" />"# r#"<w:tblW w:w="20" w:type="dxa" />"#

View File

@ -103,7 +103,7 @@ mod tests {
t, t,
Table::without_borders(vec![]) Table::without_borders(vec![])
.set_grid(vec![3212, 3213, 3213]) .set_grid(vec![3212, 3213, 3213])
.width(9638, WidthType::DXA) .width(9638, WidthType::Dxa)
); );
} }

View File

@ -84,7 +84,7 @@ mod tests {
cell, cell,
TableCell::new() TableCell::new()
.add_paragraph(Paragraph::new().add_run(Run::new())) .add_paragraph(Paragraph::new().add_run(Run::new()))
.width(6425, WidthType::DXA) .width(6425, WidthType::Dxa)
.grid_span(2) .grid_span(2)
.vertical_merge(VMergeType::Restart) .vertical_merge(VMergeType::Restart)
.set_border(TableCellBorder::new(TableCellBorderPosition::Top)) .set_border(TableCellBorder::new(TableCellBorderPosition::Top))
@ -123,7 +123,7 @@ mod tests {
cell, cell,
TableCell::new() TableCell::new()
.add_paragraph(Paragraph::new().add_run(Run::new())) .add_paragraph(Paragraph::new().add_run(Run::new()))
.width(6425, WidthType::DXA) .width(6425, WidthType::Dxa)
.vertical_merge(VMergeType::Continue), .vertical_merge(VMergeType::Continue),
); );
} }
@ -149,7 +149,7 @@ mod tests {
cell, cell,
TableCell::new() TableCell::new()
.add_paragraph(Paragraph::new().add_run(Run::new())) .add_paragraph(Paragraph::new().add_run(Run::new()))
.width(6425, WidthType::DXA) .width(6425, WidthType::Dxa)
.vertical_align(VAlignType::Bottom), .vertical_align(VAlignType::Bottom),
); );
} }

View File

@ -7,8 +7,9 @@ use std::str::FromStr;
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Copy, Clone, Debug, PartialEq, Serialize)] #[derive(Copy, Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum WidthType { pub enum WidthType {
DXA, Dxa,
Auto, Auto,
Pct, Pct,
Nil, Nil,
@ -18,7 +19,7 @@ pub enum WidthType {
impl fmt::Display for WidthType { impl fmt::Display for WidthType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self { match *self {
WidthType::DXA => write!(f, "dxa"), WidthType::Dxa => write!(f, "dxa"),
WidthType::Auto => write!(f, "auto"), WidthType::Auto => write!(f, "auto"),
WidthType::Pct => write!(f, "pct"), WidthType::Pct => write!(f, "pct"),
WidthType::Nil => write!(f, "nil"), WidthType::Nil => write!(f, "nil"),
@ -30,11 +31,12 @@ impl fmt::Display for WidthType {
impl FromStr for WidthType { impl FromStr for WidthType {
type Err = errors::TypeError; type Err = errors::TypeError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
// https://github.com/bokuweb/docx-rs/issues/451
match s { match s {
"dxa" => Ok(WidthType::DXA), "DXA" | "dxa" => Ok(WidthType::Dxa),
"auto" => Ok(WidthType::Auto), "Auto" | "auto" => Ok(WidthType::Auto),
"pct" => Ok(WidthType::Pct), "Pct" | "pct" => Ok(WidthType::Pct),
"nil" => Ok(WidthType::Nil), "Nil" | "nil" => Ok(WidthType::Nil),
_ => Ok(WidthType::Unsupported), _ => Ok(WidthType::Unsupported),
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,7 @@ import {
PageMargin, PageMargin,
PageOrientationType, PageOrientationType,
} from "./section-property"; } from "./section-property";
import { DocGridType, DocxJSON, WidthType } from "./json"; import { DocGridType, DocxJSON } from "./json";
import * as wasm from "./pkg"; import * as wasm from "./pkg";
import { Level } from "./level"; import { Level } from "./level";
@ -62,18 +62,22 @@ const convertBorderType = (t: BorderType) => {
} }
}; };
const convertWidthType = (t: WidthType) => { const convertWidthType = (t: string) => {
switch (t) { switch (t) {
case "nil": case "nil":
case "Nil":
return wasm.WidthType.Nil; return wasm.WidthType.Nil;
case "Pct": case "Pct":
case "pct":
return wasm.WidthType.Pct; return wasm.WidthType.Pct;
case "DXA": case "DXA":
return wasm.WidthType.DXA; case "dxa":
return wasm.WidthType.Dxa;
case "Auto": case "Auto":
case "auto":
return wasm.WidthType.Auto; return wasm.WidthType.Auto;
default: default:
return wasm.WidthType.DXA; return wasm.WidthType.Dxa;
} }
}; };

View File

@ -8,7 +8,8 @@ import { DeleteJSON, InsertJSON } from "..";
export type TableCellChildJSON = ParagraphJSON; export type TableCellChildJSON = ParagraphJSON;
export type WidthType = "DXA" | "Auto" | "Pct" | "nil"; export type WidthType = "dxa" | "auto" | "pct" | "nil";
export { TextDirectionType } from "../table-cell"; export { TextDirectionType } from "../table-cell";
export { HeightRule } from "../table-row"; export { HeightRule } from "../table-row";

View File

@ -19,10 +19,10 @@ export type TableProperty = {
export const createDefaultTableCellMargins = () => { export const createDefaultTableCellMargins = () => {
return { return {
top: { val: 0, type: "DXA" }, top: { val: 0, type: "dxa" },
left: { val: 55, type: "DXA" }, left: { val: 55, type: "dxa" },
bottom: { val: 0, type: "DXA" }, bottom: { val: 0, type: "dxa" },
right: { val: 55, type: "DXA" }, right: { val: 55, type: "dxa" },
} as const; } as const;
}; };
@ -69,10 +69,10 @@ export class Table {
cellMargins(top: number, right: number, bottom: number, left: number) { cellMargins(top: number, right: number, bottom: number, left: number) {
this.property.cellMargins = { this.property.cellMargins = {
top: { val: top, type: "DXA" }, top: { val: top, type: "dxa" },
left: { val: left, type: "DXA" }, left: { val: left, type: "dxa" },
bottom: { val: bottom, type: "DXA" }, bottom: { val: bottom, type: "dxa" },
right: { val: right, type: "DXA" }, right: { val: right, type: "dxa" },
}; };
return this; return this;
} }

View File

@ -40,7 +40,7 @@ impl Table {
} }
pub fn width(mut self, w: usize) -> Table { pub fn width(mut self, w: usize) -> Table {
self.0 = self.0.width(w, docx_rs::WidthType::DXA); self.0 = self.0.width(w, docx_rs::WidthType::Dxa);
self self
} }

View File

@ -51,7 +51,7 @@ impl TableCell {
} }
pub fn width(mut self, v: usize) -> TableCell { pub fn width(mut self, v: usize) -> TableCell {
self.0.property = self.0.property.width(v, docx_rs::WidthType::DXA); self.0.property = self.0.property.width(v, docx_rs::WidthType::Dxa);
self self
} }

File diff suppressed because it is too large Load Diff