Skip to content
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
96 changes: 95 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 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 <amitu@acko.com>"]
description = "Rust / Elm base full stack web framework."
license = "BSD-2-Clause"
Expand All @@ -19,6 +19,7 @@ failure = "~0.1.1"
url = "~1"
htmlescape = "0.3.1"
itertools = "~0.7.8"
rust-embed = "5.1.0"


[dependencies.chrono]
Expand Down
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
36 changes: 24 additions & 12 deletions realm-cli/realm_cli/rust_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import re
from typing import List, Tuple, Optional, Match
from string import Template
Expand All @@ -14,7 +15,7 @@
"""

FORWARD_TEMPLATE = """pub fn magic(%s) -> realm::Result {%s
let mut input = realm::request_config::RequestConfig::new(req)?;
let input = realm::request_config::RequestConfig::new(req)?;
match input.path.as_str() {%s
}
}
Expand Down Expand Up @@ -85,7 +86,8 @@ def get_routes(test_dir: Optional[str] = None):
path = f"/{routePath}/{routeName}/"
module = routePath.replace("/", "::") + "::" + routeName
print("module", module)
routes.append((path, module, parse(root + "/" + fileName)[1:]))
parse_res = parse(root + "/" + fileName)
routes.append((path, module, parse_res[0][1:], parse_res[1] ))

routes.sort(reverse=True)
return routes
Expand All @@ -95,14 +97,14 @@ def generate_forward(directories, routes, test_dir=None):
# filter routes and directories based on whitelist

forward = ""

print(routes)
if "context" in REALM_CONFIG:
ireq_type = REALM_CONFIG["context"]
else:
print("'context' key is absent in realm.json")
ireq_type = None

for (url, mod, args) in routes:
for (url, mod, args, is_layout_present) in routes:
if url == "/" and mod != "index":
url += mod + "/"

Expand Down Expand Up @@ -165,10 +167,12 @@ def generate_forward(directories, routes, test_dir=None):


def generate_reverse(
routes: List[Tuple[str, str, List[Tuple[str, str]]]], test_dir: Optional[str] = None
routes: (List[Tuple[str, str, List[Tuple[str, str]]]], bool), test_dir: Optional[str] = None
) -> str:
reverse: str = ""
for (url, mod, args) in routes:
for (url, mod, args, is_layout_present) in routes:
if not is_layout_present:
return ""
if url == "/":
function_name = mod
if mod != "index":
Expand All @@ -177,7 +181,7 @@ def generate_reverse(
function_name = url[1:].replace("/", "_").replace("_index", "")
if function_name.endswith("_"):
function_name = function_name[:-1]

print("args ", args)
if len(args) == 0:
reverse += """
pub fn %s() -> String {
Expand Down Expand Up @@ -213,7 +217,7 @@ def generate_reverse(
return reverse_content


def parse(mod_path: str) -> List[Tuple[str, str]]:
def parse(mod_path: str) -> (List[Tuple[str, str]], bool):
"""
Given a module name (file path, relative to ., eg src/acko/utils.rs), this
function returns:
Expand All @@ -222,13 +226,21 @@ def parse(mod_path: str) -> List[Tuple[str, str]]:

"""
with open(mod_path, "r") as f:
file_content = f.read()
if not re.search(r'.*?(pub fn layout)', file_content ):
return ([], False)

args_str_: Optional[Match[str]] = re.compile(
r"(?<=pub fn layout\()[^{]*(?=\) ->)"
).search(f.read().replace("\n", " "))
).search(file_content.replace("\n", " "))
args_str: str = "" if not args_str_ else args_str_[0].replace(" ", "")
return [


return ([
(r.split(":")[0], r.split(":")[1]) for r in args_str.split(",") if r != ""
]
], True)

return ([], False)


def main() -> None:
Expand All @@ -254,7 +266,7 @@ def test() -> None:
print(i)
gen_reverse_content = generate_reverse(r, test_dir=test_dir)
reverse_content = open(test_dir + "/reverse.rs").read()

print("gen reverse content is", gen_reverse_content)
try:
assert gen_reverse_content.strip() == reverse_content.strip()
except:
Expand Down
Loading