Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve realm #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "realm"
version = "0.1.7"
version = "0.1.8"
authors = ["Amit Upadhyay <[email protected]>"]
description = "Rust / Elm base full stack web framework."
license = "BSD-2-Clause"
Expand Down
2 changes: 1 addition & 1 deletion realm-cli/realm_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
name = "graftpress_cli"
name = "realm_cli"
29 changes: 11 additions & 18 deletions realm-cli/realm_cli/compile_elm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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__":
Expand Down
6 changes: 3 additions & 3 deletions realm-cli/realm_cli/rust_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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,
)
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion realm-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions realm-cli/tests/01_basic/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
}
4 changes: 2 additions & 2 deletions realm-cli/tests/02_single_arg/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
Expand Down
4 changes: 2 additions & 2 deletions realm-cli/tests/03_two_args/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
Expand Down
12 changes: 6 additions & 6 deletions realm-cli/tests/04_order/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
}
4 changes: 2 additions & 2 deletions realm-cli/tests/05_maybe/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
Expand Down
4 changes: 2 additions & 2 deletions realm-cli/tests/06_default_catchall/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
}
6 changes: 3 additions & 3 deletions realm-cli/tests/07_default_context_catchall/forward.rs
Original file line number Diff line number Diff line change
@@ -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_),
}
}
2 changes: 1 addition & 1 deletion realm-cli/tests/07_default_context_catchall/realm.json
Original file line number Diff line number Diff line change
@@ -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_),"
}
6 changes: 3 additions & 3 deletions realm-cli/tests/08_custom_context_catchall/forward.rs
Original file line number Diff line number Diff line change
@@ -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_),
}
}
2 changes: 1 addition & 1 deletion realm-cli/tests/08_custom_context_catchall/realm.json
Original file line number Diff line number Diff line change
@@ -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_),"
}
4 changes: 2 additions & 2 deletions realm-cli/tests/09_middleware/forward.rs
Original file line number Diff line number Diff line change
@@ -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!(),
}
}
4 changes: 1 addition & 3 deletions src/request_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>,
pub data: serde_json::Value,
pub rest: String,
Expand All @@ -26,7 +25,7 @@ fn first_rest(s: &str) -> (Option<String>, String) {
}

impl RequestConfig {
pub fn new(req: crate::Request) -> std::result::Result<RequestConfig, failure::Error> {
pub fn new(req: &crate::Request) -> std::result::Result<RequestConfig, failure::Error> {
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();
Expand All @@ -42,7 +41,6 @@ impl RequestConfig {
query,
data,
path,
req,
};
Ok(req_config)
}
Expand Down