Rename functions: *_external_link -> *_url

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-05-30 11:00:43 +02:00
parent 7f2e4c8442
commit d2a5e8fb59
6 changed files with 49 additions and 49 deletions

View file

@ -158,7 +158,7 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I)
}); });
let iter = from_entry let iter = from_entry
.add_external_link(rt.store(), url) .add_url(rt.store(), url)
.map_err_trace_exit_unwrap() .map_err_trace_exit_unwrap()
.into_iter(); .into_iter();
@ -239,7 +239,7 @@ fn remove_linking(rt: &Runtime) {
error!("Error parsing URL: {:?}", e); error!("Error parsing URL: {:?}", e);
::std::process::exit(1); ::std::process::exit(1);
}); });
from.remove_external_link(rt.store(), url).map_err_trace_exit_unwrap(); from.remove_url(rt.store(), url).map_err_trace_exit_unwrap();
info!("Ok: {}", id); info!("Ok: {}", id);
} else { } else {
warn!("Entry not found: {:?}", id); warn!("Entry not found: {:?}", id);
@ -314,7 +314,7 @@ fn list_linkings(rt: &Runtime) {
} }
if list_externals { if list_externals {
entry.get_external_links(rt.store()) entry.get_urls(rt.store())
.map_err_trace_exit_unwrap() .map_err_trace_exit_unwrap()
.enumerate() .enumerate()
.for_each(|(i, link)| { .for_each(|(i, link)| {

View file

@ -91,7 +91,7 @@ pub trait BookmarkCollection : Sized + InternalLinker + UrlLinker {
impl BookmarkCollection for Entry { impl BookmarkCollection for Entry {
fn links<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>> { fn links<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>> {
self.get_external_links(store) self.get_urls(store)
} }
fn link_entries(&self) -> Result<Vec<StoreLink>> { fn link_entries(&self) -> Result<Vec<StoreLink>> {
@ -101,17 +101,17 @@ impl BookmarkCollection for Entry {
fn add_link(&mut self, store: &Store, l: Link) -> Result<Vec<StoreId>> { fn add_link(&mut self, store: &Store, l: Link) -> Result<Vec<StoreId>> {
use crate::link::IntoUrl; use crate::link::IntoUrl;
l.into_url().and_then(|url| self.add_external_link(store, url)) l.into_url().and_then(|url| self.add_url(store, url))
} }
fn get_links_matching<'a>(&self, store: &'a Store, r: Regex) -> Result<LinksMatchingRegexIter<'a>> { fn get_links_matching<'a>(&self, store: &'a Store, r: Regex) -> Result<LinksMatchingRegexIter<'a>> {
use self::iter::IntoLinksMatchingRegexIter; use self::iter::IntoLinksMatchingRegexIter;
self.get_external_links(store).map(|iter| iter.matching_regex(r)) self.get_urls(store).map(|iter| iter.matching_regex(r))
} }
fn remove_link(&mut self, store: &Store, l: Link) -> Result<Vec<StoreId>> { fn remove_link(&mut self, store: &Store, l: Link) -> Result<Vec<StoreId>> {
use crate::link::IntoUrl; use crate::link::IntoUrl;
l.into_url().and_then(|url| self.remove_external_link(store, url)) l.into_url().and_then(|url| self.remove_url(store, url))
} }
} }

View file

@ -57,7 +57,7 @@ impl WikiEntry for Entry {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(true) .process_internal_links(true)
.create_internal_targets(true) .create_internal_targets(true)
.process_external_links(true) .process_urls(true)
.process_refs(true); .process_refs(true);
self.autolink_with_processor(store, processor) self.autolink_with_processor(store, processor)

View file

@ -58,7 +58,7 @@ use url::Url;
pub struct LinkProcessor { pub struct LinkProcessor {
process_internal_links: bool, process_internal_links: bool,
create_internal_targets: bool, create_internal_targets: bool,
process_external_links: bool, process_urls: bool,
process_refs: bool process_refs: bool
} }
@ -86,8 +86,8 @@ impl LinkProcessor {
/// Switch external link processing on/off /// Switch external link processing on/off
/// ///
/// An external link must start with `https://` or `http://`. /// An external link must start with `https://` or `http://`.
pub fn process_external_links(mut self, b: bool) -> Self { pub fn process_urls(mut self, b: bool) -> Self {
self.process_external_links = b; self.process_urls = b;
self self
} }
@ -154,11 +154,11 @@ impl LinkProcessor {
let _ = entry.add_internal_link(&mut target)?; let _ = entry.add_internal_link(&mut target)?;
}, },
LinkQualification::ExternalLink(url) => { LinkQualification::ExternalLink(url) => {
if !self.process_external_links { if !self.process_urls {
continue continue
} }
entry.add_external_link(store, url)?; entry.add_url(store, url)?;
}, },
LinkQualification::RefLink(url) => { LinkQualification::RefLink(url) => {
use sha1::{Sha1, Digest}; use sha1::{Sha1, Digest};
@ -273,7 +273,7 @@ impl Default for LinkProcessor {
LinkProcessor { LinkProcessor {
process_internal_links: true, process_internal_links: true,
create_internal_targets: false, create_internal_targets: false,
process_external_links: true, process_urls: true,
process_refs: false process_refs: false
} }
} }
@ -330,7 +330,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(true) .process_internal_links(true)
.create_internal_targets(false) .create_internal_targets(false)
.process_external_links(false) .process_urls(false)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -370,7 +370,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(true) .process_internal_links(true)
.create_internal_targets(false) .create_internal_targets(false)
.process_external_links(false) .process_urls(false)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -391,7 +391,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(true) .process_internal_links(true)
.create_internal_targets(true) .create_internal_targets(true)
.process_external_links(false) .process_urls(false)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -418,7 +418,7 @@ mod tests {
} }
#[test] #[test]
fn test_process_one_external_link() { fn test_process_one_url() {
setup_logging(); setup_logging();
let store = get_store(); let store = get_store();
@ -431,7 +431,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(true) .process_internal_links(true)
.create_internal_targets(true) .create_internal_targets(true)
.process_external_links(true) .process_urls(true)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -481,7 +481,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(false) .process_internal_links(false)
.create_internal_targets(false) .create_internal_targets(false)
.process_external_links(false) .process_urls(false)
.process_refs(true); .process_refs(true);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -514,7 +514,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(false) .process_internal_links(false)
.create_internal_targets(false) .create_internal_targets(false)
.process_external_links(false) .process_urls(false)
.process_refs(true); .process_refs(true);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -547,7 +547,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(false) .process_internal_links(false)
.create_internal_targets(false) .create_internal_targets(false)
.process_external_links(false) .process_urls(false)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -575,7 +575,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(true) .process_internal_links(true)
.create_internal_targets(true) .create_internal_targets(true)
.process_external_links(false) .process_urls(false)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);
@ -605,7 +605,7 @@ mod tests {
let processor = LinkProcessor::default() let processor = LinkProcessor::default()
.process_internal_links(false) .process_internal_links(false)
.create_internal_targets(false) .create_internal_targets(false)
.process_external_links(false) .process_urls(false)
.process_refs(false); .process_refs(false);
let result = processor.process(&mut base, &store); let result = processor.process(&mut base, &store);

View file

@ -79,13 +79,13 @@ impl Iterator for ExternalFilterIter {
/// # See also /// # See also
/// ///
/// Also see `OnlyExternalIter` and `NoExternalIter` and the helper traits/functions /// Also see `OnlyExternalIter` and `NoExternalIter` and the helper traits/functions
/// `OnlyInteralLinks`/`only_internal_links()` and `OnlyExternalLinks`/`only_external_links()`. /// `OnlyInteralLinks`/`only_internal_links()` and `OnlyExternalLinks`/`only_urls()`.
pub trait SelectExternal { pub trait SelectExternal {
fn select_external_links(self, b: bool) -> ExternalFilterIter; fn select_urls(self, b: bool) -> ExternalFilterIter;
} }
impl SelectExternal for LinkIter { impl SelectExternal for LinkIter {
fn select_external_links(self, b: bool) -> ExternalFilterIter { fn select_urls(self, b: bool) -> ExternalFilterIter {
ExternalFilterIter(self, b) ExternalFilterIter(self, b)
} }
} }
@ -128,15 +128,15 @@ impl Iterator for NoExternalIter {
} }
pub trait OnlyExternalLinks : Sized { pub trait OnlyExternalLinks : Sized {
fn only_external_links(self) -> OnlyExternalIter ; fn only_urls(self) -> OnlyExternalIter ;
fn no_internal_links(self) -> OnlyExternalIter { fn no_internal_links(self) -> OnlyExternalIter {
self.only_external_links() self.only_urls()
} }
} }
impl OnlyExternalLinks for LinkIter { impl OnlyExternalLinks for LinkIter {
fn only_external_links(self) -> OnlyExternalIter { fn only_urls(self) -> OnlyExternalIter {
OnlyExternalIter::new(self) OnlyExternalIter::new(self)
} }
} }
@ -144,7 +144,7 @@ impl OnlyExternalLinks for LinkIter {
pub trait OnlyInternalLinks : Sized { pub trait OnlyInternalLinks : Sized {
fn only_internal_links(self) -> NoExternalIter; fn only_internal_links(self) -> NoExternalIter;
fn no_external_links(self) -> NoExternalIter { fn no_urls(self) -> NoExternalIter {
self.only_internal_links() self.only_internal_links()
} }
} }

View file

@ -39,16 +39,16 @@ use crate::iter::UrlIter;
pub trait UrlLinker : InternalLinker { pub trait UrlLinker : InternalLinker {
/// Get the external links from the implementor object /// Get the external links from the implementor object
fn get_external_links<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>>; fn get_urls<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>>;
/// Set the external links for the implementor object /// Set the external links for the implementor object
fn set_external_links(&mut self, store: &Store, links: Vec<Url>) -> Result<Vec<StoreId>>; fn set_urls(&mut self, store: &Store, links: Vec<Url>) -> Result<Vec<StoreId>>;
/// Add an external link to the implementor object /// Add an external link to the implementor object
fn add_external_link(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>>; fn add_url(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>>;
/// Remove an external link from the implementor object /// Remove an external link from the implementor object
fn remove_external_link(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>>; fn remove_url(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>>;
} }
@ -58,7 +58,7 @@ pub trait UrlLinker : InternalLinker {
impl UrlLinker for Entry { impl UrlLinker for Entry {
/// Get the external links from the implementor object /// Get the external links from the implementor object
fn get_external_links<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>> { fn get_urls<'a>(&self, store: &'a Store) -> Result<UrlIter<'a>> {
use crate::iter::OnlyExternalLinks; use crate::iter::OnlyExternalLinks;
// Iterate through all internal links and filter for FileLockEntries which live in // Iterate through all internal links and filter for FileLockEntries which live in
@ -67,7 +67,7 @@ impl UrlLinker for Entry {
self.get_internal_links() self.get_internal_links()
.map(|iter| { .map(|iter| {
debug!("Getting external links"); debug!("Getting external links");
iter.only_external_links().urls(store) iter.only_urls().urls(store)
}) })
} }
@ -79,7 +79,7 @@ impl UrlLinker for Entry {
/// external links than before. /// external links than before.
/// If there are less external links than before, an empty vec![] is returned. /// If there are less external links than before, an empty vec![] is returned.
/// ///
fn set_external_links(&mut self, store: &Store, links: Vec<Url>) -> Result<Vec<StoreId>> { fn set_urls(&mut self, store: &Store, links: Vec<Url>) -> Result<Vec<StoreId>> {
// Take all the links, generate a SHA sum out of each one, filter out the already existing // Take all the links, generate a SHA sum out of each one, filter out the already existing
// store entries and store the other URIs in the header of one FileLockEntry each, in // store entries and store the other URIs in the header of one FileLockEntry each, in
// the path /link/external/<SHA of the URL> // the path /link/external/<SHA of the URL>
@ -146,16 +146,16 @@ impl UrlLinker for Entry {
/// ///
/// # Return Value /// # Return Value
/// ///
/// (See ExternalLinker::set_external_links()) /// (See ExternalLinker::set_urls())
/// ///
/// Returns the StoreIds which were newly created for the new external links, if there are more /// Returns the StoreIds which were newly created for the new external links, if there are more
/// external links than before. /// external links than before.
/// If there are less external links than before, an empty vec![] is returned. /// If there are less external links than before, an empty vec![] is returned.
/// ///
fn add_external_link(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>> { fn add_url(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>> {
// get external links, add this one, save them // get external links, add this one, save them
debug!("Getting links"); debug!("Getting links");
self.get_external_links(store) self.get_urls(store)
.and_then(|links| { .and_then(|links| {
let mut links = links.collect::<Result<Vec<_>>>()?; let mut links = links.collect::<Result<Vec<_>>>()?;
@ -163,7 +163,7 @@ impl UrlLinker for Entry {
links.push(link); links.push(link);
debug!("Setting {} links = {:?}", links.len(), links); debug!("Setting {} links = {:?}", links.len(), links);
self.set_external_links(store, links) self.set_urls(store, links)
}) })
} }
@ -171,22 +171,22 @@ impl UrlLinker for Entry {
/// ///
/// # Return Value /// # Return Value
/// ///
/// (See ExternalLinker::set_external_links()) /// (See ExternalLinker::set_urls())
/// ///
/// Returns the StoreIds which were newly created for the new external links, if there are more /// Returns the StoreIds which were newly created for the new external links, if there are more
/// external links than before. /// external links than before.
/// If there are less external links than before, an empty vec![] is returned. /// If there are less external links than before, an empty vec![] is returned.
/// ///
fn remove_external_link(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>> { fn remove_url(&mut self, store: &Store, link: Url) -> Result<Vec<StoreId>> {
// get external links, remove this one, save them // get external links, remove this one, save them
self.get_external_links(store) self.get_urls(store)
.and_then(|links| { .and_then(|links| {
debug!("Removing link = '{:?}'", link); debug!("Removing link = '{:?}'", link);
let links = links let links = links
.filter_map(Result::ok) .filter_map(Result::ok)
.filter(|l| l.as_str() != link.as_str()) .filter(|l| l.as_str() != link.as_str())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
self.set_external_links(store, links) self.set_urls(store, links)
}) })
} }
@ -215,10 +215,10 @@ mod tests {
let mut e = store.retrieve(PathBuf::from("base-test_simple")).unwrap(); let mut e = store.retrieve(PathBuf::from("base-test_simple")).unwrap();
let url = Url::parse("http://google.de").unwrap(); let url = Url::parse("http://google.de").unwrap();
assert!(e.add_external_link(&store, url.clone()).is_ok()); assert!(e.add_url(&store, url.clone()).is_ok());
assert_eq!(1, e.get_external_links(&store).unwrap().count()); assert_eq!(1, e.get_urls(&store).unwrap().count());
assert_eq!(url, e.get_external_links(&store).unwrap().next().unwrap().unwrap()); assert_eq!(url, e.get_urls(&store).unwrap().next().unwrap().unwrap());
} }
} }