Skip to content

Commit

Permalink
removed support for locales
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelMon committed Dec 24, 2023
1 parent 6745f97 commit 2cf057d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 373 deletions.
66 changes: 2 additions & 64 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ mod locales;
mod parsers;
mod url;
use locales::en_us::Site;
use once_cell::{self, sync::OnceCell};

/// The markup formats supported.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Markup {
/// Common markdown `(LINK TEXT)[URL]`
Markdown,
/// Asciidoc markdown `URL[LINK TEXT]`
Asciidoc,
/// HTML `<a href="URL">LINK TEXT</a>`
HTML,
}

// Initialize a safe global variable.
// Can be only set once but read many times.
static LOCALE: OnceCell<Locale> = OnceCell::new();

#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand All @@ -58,25 +42,6 @@ pub enum Locale {
es_es,
}

#[allow(unused_must_use)]
impl Locale {
/// Sets the value of `LOCALE`. Can only set once.
//TODO: Should be a result since it can panic if ran twice
pub fn new(locale: Locale) {
LOCALE.set(locale);
}

/// Retrieves the value of `LOCALE`, may retrieve an arbitrary number of times.
//TODO: Should be a result since it can panic
pub fn get() -> &'static Locale {
match LOCALE.get().expect("LOCALE was not initialized"){
Locale::en_us => &Locale::en_us,
Locale::es_es => &Locale::es_es,
}

}
}

/// Adds the prefix and postfix around each scripture found in the `text`.
pub fn surround<'a, S: Into<String> + Clone>(text: S, prefix: &'a str, postfix: &'a str) -> String {
parsers::surround::Script::new(text)
Expand All @@ -89,7 +54,7 @@ pub fn surround<'a, S: Into<String> + Clone>(text: S, prefix: &'a str, postfix:
/// Links scriptures found to a online Bible.
pub fn url<S: Into<String> + Clone>(site: &Site, text: S) -> String {
parsers::surround::Script::new(text)
.url(Locale::get(), site)
.url(site)
.get_text()
}

Expand All @@ -100,38 +65,11 @@ mod test {
use super::*;
use pretty_assertions::assert_eq;

#[test]
fn t_set_read_locales() {
let expect = &Locale::en_us;
Locale::new(Locale::en_us);
let got = Locale::get();
assert_eq!(got, expect);
}

#[test]
#[should_panic]
// Should panic because locale was not set.
fn t_read_locales_error() {
let expect = &Locale::en_us;
let got = Locale::get();
assert_eq!(got, expect);
}

#[test]
fn t_revelations_url() {
let text: &str = "A popular scriptures is Rev 12:12. It is quoted often.";
let expect: String = "A popular scriptures is [Rev 12:12](https://www.jw.org/en/library/bible/study-bible/books/revelation/12/#v66012012). It is quoted often.".to_string();
Locale::new(Locale::en_us);
let got: String = Script::new(text).url(Locale::get(), &Site::JwOrg).get_text();
assert_eq!(got, expect)
}

#[test]
fn t_mateo_url() {
let text: &str = "A popular scriptures is Mateo 12:12. It is quoted often.";
let expect: String = "A popular scriptures is [Mateo 12:12](https://www.jw.org/en/library/bible/study-bible/books/mateo/12/#v40012012). It is quoted often.".to_string();
Locale::new(Locale::es_es);
let got: String = Script::new(text).url(Locale::get(), &Site::JwOrg).get_text();
let got: String = Script::new(text).url( &Site::JwOrg).get_text();
assert_eq!(got, expect)
}

Expand Down
297 changes: 0 additions & 297 deletions src/locales/es_es.rs

This file was deleted.

Loading

0 comments on commit 2cf057d

Please sign in to comment.