* rename

* fix: readme

* fix: README
main
bokuweb 2020-01-24 19:44:43 +09:00 committed by GitHub
parent e479506a49
commit 3d6f36ef88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 129 additions and 123 deletions

8
Cargo.lock generated
View File

@ -75,8 +75,8 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "docx-core"
version = "0.1.0"
name = "docx-rs"
version = "0.2.0"
dependencies = [
"pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"thiserror 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -86,10 +86,10 @@ dependencies = [
]
[[package]]
name = "docx-rs"
name = "docx-wasm"
version = "0.1.0"
dependencies = [
"docx-core 0.1.0",
"docx-rs 0.2.0",
"wasm-bindgen 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-test 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -8,19 +8,26 @@
[![GitHub Actions Status](https://github.com/bokuweb/docx-rs/workflows/Continuous%20Integration/badge.svg)](https://github.com/bokuweb/docx-rs/actions)
## install
```
[dependencies]
docx-rs = "0.2.0"
```
## Example
```rust
use docx_core::*;
use docx_rs::*;
pub fn hello() -> Result<(), DocxError> {
let path = std::path::Path::new("./hello.docx");
let file = std::fs::File::create(&path).unwrap();
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.build()
.pack(file)?;
Ok(())
let path = std::path::Path::new("./hello.docx");
let file = std::fs::File::create(&path).unwrap();
Docx::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.build()
.pack(file)?;
Ok(())
}
```

View File

@ -1,8 +1,21 @@
[package]
name = "docx-core"
version = "0.1.0"
name = "docx-rs"
version = "0.2.0"
authors = ["bokuweb <bokuweb12@gmail.com>"]
repository = "https://github.com/bokuweb/docx-rs"
edition = "2018"
license = "MIT"
readme = "../README.md"
description = "A .docx file generater with Rust/WebAssembly."
keywords = [
"office",
"word",
"docx",
]
[lib]
name = "docx_rs"
path = "src/lib.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -13,4 +26,5 @@ thiserror = "1.0"
zip = { version = "0.5", default-features = false }
[dev-dependencies]
pretty_assertions = "*"
pretty_assertions = "0.6.1"

View File

@ -1,4 +1,4 @@
use docx_core::*;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./alignment.docx");

View File

@ -1,4 +1,4 @@
use docx_core::*;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./comment.docx");

View File

@ -1,4 +1,4 @@
use docx_core::*;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./output/hello.docx");

View File

@ -1,4 +1,4 @@
use docx_core::*;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./history.docx");

View File

@ -1,4 +1,4 @@
use docx_core::*;
use docx_rs::*;
pub const DUMMY: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

View File

@ -1,4 +1,5 @@
use docx_core::*;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./numbering.docx");

View File

@ -1,4 +1,4 @@
use docx_core::*;
use docx_rs::*;
pub fn main() -> Result<(), DocxError> {
let path = std::path::Path::new("./table.docx");

View File

@ -1,6 +1,6 @@
extern crate docx_core;
extern crate docx_rs;
use docx_core::*;
use docx_rs::*;
pub const DUMMY: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

View File

@ -1,5 +1,5 @@
[package]
name = "docx-rs"
name = "docx-wasm"
version = "0.1.0"
authors = ["bokuweb <bokuweb12@gmail.com>"]
edition = "2018"
@ -11,7 +11,7 @@ crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2.50"
docx-core = { path = "../docx-core" }
docx-rs= { path = "../docx-core" }
[dev-dependencies]
wasm-bindgen-test = "0.2"

View File

@ -1,18 +1,14 @@
use docx_core;
use docx_rs;
pub fn create_special_indent(
special_indent_kind: Option<docx_core::SpecialIndentKind>,
special_indent_kind: Option<docx_rs::SpecialIndentKind>,
special_indent_size: Option<usize>,
) -> Option<docx_core::SpecialIndentType> {
) -> Option<docx_rs::SpecialIndentType> {
if let Some(kind) = special_indent_kind {
let size = special_indent_size.unwrap_or_else(|| 0);
match kind {
docx_core::SpecialIndentKind::FirstLine => {
Some(docx_core::SpecialIndentType::FirstLine(size))
}
docx_core::SpecialIndentKind::Hanging => {
Some(docx_core::SpecialIndentType::Hanging(size))
}
docx_rs::SpecialIndentKind::FirstLine => Some(docx_rs::SpecialIndentType::FirstLine(size)),
docx_rs::SpecialIndentKind::Hanging => Some(docx_rs::SpecialIndentType::Hanging(size)),
}
} else {
None

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Comment(docx_core::Comment);
pub struct Comment(docx_rs::Comment);
#[wasm_bindgen(js_name = createComment)]
pub fn create_comment(id: usize) -> Comment {
Comment(docx_core::Comment::new(id))
Comment(docx_rs::Comment::new(id))
}
impl Comment {
pub fn take(self) -> docx_core::Comment {
pub fn take(self) -> docx_rs::Comment {
self.0
}
}

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Delete(docx_core::Delete);
pub struct Delete(docx_rs::Delete);
#[wasm_bindgen(js_name = createDelete)]
pub fn create_delete(run: Run) -> Delete {
Delete(docx_core::Delete::new(run.take()))
Delete(docx_rs::Delete::new(run.take()))
}
impl Delete {
pub fn take(self) -> docx_core::Delete {
pub fn take(self) -> docx_rs::Delete {
self.0
}
}

View File

@ -1,15 +1,15 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Docx(docx_core::Docx);
pub struct Docx(docx_rs::Docx);
#[wasm_bindgen]
#[allow(non_snake_case)]
pub fn createDocx() -> Docx {
Docx(docx_core::Docx::new())
Docx(docx_rs::Docx::new())
}
#[wasm_bindgen]

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Insert(docx_core::Insert);
pub struct Insert(docx_rs::Insert);
#[wasm_bindgen(js_name = createInsert)]
pub fn create_insert(run: Run) -> Insert {
Insert(docx_core::Insert::new(run.take()))
Insert(docx_rs::Insert::new(run.take()))
}
impl Insert {
pub fn take(self) -> docx_core::Insert {
pub fn take(self) -> docx_rs::Insert {
self.0
}
}

View File

@ -1,22 +1,22 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Level(docx_core::Level);
pub struct Level(docx_rs::Level);
#[wasm_bindgen(js_name = createLevel)]
pub fn create_level(id: usize, start: usize, format: &str, text: &str, jc: &str) -> Level {
let start = docx_core::Start::new(start);
let format = docx_core::NumberFormat::new(format);
let text = docx_core::LevelText::new(text);
let jc = docx_core::LevelJc::new(jc);
Level(docx_core::Level::new(id, start, format, text, jc))
let start = docx_rs::Start::new(start);
let format = docx_rs::NumberFormat::new(format);
let text = docx_rs::LevelText::new(text);
let jc = docx_rs::LevelJc::new(jc);
Level(docx_rs::Level::new(id, start, format, text, jc))
}
impl Level {
pub fn take(self) -> docx_core::Level {
pub fn take(self) -> docx_rs::Level {
self.0
}
}
@ -26,7 +26,7 @@ impl Level {
pub fn indent(
mut self,
left: usize,
special_indent_kind: Option<docx_core::SpecialIndentKind>,
special_indent_kind: Option<docx_rs::SpecialIndentKind>,
special_indent_size: Option<usize>,
) -> Self {
let special_indent = create_special_indent(special_indent_kind, special_indent_size);

View File

@ -1,7 +1,7 @@
mod adaptors;
mod comment;
mod delete;
mod docx;
mod doc;
mod insert;
mod level;
mod numbering;
@ -14,8 +14,7 @@ mod table_row;
pub use adaptors::*;
pub use comment::*;
pub use delete::*;
pub use docx::*;
pub use docx_core;
pub use doc::*;
pub use insert::*;
pub use level::*;
pub use numbering::*;

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Numbering(docx_core::Numbering);
pub struct Numbering(docx_rs::Numbering);
#[wasm_bindgen(js_name = createNumbering)]
pub fn create_numbering(id: usize) -> Numbering {
Numbering(docx_core::Numbering::new(id))
Numbering(docx_rs::Numbering::new(id))
}
impl Numbering {
pub fn take(self) -> docx_core::Numbering {
pub fn take(self) -> docx_rs::Numbering {
self.0
}
}

View File

@ -1,14 +1,14 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Paragraph(docx_core::Paragraph);
pub struct Paragraph(docx_rs::Paragraph);
#[wasm_bindgen(js_name = createParagraph)]
pub fn create_paragraph() -> Paragraph {
Paragraph(docx_core::Paragraph::new())
Paragraph(docx_rs::Paragraph::new())
}
#[wasm_bindgen]
@ -19,52 +19,48 @@ impl Paragraph {
}
pub fn add_insert(mut self, i: Insert) -> Paragraph {
self.0
.children
.push(docx_core::ParagraphChild::Insert(i.take()));
self.0.children.push(docx_rs::ParagraphChild::Insert(i.take()));
self
}
pub fn add_delete(mut self, d: Delete) -> Paragraph {
self.0
.children
.push(docx_core::ParagraphChild::Delete(d.take()));
self.0.children.push(docx_rs::ParagraphChild::Delete(d.take()));
self
}
pub fn add_bookmark_start(mut self, id: &str, name: &str) -> Paragraph {
self.0
.children
.push(docx_core::ParagraphChild::BookmarkStart(
docx_core::BookmarkStart::new(id, name),
));
self.0.children.push(docx_rs::ParagraphChild::BookmarkStart(
docx_rs::BookmarkStart::new(id, name),
));
self
}
pub fn add_bookmark_end(mut self, id: &str) -> Paragraph {
self.0.children.push(docx_core::ParagraphChild::BookmarkEnd(
docx_core::BookmarkEnd::new(id),
));
self.0
.children
.push(docx_rs::ParagraphChild::BookmarkEnd(docx_rs::BookmarkEnd::new(
id,
)));
self
}
pub fn add_comment_start(mut self, comment: Comment) -> Paragraph {
self.0
.children
.push(docx_core::ParagraphChild::CommentStart(Box::new(
docx_core::CommentRangeStart::new(comment.take()),
.push(docx_rs::ParagraphChild::CommentStart(Box::new(
docx_rs::CommentRangeStart::new(comment.take()),
)));
self
}
pub fn add_comment_end(mut self, id: usize) -> Paragraph {
self.0.children.push(docx_core::ParagraphChild::CommentEnd(
docx_core::CommentRangeEnd::new(id),
self.0.children.push(docx_rs::ParagraphChild::CommentEnd(
docx_rs::CommentRangeEnd::new(id),
));
self
}
pub fn align(mut self, alignment_type: docx_core::AlignmentType) -> Paragraph {
pub fn align(mut self, alignment_type: docx_rs::AlignmentType) -> Paragraph {
self.0.property = self.0.property.align(alignment_type);
self
}
@ -77,7 +73,7 @@ impl Paragraph {
pub fn indent(
mut self,
left: usize,
special_indent_kind: Option<docx_core::SpecialIndentKind>,
special_indent_kind: Option<docx_rs::SpecialIndentKind>,
special_indent_size: Option<usize>,
) -> Paragraph {
let special_indent = create_special_indent(special_indent_kind, special_indent_size);
@ -86,15 +82,15 @@ impl Paragraph {
}
pub fn numbering(mut self, id: usize, level: usize) -> Self {
let id = docx_core::NumberingId::new(id);
let level = docx_core::IndentLevel::new(level);
let id = docx_rs::NumberingId::new(id);
let level = docx_rs::IndentLevel::new(level);
self.0.property = self.0.property.numbering(id, level);
self
}
}
impl Paragraph {
pub fn take(self) -> docx_core::Paragraph {
pub fn take(self) -> docx_rs::Paragraph {
self.0
}
}

View File

@ -1,14 +1,13 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Run(docx_core::Run);
pub struct Run(docx_rs::Run);
#[wasm_bindgen(js_name = createRun)]
pub fn create_run() -> Run {
Run(docx_core::Run::new())
Run(docx_rs::Run::new())
}
#[wasm_bindgen]
@ -21,25 +20,19 @@ impl Run {
pub fn add_delete_text(mut self, text: &str) -> Run {
self.0
.children
.push(docx_core::RunChild::DeleteText(docx_core::DeleteText::new(
text,
)));
.push(docx_rs::RunChild::DeleteText(docx_rs::DeleteText::new(text)));
self
}
pub fn add_tab(mut self) -> Run {
self.0
.children
.push(docx_core::RunChild::Tab(docx_core::Tab::new()));
self.0.children.push(docx_rs::RunChild::Tab(docx_rs::Tab::new()));
self
}
pub fn add_break(mut self, break_type: docx_core::BreakType) -> Run {
pub fn add_break(mut self, break_type: docx_rs::BreakType) -> Run {
self.0
.children
.push(docx_core::RunChild::Break(docx_core::Break::new(
break_type,
)));
.push(docx_rs::RunChild::Break(docx_rs::Break::new(break_type)));
self
}
@ -80,7 +73,7 @@ impl Run {
}
impl Run {
pub fn take(self) -> docx_core::Run {
pub fn take(self) -> docx_rs::Run {
self.0
}
}

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct Table(docx_core::Table);
pub struct Table(docx_rs::Table);
#[wasm_bindgen(js_name = createTable)]
pub fn create_table() -> Table {
Table(docx_core::Table::new(vec![]))
Table(docx_rs::Table::new(vec![]))
}
impl Table {
pub fn take(self) -> docx_core::Table {
pub fn take(self) -> docx_rs::Table {
self.0
}
}
@ -34,7 +34,7 @@ impl Table {
self
}
pub fn align(mut self, v: docx_core::TableAlignmentType) -> Table {
pub fn align(mut self, v: docx_rs::TableAlignmentType) -> Table {
self.0 = self.0.align(v);
self
}

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct TableCell(docx_core::TableCell);
pub struct TableCell(docx_rs::TableCell);
#[wasm_bindgen(js_name = createTableCell)]
pub fn create_table_cell() -> TableCell {
TableCell(docx_core::TableCell::new())
TableCell(docx_rs::TableCell::new())
}
impl TableCell {
pub fn take(self) -> docx_core::TableCell {
pub fn take(self) -> docx_rs::TableCell {
self.0
}
}
@ -22,11 +22,11 @@ impl TableCell {
pub fn add_paragraph(mut self, p: Paragraph) -> TableCell {
self.0
.contents
.push(docx_core::TableCellContent::Paragraph(p.take()));
.push(docx_rs::TableCellContent::Paragraph(p.take()));
self
}
pub fn vertical_merge(mut self, t: docx_core::VMergeType) -> TableCell {
pub fn vertical_merge(mut self, t: docx_rs::VMergeType) -> TableCell {
self.0.property = self.0.property.vertical_merge(t);
self
}
@ -37,7 +37,7 @@ impl TableCell {
}
pub fn width(mut self, v: usize) -> TableCell {
self.0.property = self.0.property.width(v, docx_core::WidthType::DXA);
self.0.property = self.0.property.width(v, docx_rs::WidthType::DXA);
self
}
}

View File

@ -1,18 +1,18 @@
use super::*;
use docx_core;
use docx_rs;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug)]
pub struct TableRow(docx_core::TableRow);
pub struct TableRow(docx_rs::TableRow);
#[wasm_bindgen(js_name = createTableRow)]
pub fn create_table_row() -> TableRow {
TableRow(docx_core::TableRow::new(vec![]))
TableRow(docx_rs::TableRow::new(vec![]))
}
impl TableRow {
pub fn take(self) -> docx_core::TableRow {
pub fn take(self) -> docx_rs::TableRow {
self.0
}
}