refactor: rename macros (#25)

* refactor: rename macros

* fix: some clippy error

* fix: lint error

* chore: run lint in actions
main
bokuweb 2020-01-24 17:57:14 +09:00 committed by GitHub
parent a10441cbdf
commit 22aee045a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 288 additions and 169 deletions

View File

@ -63,18 +63,18 @@ jobs:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- run: cargo build
# clippy:
# name: Clippy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - run: rustup component add clippy
# - uses: actions-rs/cargo@v1
# with:
# command: clippy
# args: -- -D warnings
lint:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings

View File

@ -6,6 +6,12 @@ pub struct ContentTypes {}
impl ContentTypes {
pub fn new() -> ContentTypes {
Default::default()
}
}
impl Default for ContentTypes {
fn default() -> Self {
ContentTypes {}
}
}

View File

@ -6,7 +6,13 @@ pub struct AppProps {}
impl AppProps {
pub fn new() -> AppProps {
AppProps {}
Default::default()
}
}
impl Default for AppProps {
fn default() -> Self {
Self {}
}
}

View File

@ -19,6 +19,30 @@ pub struct CorePropsConfig {
title: Option<String>,
}
impl Default for CorePropsConfig {
fn default() -> Self {
Self {
created: None,
creator: None,
description: None,
language: None,
last_modified_by: None,
modified: None,
revision: None,
subject: None,
title: None,
}
}
}
impl Default for CoreProps {
fn default() -> Self {
Self {
config: CorePropsConfig::default(),
}
}
}
impl CoreProps {
pub(crate) fn new(config: CorePropsConfig) -> CoreProps {
CoreProps { config }

View File

@ -9,7 +9,13 @@ pub struct DocumentRels {
impl DocumentRels {
pub fn new() -> DocumentRels {
DocumentRels {
Default::default()
}
}
impl Default for DocumentRels {
fn default() -> Self {
Self {
has_comments: false,
has_numberings: false,
}

View File

@ -6,7 +6,13 @@ pub struct Bold {}
impl Bold {
pub fn new() -> Bold {
Bold {}
Default::default()
}
}
impl Default for Bold {
fn default() -> Self {
Self {}
}
}

View File

@ -6,7 +6,13 @@ pub struct BoldCs {}
impl BoldCs {
pub fn new() -> BoldCs {
BoldCs {}
Default::default()
}
}
impl Default for BoldCs {
fn default() -> Self {
Self {}
}
}

View File

@ -10,6 +10,12 @@ pub struct DocDefaults {
impl DocDefaults {
pub fn new() -> DocDefaults {
Default::default()
}
}
impl Default for DocDefaults {
fn default() -> Self {
let run_property_default = RunPropertyDefault::new();
DocDefaults {
run_property_default,

View File

@ -6,7 +6,13 @@ pub struct Italic {}
impl Italic {
pub fn new() -> Italic {
Italic {}
Default::default()
}
}
impl Default for Italic {
fn default() -> Self {
Self {}
}
}

View File

@ -6,7 +6,13 @@ pub struct ItalicCs {}
impl ItalicCs {
pub fn new() -> ItalicCs {
ItalicCs {}
Default::default()
}
}
impl Default for ItalicCs {
fn default() -> Self {
Self {}
}
}

View File

@ -29,7 +29,7 @@ pub enum ParagraphChild {
Delete(Delete),
BookmarkStart(BookmarkStart),
BookmarkEnd(BookmarkEnd),
CommentStart(CommentRangeStart),
CommentStart(Box<CommentRangeStart>),
CommentEnd(CommentRangeEnd),
}
@ -93,9 +93,8 @@ impl Paragraph {
}
pub fn add_comment_start(mut self, comment: Comment) -> Paragraph {
self.children
.push(ParagraphChild::CommentStart(CommentRangeStart::new(
comment,
self.children.push(ParagraphChild::CommentStart(Box::new(
CommentRangeStart::new(comment),
)));
self
}

View File

@ -11,7 +11,13 @@ pub struct QFormat {}
impl QFormat {
pub fn new() -> QFormat {
QFormat {}
Default::default()
}
}
impl Default for QFormat {
fn default() -> Self {
Self {}
}
}

View File

@ -9,6 +9,12 @@ pub struct RunPropertyDefault {
impl RunPropertyDefault {
pub fn new() -> RunPropertyDefault {
Default::default()
}
}
impl Default for RunPropertyDefault {
fn default() -> Self {
let run_property = RunProperty::new();
RunPropertyDefault { run_property }
}

View File

@ -6,6 +6,12 @@ pub struct Tab {}
impl Tab {
pub fn new() -> Tab {
Default::default()
}
}
impl Default for Tab {
fn default() -> Self {
Tab {}
}
}

View File

@ -17,13 +17,7 @@ pub enum TableCellContent {
impl TableCell {
pub fn new() -> TableCell {
let property = TableCellProperty::new();
let contents = vec![];
Self {
property,
contents,
has_numbering: false,
}
Default::default()
}
pub fn add_paragraph(mut self, p: Paragraph) -> TableCell {
@ -50,6 +44,18 @@ impl TableCell {
}
}
impl Default for TableCell {
fn default() -> Self {
let property = TableCellProperty::new();
let contents = vec![];
Self {
property,
contents,
has_numbering: false,
}
}
}
impl BuildXML for TableCell {
fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new();

View File

@ -13,12 +13,7 @@ pub struct TableCellProperty {
impl TableCellProperty {
pub fn new() -> TableCellProperty {
TableCellProperty {
width: None,
borders: None,
grid_span: None,
vertical_merge: None,
}
Default::default()
}
pub fn width(mut self, v: usize, t: WidthType) -> TableCellProperty {
@ -37,6 +32,17 @@ impl TableCellProperty {
}
}
impl Default for TableCellProperty {
fn default() -> Self {
TableCellProperty {
width: None,
borders: None,
grid_span: None,
vertical_merge: None,
}
}
}
impl BuildXML for TableCellProperty {
fn build(&self) -> Vec<u8> {
XMLBuilder::new()

View File

@ -6,6 +6,12 @@ pub struct TableRowProperty {}
impl TableRowProperty {
pub fn new() -> TableRowProperty {
Default::default()
}
}
impl Default for TableRowProperty {
fn default() -> Self {
TableRowProperty {}
}
}

View File

@ -10,6 +10,12 @@ impl Vanish {
}
}
impl Default for Vanish {
fn default() -> Self {
Vanish {}
}
}
impl BuildXML for Vanish {
fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new();

View File

@ -1,12 +1,13 @@
#[allow(unused)]
use std::sync::atomic::{AtomicUsize, Ordering};
#[allow(dead_code)]
#[cfg(not(test))]
use std::sync::atomic::AtomicUsize;
#[cfg(not(test))]
static HISTORY_ID: AtomicUsize = AtomicUsize::new(0);
#[cfg(not(test))]
pub trait HistoryId {
fn generate(&self) -> String {
use std::sync::atomic::Ordering;
let id = HISTORY_ID.load(Ordering::Relaxed);
HISTORY_ID.store(id + 1, Ordering::Relaxed);
format!("{}", id)

View File

@ -133,12 +133,9 @@ impl Docx {
match child {
DocumentChild::Paragraph(paragraph) => {
for child in &paragraph.children {
match child {
ParagraphChild::CommentStart(c) => {
if let ParagraphChild::CommentStart(c) = child {
comments.push(c.comment());
}
_ => {}
}
}
}
DocumentChild::Table(table) => {
@ -148,12 +145,9 @@ impl Docx {
match content {
TableCellContent::Paragraph(paragraph) => {
for child in &paragraph.children {
match child {
ParagraphChild::CommentStart(c) => {
if let ParagraphChild::CommentStart(c) = child {
comments.push(c.comment());
}
_ => {}
}
}
}
}
@ -165,7 +159,7 @@ impl Docx {
}
// If this document has comments, set comments.xml to document_rels.
// This is because comments.xml without comment cause an error on word online.
if comments.len() > 0 {
if !comments.is_empty() {
self.document_rels.has_comments = true;
}
self.comments.add_comments(comments);

View File

@ -6,6 +6,12 @@ pub struct Rels {}
impl Rels {
pub fn new() -> Rels {
Default::default()
}
}
impl Default for Rels {
fn default() -> Self {
Rels {}
}
}
@ -39,9 +45,9 @@ impl BuildXML for Rels {
mod tests {
use super::*;
use std::str;
#[cfg(test)]
use pretty_assertions::assert_eq;
use std::str;
#[test]
fn test_build() {

View File

@ -1,4 +1,4 @@
use super::{DefaultTabStop, Style, Zoom};
use super::{DefaultTabStop, Zoom};
use crate::documents::BuildXML;
use crate::xml_builder::*;

View File

@ -7,5 +7,4 @@ mod zipper;
pub use documents::*;
pub use errors::*;
pub(crate) use escape::*;
pub use types::*;

View File

@ -3,7 +3,7 @@ use super::XmlEvent;
impl XMLBuilder {
// i.e. <cp:properties xmlns:vt="http://schemas.openxmlformats.org/package/2006/relationships">
opened_el!(
open!(
open_core_properties,
"cp:coreProperties",
"xmlns:cp",
@ -12,13 +12,13 @@ impl XMLBuilder {
"xmlns:dcmitype",
"xmlns:xsi"
);
closed_el_with_child!(dcterms_created, "dcterms:created", "xsi:type");
closed_el_with_child!(dc_creator, "dc:creator");
closed_el_with_child!(dc_description, "dc:description");
closed_el_with_child!(dc_language, "dc:language");
closed_el_with_child!(cp_last_modified_by, "cp:lastModifiedBy");
closed_el_with_child!(dcterms_modified, "dcterms:modified", "xsi:type");
closed_el_with_child!(cp_revision, "cp:revision");
closed_el_with_child!(dc_subject, "dc:subject");
closed_el_with_child!(dc_title, "dc:title");
closed_with_child!(dcterms_created, "dcterms:created", "xsi:type");
closed_with_child!(dc_creator, "dc:creator");
closed_with_child!(dc_description, "dc:description");
closed_with_child!(dc_language, "dc:language");
closed_with_child!(cp_last_modified_by, "cp:lastModifiedBy");
closed_with_child!(dcterms_modified, "dcterms:modified", "xsi:type");
closed_with_child!(cp_revision, "cp:revision");
closed_with_child!(dc_subject, "dc:subject");
closed_with_child!(dc_title, "dc:title");
}

View File

@ -6,9 +6,9 @@ const EXPECT_MESSAGE: &str = "should write buf";
impl XMLBuilder {
// i.e. <w:body... >
opened_el!(open_body, "w:body");
open!(open_body, "w:body");
// i.e. <w:basedOn ... >
only_str_val_el!(based_on, "w:basedOn");
closed_with_str!(based_on, "w:basedOn");
// i.e. <w:t ... >
pub(crate) fn text(mut self, text: &str, preserve_space: bool) -> Self {
let space = if preserve_space {
@ -36,32 +36,32 @@ impl XMLBuilder {
self.close()
}
// i.e. <w:r ... >
opened_el!(open_run, "w:r");
opened_el!(open_run_property, "w:rPr");
opened_el!(open_run_property_default, "w:rPrDefault");
open!(open_run, "w:r");
open!(open_run_property, "w:rPr");
open!(open_run_property_default, "w:rPrDefault");
// i.e. <w:qFormat ... >
closed_el!(q_format, "w:qFormat");
closed!(q_format, "w:qFormat");
// i.e. <w:p ... >
// opened_el!(open_paragraph, "w:p");
opened_el_with_attrs!(open_paragraph, "w:p");
opened_el!(open_paragraph_property, "w:pPr");
opened_el!(open_doc_defaults, "w:docDefaults");
// open!(open_paragraph, "w:p");
open_with_attrs!(open_paragraph, "w:p");
open!(open_paragraph_property, "w:pPr");
open!(open_doc_defaults, "w:docDefaults");
// i.e. <w:name ... >
only_str_val_el!(name, "w:name");
closed_with_str!(name, "w:name");
// i.e. <w:jc ... >
only_str_val_el!(justification, "w:jc");
closed_with_str!(justification, "w:jc");
// i.e. <w:pStyle ... >
only_str_val_el!(paragraph_style, "w:pStyle");
closed_with_str!(paragraph_style, "w:pStyle");
// i.e. <w:sz ... >
only_usize_val_el!(sz, "w:sz");
closed_with_usize!(sz, "w:sz");
// i.e. <w:szCs ... >
only_usize_val_el!(sz_cs, "w:szCs");
closed_with_usize!(sz_cs, "w:szCs");
closed_el!(b, "w:b");
closed_el!(b_cs, "w:bCs");
closed!(b, "w:b");
closed!(b_cs, "w:bCs");
closed_el!(i, "w:i");
closed_el!(i_cs, "w:iCs");
closed!(i, "w:i");
closed!(i_cs, "w:iCs");
// Build w:style element
// i.e. <w:style ... >
pub(crate) fn open_style(mut self, style_type: StyleType, id: &str) -> Self {
@ -75,16 +75,16 @@ impl XMLBuilder {
self
}
// i.e. <w:next ... >
only_str_val_el!(next, "w:next");
closed_with_str!(next, "w:next");
// i.e. <w:color ... >
only_str_val_el!(color, "w:color");
closed_with_str!(color, "w:color");
// i.e. <w:highlight ... >
only_str_val_el!(highlight, "w:highlight");
closed_with_str!(highlight, "w:highlight");
// i.e. <w:u ... >
only_str_val_el!(underline, "w:u");
closed_with_str!(underline, "w:u");
// i.e. <w:ind ... >
pub(crate) fn indent(mut self, left: usize, special_indent: Option<SpecialIndentType>) -> Self {
@ -107,24 +107,24 @@ impl XMLBuilder {
//
// Table elements
//
opened_el!(open_table, "w:tbl");
opened_el!(open_table_property, "w:tblPr");
opened_el!(open_table_grid, "w:tblGrid");
opened_el!(open_table_row, "w:tr");
opened_el!(open_table_row_property, "w:trPr");
opened_el!(open_table_cell, "w:tc");
opened_el!(open_table_cell_property, "w:tcPr");
opened_el!(open_table_cell_borders, "w:tcBorders");
opened_el!(open_table_borders, "w:tblBorders");
opened_el!(open_table_cell_margins, "w:tblCellMar");
open!(open_table, "w:tbl");
open!(open_table_property, "w:tblPr");
open!(open_table_grid, "w:tblGrid");
open!(open_table_row, "w:tr");
open!(open_table_row_property, "w:trPr");
open!(open_table_cell, "w:tc");
open!(open_table_cell_property, "w:tcPr");
open!(open_table_cell_borders, "w:tcBorders");
open!(open_table_borders, "w:tblBorders");
open!(open_table_cell_margins, "w:tblCellMar");
closed_w_with_type_el!(table_width, "w:tblW");
closed_w_with_type_el!(table_indent, "w:tblInd");
closed_w_with_type_el!(grid_column, "w:gridCol");
closed_w_with_type_el!(table_cell_width, "w:tcW");
only_usize_val_el!(grid_span, "w:gridSpan");
only_str_val_el!(vertical_merge, "w:vMerge");
closed_with_usize!(grid_span, "w:gridSpan");
closed_with_str!(vertical_merge, "w:vMerge");
closed_w_with_type_el!(margin_top, "w:top");
closed_w_with_type_el!(margin_left, "w:left");
@ -138,24 +138,24 @@ impl XMLBuilder {
closed_border_el!(border_inside_h, "w:insideH");
closed_border_el!(border_inside_v, "w:insideV");
closed_el!(shd, "w:shd", "w:fill", "w:val");
closed!(shd, "w:shd", "w:fill", "w:val");
closed_el!(tab, "w:tab");
closed_el!(tab_with_pos, "w:tab", "w:val", "w:pos");
closed!(tab, "w:tab");
closed!(tab_with_pos, "w:tab", "w:val", "w:pos");
closed_el!(br, "w:br", "w:type");
closed_el!(zoom, "w:zoom", "w:percent");
only_usize_val_el!(default_tab_stop, "w:defaultTabStop");
closed!(br, "w:br", "w:type");
closed!(zoom, "w:zoom", "w:percent");
closed_with_usize!(default_tab_stop, "w:defaultTabStop");
opened_el!(open_font, "w:font", "w:name");
only_str_val_el!(pitch, "w:pitch");
only_str_val_el!(family, "w:family");
only_str_val_el!(charset, "w:charset");
open!(open_font, "w:font", "w:name");
closed_with_str!(pitch, "w:pitch");
closed_with_str!(family, "w:family");
closed_with_str!(charset, "w:charset");
opened_el!(open_section_property, "w:sectPr");
only_str_val_el!(type_tag, "w:type");
closed_el!(page_size, "w:pgSz", "w:w", "w:h");
closed_el!(
open!(open_section_property, "w:sectPr");
closed_with_str!(type_tag, "w:type");
closed!(page_size, "w:pgSz", "w:w", "w:h");
closed!(
page_margin,
"w:pgMar",
"w:top",
@ -166,19 +166,19 @@ impl XMLBuilder {
"w:footer",
"w:gutter"
);
closed_el!(columns, "w:cols", "w:space");
closed_el!(document_grid, "w:docGrid", "w:type", "w:linePitch");
closed!(columns, "w:cols", "w:space");
closed!(document_grid, "w:docGrid", "w:type", "w:linePitch");
opened_el!(open_insert, "w:ins", "w:id", "w:author", "w:date");
opened_el!(open_delete, "w:del", "w:id", "w:author", "w:date");
open!(open_insert, "w:ins", "w:id", "w:author", "w:date");
open!(open_delete, "w:del", "w:id", "w:author", "w:date");
closed_el!(bookmark_start, "w:bookmarkStart", "w:id", "w:name");
closed_el!(bookmark_end, "w:bookmarkEnd", "w:id");
closed!(bookmark_start, "w:bookmarkStart", "w:id", "w:name");
closed!(bookmark_end, "w:bookmarkEnd", "w:id");
closed_el!(comment_range_start, "w:commentRangeStart", "w:id");
closed_el!(comment_range_end, "w:commentRangeEnd", "w:id");
closed_el!(comment_reference, "w:commentReference", "w:id");
opened_el!(
closed!(comment_range_start, "w:commentRangeStart", "w:id");
closed!(comment_range_end, "w:commentRangeEnd", "w:id");
closed!(comment_reference, "w:commentReference", "w:id");
open!(
open_comment,
"w:comment",
"w:id",
@ -187,19 +187,19 @@ impl XMLBuilder {
"w:initials"
);
opened_el!(open_abstract_num, "w:abstractNum", "w:abstractNumId");
opened_el!(open_level, "w:lvl", "w:ilvl");
opened_el!(open_tabs, "w:tabs");
opened_el!(open_num, "w:num", "w:numId");
opened_el!(open_numbering_property, "w:numPr");
only_usize_val_el!(indent_level, "w:ilvl");
only_usize_val_el!(num_id, "w:numId");
only_usize_val_el!(start, "w:start");
only_str_val_el!(number_format, "w:numFmt");
only_str_val_el!(level_text, "w:lvlText");
only_str_val_el!(level_justification, "w:lvlJc");
only_str_val_el!(abstract_num_id, "w:abstractNumId");
closed_el!(vanish, "w:vanish");
open!(open_abstract_num, "w:abstractNum", "w:abstractNumId");
open!(open_level, "w:lvl", "w:ilvl");
open!(open_tabs, "w:tabs");
open!(open_num, "w:num", "w:numId");
open!(open_numbering_property, "w:numPr");
closed_with_usize!(indent_level, "w:ilvl");
closed_with_usize!(num_id, "w:numId");
closed_with_usize!(start, "w:start");
closed_with_str!(number_format, "w:numFmt");
closed_with_str!(level_text, "w:lvlText");
closed_with_str!(level_justification, "w:lvlJc");
closed_with_str!(abstract_num_id, "w:abstractNumId");
closed!(vanish, "w:vanish");
}
#[cfg(test)]

View File

@ -1,5 +1,6 @@
macro_rules! opened_el {
macro_rules! open {
($name: ident, $el_name: expr) => {
#[allow(dead_code)]
pub(crate) fn $name(mut self) -> Self {
self.writer
.write(XmlEvent::start_element($el_name))
@ -49,7 +50,7 @@ macro_rules! opened_el {
};
}
macro_rules! opened_el_with_attrs {
macro_rules! open_with_attrs {
($name: ident, $el_name: expr) => {
pub(crate) fn $name(mut self, attrs: &[(String, String)]) -> Self {
let mut e = XmlEvent::start_element($el_name);
@ -70,8 +71,9 @@ macro_rules! opened_el_with_attrs {
};
}
macro_rules! closed_el_with_child {
macro_rules! closed_with_child {
($name: ident, $el_name: expr) => {
#[allow(dead_code)]
pub(crate) fn $name(mut self, child: &str) -> Self {
self.writer
.write(XmlEvent::start_element($el_name))
@ -117,7 +119,7 @@ macro_rules! closed_el_with_child {
};
}
macro_rules! closed_el {
macro_rules! closed {
($name: ident, $el_name: expr) => {
pub(crate) fn $name(mut self) -> Self {
self.writer
@ -135,6 +137,7 @@ macro_rules! closed_el {
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr) => {
#[allow(dead_code)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str) -> Self {
self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1))
@ -175,6 +178,7 @@ macro_rules! closed_el {
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr) => {
#[allow(clippy::too_many_arguments)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str, arg6: &str) -> Self {
self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5).attr($attr6, arg6))
@ -183,6 +187,7 @@ macro_rules! closed_el {
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr) => {
#[allow(clippy::too_many_arguments)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str, arg6: &str, arg7: &str) -> Self {
self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5).attr($attr6, arg6).attr($attr7, arg7))
@ -191,6 +196,7 @@ macro_rules! closed_el {
}
};
($name: ident, $el_name: expr, $attr0: expr, $attr1: expr, $attr2: expr, $attr3: expr, $attr4: expr, $attr5: expr, $attr6: expr, $attr7: expr, $attr8: expr) => {
#[allow(clippy::too_many_arguments)]
pub(crate) fn $name(mut self, arg0: &str, arg1: &str, arg2: &str, arg3: &str, arg4: &str, arg5: &str, arg6: &str, arg7: &str, arg8: &str) -> Self {
self.writer
.write(XmlEvent::start_element($el_name).attr($attr0, arg0).attr($attr1, arg1).attr($attr2, arg2).attr($attr3, arg3).attr($attr4, arg4).attr($attr5, arg5).attr($attr6, arg6).attr($attr7, arg7).attr($attr8, arg8))
@ -200,8 +206,9 @@ macro_rules! closed_el {
};
}
macro_rules! only_str_val_el {
macro_rules! closed_with_str {
($name: ident, $el_name: expr) => {
#[allow(dead_code)]
pub(crate) fn $name(mut self, val: &str) -> Self {
self.writer
.write(XmlEvent::start_element($el_name).attr("w:val", val))
@ -211,7 +218,7 @@ macro_rules! only_str_val_el {
};
}
macro_rules! only_usize_val_el {
macro_rules! closed_with_usize {
($name: ident, $el_name: expr) => {
pub(crate) fn $name(mut self, val: usize) -> Self {
self.writer

View File

@ -4,16 +4,16 @@ use super::XmlEvent;
impl XMLBuilder {
// Build Properties element
// i.e. <Properties xmlns:vt="http://schemas.openxmlformats.org/package/2006/relationships">
opened_el!(open_properties, "Properties", "xmlns", "xmlns:vt");
open!(open_properties, "Properties", "xmlns", "xmlns:vt");
closed_el_with_child!(template, "Template");
closed_el_with_child!(total_time, "TotalTime");
closed_el_with_child!(application, "Application");
closed_el_with_child!(pages, "Pages");
closed_el_with_child!(words, "Words");
closed_el_with_child!(characters, "Characters");
closed_el_with_child!(characters_with_spaces, "CharactersWithSpaces");
closed_el_with_child!(paragraphs, "Paragraphs");
closed_with_child!(template, "Template");
closed_with_child!(total_time, "TotalTime");
closed_with_child!(application, "Application");
closed_with_child!(pages, "Pages");
closed_with_child!(words, "Words");
closed_with_child!(characters, "Characters");
closed_with_child!(characters_with_spaces, "CharactersWithSpaces");
closed_with_child!(paragraphs, "Paragraphs");
}
#[cfg(test)]

View File

@ -4,10 +4,10 @@ use super::XmlEvent;
impl XMLBuilder {
// Build RelationShips element
// i.e. <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
opened_el!(open_relationships, "Relationships", "xmlns");
open!(open_relationships, "Relationships", "xmlns");
// Build Relationship
closed_el!(relationship, "Relationship", "Id", "Type", "Target");
closed!(relationship, "Relationship", "Id", "Type", "Target");
}
#[cfg(test)]

View File

@ -5,11 +5,7 @@ pub fn create_special_indent(
special_indent_size: Option<usize>,
) -> Option<docx_core::SpecialIndentType> {
if let Some(kind) = special_indent_kind {
let size = if special_indent_size.is_some() {
special_indent_size.unwrap()
} else {
0
};
let size = special_indent_size.unwrap_or_else(|| 0);
match kind {
docx_core::SpecialIndentKind::FirstLine => {
Some(docx_core::SpecialIndentType::FirstLine(size))

View File

@ -20,12 +20,12 @@ impl Comment {
#[wasm_bindgen]
impl Comment {
pub fn author(mut self, author: String) -> Comment {
self.0.author = author.into();
self.0.author = author;
self
}
pub fn date(mut self, date: String) -> Comment {
self.0.date = date.into();
self.0.date = date;
self
}

View File

@ -51,9 +51,9 @@ impl Paragraph {
pub fn add_comment_start(mut self, comment: Comment) -> Paragraph {
self.0
.children
.push(docx_core::ParagraphChild::CommentStart(
.push(docx_core::ParagraphChild::CommentStart(Box::new(
docx_core::CommentRangeStart::new(comment.take()),
));
)));
self
}

View File

@ -1,6 +1,9 @@
test:
cargo test
lint:
cargo clippy --all-targets --all-features -- -D warnings
vrt:
node vrt/index.js && reg-cli vrt/screenshot/actual vrt/screenshot/expected vrt/screenshot/diff -R vrt/report.html -I