Initial import: libimagwiki
This commit is contained in:
parent
90eb83a538
commit
bb0d4319c3
10 changed files with 417 additions and 0 deletions
|
@ -35,6 +35,7 @@ members = [
|
||||||
"lib/domain/libimagnotes",
|
"lib/domain/libimagnotes",
|
||||||
"lib/domain/libimagtimetrack",
|
"lib/domain/libimagtimetrack",
|
||||||
"lib/domain/libimagtodo",
|
"lib/domain/libimagtodo",
|
||||||
|
"lib/domain/libimagwiki",
|
||||||
"lib/entry/libimagentryannotation",
|
"lib/entry/libimagentryannotation",
|
||||||
"lib/entry/libimagentrycategory",
|
"lib/entry/libimagentrycategory",
|
||||||
"lib/entry/libimagentrydatetime",
|
"lib/entry/libimagentrydatetime",
|
||||||
|
|
59
doc/src/05100-lib-wiki.md
Normal file
59
doc/src/05100-lib-wiki.md
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
## libimagwiki
|
||||||
|
|
||||||
|
The wiki library implements a complete wiki for personal use.
|
||||||
|
|
||||||
|
This basically is a note-taking functionality combined with linking.
|
||||||
|
|
||||||
|
### Layout
|
||||||
|
|
||||||
|
The basic structure and layout is as simple as it gets:
|
||||||
|
|
||||||
|
`/wiki` holds all wikis. The default wiki is `/wiki/default`. Below that there
|
||||||
|
are entries. Entries can be in sub-collections, so
|
||||||
|
`/wiki/default/cars/mustang` could be an entry.
|
||||||
|
|
||||||
|
|
||||||
|
``` {.numberLines}
|
||||||
|
|
||||||
|
+-------------+
|
||||||
|
| |
|
||||||
|
| WikiStore |
|
||||||
|
| |
|
||||||
|
+------+------+
|
||||||
|
1 |
|
||||||
|
|
|
||||||
|
| n
|
||||||
|
+------v------+
|
||||||
|
| |
|
||||||
|
| Wiki |
|
||||||
|
| |
|
||||||
|
+------+------+
|
||||||
|
1 |
|
||||||
|
|
|
||||||
|
| n
|
||||||
|
+------v------+
|
||||||
|
| | n
|
||||||
|
| Entry <------+
|
||||||
|
| | |
|
||||||
|
+------+------+ |
|
||||||
|
1 | |
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
+-------------+
|
||||||
|
```
|
||||||
|
|
||||||
|
The store offers an interface to get a Wiki. The wiki offers an interface to get
|
||||||
|
entries from it.
|
||||||
|
|
||||||
|
Each Entry might link to a number of other entries _within the same wiki_.
|
||||||
|
Cross-linking from one wiki entry to an entry of another wiki is technically
|
||||||
|
possible, but not supported by the Entry itself (also read below).
|
||||||
|
|
||||||
|
When creating a new wiki, the main page is automatically created.
|
||||||
|
|
||||||
|
### Autolinking
|
||||||
|
|
||||||
|
The `Entry` structure offers an interface which can be used to automatically
|
||||||
|
detect links in the markdown.
|
||||||
|
The links are then automatically linked (as in `libimagentrylink`).
|
||||||
|
|
32
lib/domain/libimagwiki/Cargo.toml
Normal file
32
lib/domain/libimagwiki/Cargo.toml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
[package]
|
||||||
|
name = "libimagwiki"
|
||||||
|
version = "0.7.0"
|
||||||
|
authors = ["Matthias Beyer <mail@beyermatthias.de>"]
|
||||||
|
|
||||||
|
description = "Library for the imag core distribution"
|
||||||
|
|
||||||
|
keywords = ["imag", "PIM", "personal", "information", "management"]
|
||||||
|
readme = "../../../README.md"
|
||||||
|
license = "LGPL-2.1"
|
||||||
|
|
||||||
|
documentation = "https://matthiasbeyer.github.io/imag/imag_documentation/index.html"
|
||||||
|
repository = "https://github.com/matthiasbeyer/imag"
|
||||||
|
homepage = "http://imag-pim.org"
|
||||||
|
|
||||||
|
[badges]
|
||||||
|
travis-ci = { repository = "matthiasbeyer/imag" }
|
||||||
|
is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" }
|
||||||
|
is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
|
||||||
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
error-chain = "0.11"
|
||||||
|
toml = "0.4"
|
||||||
|
toml-query = "0.6"
|
||||||
|
filters = "0.2"
|
||||||
|
|
||||||
|
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
||||||
|
libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" }
|
||||||
|
libimagentrylink = { version = "0.7.0", path = "../../../lib/entry/libimagentrylink" }
|
||||||
|
libimagentrymarkdown = { version = "0.7.0", path = "../../../lib/entry/libimagentrymarkdown" }
|
||||||
|
|
1
lib/domain/libimagwiki/README.md
Symbolic link
1
lib/domain/libimagwiki/README.md
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../../doc/src/05100-lib-wiki.md
|
73
lib/domain/libimagwiki/src/entry.rs
Normal file
73
lib/domain/libimagwiki/src/entry.rs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use libimagstore::store::Store;
|
||||||
|
use libimagstore::store::Entry;
|
||||||
|
use libimagentrymarkdown::processor::LinkProcessor;
|
||||||
|
|
||||||
|
use error::Result;
|
||||||
|
use error::WikiErrorKind as WEK;
|
||||||
|
use error::ResultExt;
|
||||||
|
|
||||||
|
pub trait WikiEntry {
|
||||||
|
fn autolink(&mut self, store: &Store) -> Result<()>;
|
||||||
|
fn autolink_with_processor(&mut self, store: &Store, processor: LinkProcessor) -> Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WikiEntry for Entry {
|
||||||
|
|
||||||
|
/// Autolink entry to entries linked in content
|
||||||
|
///
|
||||||
|
/// Uses `libimagentrymarkdown::processor::LinkProcessor` for this, with the following settings:
|
||||||
|
///
|
||||||
|
/// * Interal link processing = true
|
||||||
|
/// * Internal targets creating = true
|
||||||
|
/// * External link processing = true
|
||||||
|
/// * Processing of Refs = true
|
||||||
|
///
|
||||||
|
/// This is a convenience function for `WikiEntry::autolink_with_processor()`.
|
||||||
|
///
|
||||||
|
/// # Warning
|
||||||
|
///
|
||||||
|
/// With this function, the `LinkProcessor` automatically creates entries in the store if they
|
||||||
|
/// are linked from the current entry but do not exists yet.
|
||||||
|
///
|
||||||
|
/// # See also
|
||||||
|
///
|
||||||
|
/// * The documentation of `WikiEntry::autolink_with_processor()`.
|
||||||
|
/// * The documentation of `::libimagentrymarkdown::processor::LinkProcessor`.
|
||||||
|
///
|
||||||
|
fn autolink(&mut self, store: &Store) -> Result<()> {
|
||||||
|
let processor = LinkProcessor::default()
|
||||||
|
.process_internal_links(true)
|
||||||
|
.create_internal_targets(true)
|
||||||
|
.process_external_links(true)
|
||||||
|
.process_refs(true);
|
||||||
|
|
||||||
|
self.autolink_with_processor(store, processor)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Autolink entry to entries linked in content with the passed `LinkProcessor` instance.
|
||||||
|
///
|
||||||
|
/// See the documentation of `::libimagentrymarkdown::processor::LinkProcessor`.
|
||||||
|
fn autolink_with_processor(&mut self, store: &Store, processor: LinkProcessor) -> Result<()> {
|
||||||
|
processor.process(self, store).chain_err(|| WEK::AutoLinkError(self.get_location().clone()))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
lib/domain/libimagwiki/src/error.rs
Normal file
50
lib/domain/libimagwiki/src/error.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
|
error_chain! {
|
||||||
|
types {
|
||||||
|
WikiError, WikiErrorKind, ResultExt, Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
links {
|
||||||
|
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
|
||||||
|
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
|
||||||
|
}
|
||||||
|
|
||||||
|
errors {
|
||||||
|
WikiDoesNotExist(name: String) {
|
||||||
|
description("Wiki does not exist")
|
||||||
|
display("Wiki '{}' does not exist", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
WikiExists(name: String) {
|
||||||
|
description("Wiki exist already")
|
||||||
|
display("Wiki '{}' exists already", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoLinkError(sid: StoreId) {
|
||||||
|
description("Error while autolinking entry")
|
||||||
|
display("Error while autolinking entry: {}", sid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
53
lib/domain/libimagwiki/src/lib.rs
Normal file
53
lib/domain/libimagwiki/src/lib.rs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
#![recursion_limit="256"]
|
||||||
|
|
||||||
|
#![deny(
|
||||||
|
dead_code,
|
||||||
|
non_camel_case_types,
|
||||||
|
non_snake_case,
|
||||||
|
path_statements,
|
||||||
|
trivial_numeric_casts,
|
||||||
|
unstable_features,
|
||||||
|
unused_allocation,
|
||||||
|
unused_import_braces,
|
||||||
|
unused_imports,
|
||||||
|
unused_must_use,
|
||||||
|
unused_mut,
|
||||||
|
unused_qualifications,
|
||||||
|
while_true,
|
||||||
|
)]
|
||||||
|
|
||||||
|
extern crate toml;
|
||||||
|
extern crate toml_query;
|
||||||
|
#[macro_use] extern crate error_chain;
|
||||||
|
|
||||||
|
#[macro_use] extern crate libimagstore;
|
||||||
|
extern crate libimagerror;
|
||||||
|
extern crate libimagentrylink;
|
||||||
|
extern crate libimagentrymarkdown;
|
||||||
|
|
||||||
|
module_entry_path_mod!("wiki");
|
||||||
|
|
||||||
|
pub mod entry;
|
||||||
|
pub mod error;
|
||||||
|
pub mod store;
|
||||||
|
pub mod wiki;
|
||||||
|
|
96
lib/domain/libimagwiki/src/store.rs
Normal file
96
lib/domain/libimagwiki/src/store.rs
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use libimagstore::store::Store;
|
||||||
|
use libimagstore::storeid::StoreId;
|
||||||
|
use libimagstore::storeid::IntoStoreId;
|
||||||
|
|
||||||
|
use error::WikiError as WE;
|
||||||
|
use error::Result;
|
||||||
|
use wiki::Wiki;
|
||||||
|
|
||||||
|
pub trait WikiStore {
|
||||||
|
|
||||||
|
fn get_wiki<'a, 'b>(&'a self, name: &'b str) -> Result<Option<Wiki<'a, 'b>>>;
|
||||||
|
|
||||||
|
fn create_wiki<'a, 'b>(&'a self, name: &'b str, mainpagename: Option<&str>)
|
||||||
|
-> Result<Wiki<'a, 'b>>;
|
||||||
|
|
||||||
|
fn retrieve_wiki<'a, 'b>(&'a self, name: &'b str, mainpagename: Option<&str>)
|
||||||
|
-> Result<Wiki<'a, 'b>>;
|
||||||
|
|
||||||
|
fn delete_wiki<N: AsRef<str>>(&self, name: N) -> Result<()>;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WikiStore for Store {
|
||||||
|
|
||||||
|
/// get a wiki by its name
|
||||||
|
fn get_wiki<'a, 'b>(&'a self, name: &'b str) -> Result<Option<Wiki<'a, 'b>>> {
|
||||||
|
if wiki_path(name.as_ref())?.with_base(self.path().clone()).exists()? {
|
||||||
|
debug!("Building Wiki object");
|
||||||
|
Ok(Some(Wiki::new(self, name)))
|
||||||
|
} else {
|
||||||
|
debug!("Cannot build wiki object: Wiki does not exist");
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a wiki.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// Returns the Wiki object.
|
||||||
|
///
|
||||||
|
/// Ob success, an empty Wiki entry with the name `mainpagename` (or "main" if none is passed)
|
||||||
|
/// is created inside the wiki.
|
||||||
|
///
|
||||||
|
fn create_wiki<'a, 'b>(&'a self, name: &'b str, mainpagename: Option<&str>)
|
||||||
|
-> Result<Wiki<'a, 'b>>
|
||||||
|
{
|
||||||
|
debug!("Trying to get wiki '{}'", name);
|
||||||
|
debug!("Trying to create wiki '{}' with mainpage: '{:?}'", name, mainpagename);
|
||||||
|
|
||||||
|
let wiki = Wiki::new(self, name);
|
||||||
|
wiki.create_entry(mainpagename.unwrap_or("main")).map(|_| wiki)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn retrieve_wiki<'a, 'b>(&'a self, name: &'b str, mainpagename: Option<&str>)
|
||||||
|
-> Result<Wiki<'a, 'b>>
|
||||||
|
{
|
||||||
|
match self.get_wiki(name)? {
|
||||||
|
None => self.create_wiki(name, mainpagename),
|
||||||
|
Some(wiki) => {
|
||||||
|
let _ = wiki.retrieve_entry(mainpagename.unwrap_or("main"))?; // to make sure the page exists
|
||||||
|
Ok(wiki)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete a wiki and all entries inside
|
||||||
|
fn delete_wiki<N: AsRef<str>>(&self, name: N) -> Result<()> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wiki_path(name: &str) -> Result<StoreId> {
|
||||||
|
::module_path::ModuleEntryPath::new(name).into_storeid().map_err(WE::from)
|
||||||
|
}
|
||||||
|
|
51
lib/domain/libimagwiki/src/wiki.rs
Normal file
51
lib/domain/libimagwiki/src/wiki.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
//
|
||||||
|
// imag - the personal information management suite for the commandline
|
||||||
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
|
// License as published by the Free Software Foundation; version
|
||||||
|
// 2.1 of the License.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
//
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use libimagstore::store::Store;
|
||||||
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagstore::storeid::IntoStoreId;
|
||||||
|
|
||||||
|
use error::WikiError as WE;
|
||||||
|
use error::Result;
|
||||||
|
|
||||||
|
pub struct Wiki<'a, 'b>(&'a Store, &'b str);
|
||||||
|
|
||||||
|
impl<'a, 'b> Wiki<'a, 'b> {
|
||||||
|
|
||||||
|
pub(crate) fn new(store: &'a Store, name: &'b str) -> Wiki<'a, 'b> {
|
||||||
|
Wiki(store, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
|
||||||
|
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
||||||
|
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
|
||||||
|
self.0.create(sid).map_err(WE::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn retrieve_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<FileLockEntry<'a>> {
|
||||||
|
let path = PathBuf::from(format!("{}/{}", self.1, entry_name.as_ref()));
|
||||||
|
let sid = ::module_path::ModuleEntryPath::new(path).into_storeid()?;
|
||||||
|
self.0.retrieve(sid).map_err(WE::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ CRATES=(
|
||||||
./lib/domain/libimagtimetrack
|
./lib/domain/libimagtimetrack
|
||||||
./lib/domain/libimagtodo
|
./lib/domain/libimagtodo
|
||||||
./lib/domain/libimagmail
|
./lib/domain/libimagmail
|
||||||
|
./lib/domain/libimagwiki
|
||||||
./bin/domain/imag-habit
|
./bin/domain/imag-habit
|
||||||
./bin/domain/imag-diary
|
./bin/domain/imag-diary
|
||||||
./bin/domain/imag-contact
|
./bin/domain/imag-contact
|
||||||
|
|
Loading…
Reference in a new issue