diff --git a/Cargo.lock b/Cargo.lock index 7fbfc73..c2ee53d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -599,7 +599,7 @@ dependencies = [ [[package]] name = "realm" -version = "0.1.7" +version = "0.1.8" dependencies = [ "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index bdef827..560f5f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "realm" -version = "0.1.7" +version = "0.1.8" authors = ["Amit Upadhyay "] description = "Rust / Elm base full stack web framework." license = "BSD-2-Clause" diff --git a/realm-cli/realm_cli/__init__.py b/realm-cli/realm_cli/__init__.py index d28d290..8d861f2 100644 --- a/realm-cli/realm_cli/__init__.py +++ b/realm-cli/realm_cli/__init__.py @@ -1 +1 @@ -name = "graftpress_cli" +name = "realm_cli" diff --git a/realm-cli/realm_cli/compile_elm.py b/realm-cli/realm_cli/compile_elm.py index be13deb..32b9605 100644 --- a/realm-cli/realm_cli/compile_elm.py +++ b/realm-cli/realm_cli/compile_elm.py @@ -6,28 +6,21 @@ home: str = expanduser("~") -elm_path_G: str = "forgit/dwelm/elm_latest/node_modules/elm/bin/elm" -elm_path_G = home + "/" + elm_path_G -elm_format_path_G: str = "forgit/dwelm/elm_latest/node_modules/elm-format/bin/elm-format" -elm_format_path_G = home + "/" + elm_format_path_G - -go_to_dir_G: str = home + "/forgit/dwelm/graftpress/" - - -def compile( +def compile_( source_path: str, destination_path: str, - elm_path: str = elm_path_G, - elm_format_path: str = elm_format_path_G, - elm_proj_dir: str = go_to_dir_G, + elm_path: str, + elm_format_path: str, + elm_proj_dir: str, ): if elm_proj_dir: os.chdir(elm_proj_dir) print("source dest ", os.getcwd(), source_path, destination_path) os.system(elm_format_path + " --yes " + source_path) - os.system(elm_path + " make " + source_path + " --output " + destination_path) + os.system(elm_path + " make " + source_path + " --output " + + destination_path) def has_main(file: str) -> bool: @@ -37,7 +30,7 @@ def has_main(file: str) -> bool: reg_st = r"\s+?main\s*?=\s*?(Browser[.])?((sandbox)|(element))\s*\{.*?\}" c = re.compile(reg_st, re.DOTALL) search_result: Optional[Match[str]] = c.search(content_st) - return search_result != None + return search_result is not None def populate_set(bucket: Set[str], source_dir: str, root_path: str): @@ -65,9 +58,9 @@ def check_conflicts(source_dirs: List[str]): def compile_all_elm( source_dir: str, destination_dir: str, - elm_path: str = elm_path_G, - elm_format_path: str = elm_format_path_G, - go_to_dir: str = go_to_dir_G, + elm_path: str, + elm_format_path: str, + go_to_dir: str, ): # handle error @@ -92,7 +85,7 @@ def compile_all_elm( if file_extension == ".elm" and has_main(source_path): dest_path = destination_dir + "/" + filename + ".js" - compile(source_path, dest_path, elm_path, elm_format_path, go_to_dir) + compile_(source_path, dest_path, elm_path, elm_format_path, go_to_dir) if __name__ == "__main__": diff --git a/realm-cli/realm_cli/rust_json.py b/realm-cli/realm_cli/rust_json.py index e502e80..43c6c69 100644 --- a/realm-cli/realm_cli/rust_json.py +++ b/realm-cli/realm_cli/rust_json.py @@ -14,7 +14,7 @@ """ FORWARD_TEMPLATE = """pub fn magic(%s) -> realm::Result {%s - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() {%s } } @@ -110,7 +110,7 @@ def generate_forward(directories, routes, test_dir=None): if len(args) == 0: forward += """ - "%s" => crate::routes::%s::layout(&input.req),""" % ( + "%s" => crate::routes::%s::layout(&req),""" % ( url, mod, ) @@ -133,7 +133,7 @@ def generate_forward(directories, routes, test_dir=None): ) forward += """ - crate::routes::%s::layout(&input.req, %s) + crate::routes::%s::layout(&req, %s) },""" % ( mod, ", ".join(arg[0] for arg in args), diff --git a/realm-cli/setup.py b/realm-cli/setup.py index 410acd9..d79d917 100644 --- a/realm-cli/setup.py +++ b/realm-cli/setup.py @@ -9,7 +9,7 @@ setup( name="graftpress_cli", - version="0.0.10", + version="0.0.11", entry_points={"console_scripts": ["realm-cli=graftpress_cli.main:main"]}, author="nilinswap", author_email="nilinswap@gmail.com", diff --git a/realm-cli/tests/01_basic/forward.rs b/realm-cli/tests/01_basic/forward.rs index 2ea72e5..152e782 100644 --- a/realm-cli/tests/01_basic/forward.rs +++ b/realm-cli/tests/01_basic/forward.rs @@ -1,7 +1,7 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { - "/" => crate::routes::index::layout(&input.req), + "/" => crate::routes::index::layout(&req), _ => unimplemented!(), } } \ No newline at end of file diff --git a/realm-cli/tests/02_single_arg/forward.rs b/realm-cli/tests/02_single_arg/forward.rs index 92bb349..657bda3 100644 --- a/realm-cli/tests/02_single_arg/forward.rs +++ b/realm-cli/tests/02_single_arg/forward.rs @@ -1,9 +1,9 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { "/" => { let i = input.get("i", false)?; - crate::routes::index::layout(&input.req, i) + crate::routes::index::layout(&req, i) }, _ => unimplemented!(), } diff --git a/realm-cli/tests/03_two_args/forward.rs b/realm-cli/tests/03_two_args/forward.rs index 884ebd8..c63ff54 100644 --- a/realm-cli/tests/03_two_args/forward.rs +++ b/realm-cli/tests/03_two_args/forward.rs @@ -1,10 +1,10 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { "/" => { let i = input.get("i", false)?; let s = input.get("s", false)?; - crate::routes::index::layout(&input.req, i, s) + crate::routes::index::layout(&req, i, s) }, _ => unimplemented!(), } diff --git a/realm-cli/tests/04_order/forward.rs b/realm-cli/tests/04_order/forward.rs index 0200b6a..e933667 100644 --- a/realm-cli/tests/04_order/forward.rs +++ b/realm-cli/tests/04_order/forward.rs @@ -1,11 +1,11 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { - "/ab/c/" => crate::routes::ab_c::layout(&input.req), - "/ab/" => crate::routes::ab::layout(&input.req), - "/" => crate::routes::index::layout(&input.req), - "/foo/" => crate::routes::foo::layout(&input.req), - "/bar/" => crate::routes::bar::layout(&input.req), + "/ab/c/" => crate::routes::ab_c::layout(&req), + "/ab/" => crate::routes::ab::layout(&req), + "/" => crate::routes::index::layout(&req), + "/foo/" => crate::routes::foo::layout(&req), + "/bar/" => crate::routes::bar::layout(&req), _ => unimplemented!(), } } \ No newline at end of file diff --git a/realm-cli/tests/05_maybe/forward.rs b/realm-cli/tests/05_maybe/forward.rs index 5914761..b34c0e9 100644 --- a/realm-cli/tests/05_maybe/forward.rs +++ b/realm-cli/tests/05_maybe/forward.rs @@ -1,9 +1,9 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { "/" => { let m = input.get("m", true)?; - crate::routes::index::layout(&input.req, m) + crate::routes::index::layout(&req, m) }, _ => unimplemented!(), } diff --git a/realm-cli/tests/06_default_catchall/forward.rs b/realm-cli/tests/06_default_catchall/forward.rs index 2ea72e5..152e782 100644 --- a/realm-cli/tests/06_default_catchall/forward.rs +++ b/realm-cli/tests/06_default_catchall/forward.rs @@ -1,7 +1,7 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { - "/" => crate::routes::index::layout(&input.req), + "/" => crate::routes::index::layout(&req), _ => unimplemented!(), } } \ No newline at end of file diff --git a/realm-cli/tests/07_default_context_catchall/forward.rs b/realm-cli/tests/07_default_context_catchall/forward.rs index 38c5a22..7c6b1ac 100644 --- a/realm-cli/tests/07_default_context_catchall/forward.rs +++ b/realm-cli/tests/07_default_context_catchall/forward.rs @@ -1,7 +1,7 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { - "/" => crate::routes::index::layout(&input.req), - url_ => crate::cms::layout(&input.req, crate::cms::get_default_context(), url_), + "/" => crate::routes::index::layout(&req), + url_ => crate::cms::layout(&req, crate::cms::get_default_context(), url_), } } \ No newline at end of file diff --git a/realm-cli/tests/07_default_context_catchall/realm.json b/realm-cli/tests/07_default_context_catchall/realm.json index 3c4c767..16e0b6d 100644 --- a/realm-cli/tests/07_default_context_catchall/realm.json +++ b/realm-cli/tests/07_default_context_catchall/realm.json @@ -1,3 +1,3 @@ { - "catchall": "url_ => crate::cms::layout(&input.req, crate::cms::get_default_context(), url_)," + "catchall": "url_ => crate::cms::layout(&req, crate::cms::get_default_context(), url_)," } diff --git a/realm-cli/tests/08_custom_context_catchall/forward.rs b/realm-cli/tests/08_custom_context_catchall/forward.rs index 300d7c0..d0c38be 100644 --- a/realm-cli/tests/08_custom_context_catchall/forward.rs +++ b/realm-cli/tests/08_custom_context_catchall/forward.rs @@ -1,7 +1,7 @@ pub fn magic(req: realm::Request) -> realm::Result { - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { - "/" => crate::routes::index::layout(&input.req), - url_ => crate::cms::layout(&input.req, crate::cms::get_context("cms"), url_), + "/" => crate::routes::index::layout(&req), + url_ => crate::cms::layout(&req, crate::cms::get_context("cms"), url_), } } \ No newline at end of file diff --git a/realm-cli/tests/08_custom_context_catchall/realm.json b/realm-cli/tests/08_custom_context_catchall/realm.json index bcec93c..5812b4b 100644 --- a/realm-cli/tests/08_custom_context_catchall/realm.json +++ b/realm-cli/tests/08_custom_context_catchall/realm.json @@ -1,3 +1,3 @@ { - "catchall": "url_ => crate::cms::layout(&input.req, crate::cms::get_context(\"cms\"), url_)," + "catchall": "url_ => crate::cms::layout(&req, crate::cms::get_context(\"cms\"), url_)," } diff --git a/realm-cli/tests/09_middleware/forward.rs b/realm-cli/tests/09_middleware/forward.rs index 700d1d4..7f98de2 100644 --- a/realm-cli/tests/09_middleware/forward.rs +++ b/realm-cli/tests/09_middleware/forward.rs @@ -1,8 +1,8 @@ pub fn magic(ireq: crate::in_::In) -> realm::Result { let req = ireq.realm_request; - let mut input = realm::request_config::RequestConfig::new(req)?; + let mut input = realm::request_config::RequestConfig::new(&req)?; match input.path.as_str() { - "/" => crate::routes::index::layout(&input.req), + "/" => crate::routes::index::layout(&req), _ => unimplemented!(), } } diff --git a/src/request_config.rs b/src/request_config.rs index 8199625..162240e 100644 --- a/src/request_config.rs +++ b/src/request_config.rs @@ -2,7 +2,6 @@ use serde::de::DeserializeOwned; use std::{collections::HashMap, fmt::Debug, str::FromStr}; #[derive(Debug)] pub struct RequestConfig { - pub req: crate::Request, pub query: std::collections::HashMap, pub data: serde_json::Value, pub rest: String, @@ -26,7 +25,7 @@ fn first_rest(s: &str) -> (Option, String) { } impl RequestConfig { - pub fn new(req: crate::Request) -> std::result::Result { + pub fn new(req: &crate::Request) -> std::result::Result { let url = req.uri(); let path = crate::utils::get_slash_complete_path(url.path()); let site_url = "http://127.0.0.1:3000".to_string(); @@ -42,7 +41,6 @@ impl RequestConfig { query, data, path, - req, }; Ok(req_config) }