Add json listing for crosslang new

This commit is contained in:
2025-05-26 13:10:46 -05:00
parent 7456bf9bc0
commit 67e115705e
13 changed files with 86 additions and 161 deletions

View File

@@ -1,14 +0,0 @@
<?component(body) name="Shell" ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello, world</title>
</head>
<body>
<?body?>
<?end?>
</body>
</html>
<?end?>

View File

@@ -1,7 +0,0 @@
<?page() route="/" ?>
<?Shell?>
<?arg_component() ?>
<?end?>
<?end?>
<?end?>

View File

@@ -2,8 +2,11 @@ var count = 0;
func Pages.Index()
{
//use null when you wan't to use multiple tags but not emit a div or anything like that
return Components.Shell(
<null>
<h1>Hello, world</h1>
<span>Views: {++count}</span>
</null>
);
}

View File

@@ -1,3 +0,0 @@
<?component() name="Counter" ?>
<p>Count is <?expr count++ ?></p>
<?end?>

View File

@@ -1,36 +0,0 @@
<?resource name="simple.min.css" route="/css/simple.min.css" ?>
<?resource name="favicon.ico" route="/favicon.ico" ?>
<?component(title,pages,body) name="Shell" ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>%PROJECT_NAME% - <?expr Net.Http.HtmlEncode(title) ?></title>
<link rel="stylesheet" href="./css/simple.min.css">
</head>
<body>
<header>
<h1>%PROJECT_NAME%</h1>
<nav>
<ul>
<?code
each(var item : pages)
{
?>
<li><a <?code if(item.active) { ?> aria-current="page" <?code } ?> href="<?expr Net.Http.UrlPathEncode(item.route) ?>"><?expr Net.Http.HtmlEncode(item.text) ?></a></li>
<?code
}
?>
</ul>
</nav>
</header>
<h1><?expr Net.Http.HtmlEncode(title) ?></h1>
<?body?>
<?end?>
<footer>
<p>Created using <a href="https://crosslang.tesseslanguage.com/">CrossLang</a> and <a href="https://simplecss.org/">SimpleCSS</a></p>
</footer>
</body>
</html>
<?end?>

View File

@@ -1,28 +0,0 @@
<?page() route="/about" ?>
<?code
var pages = [
{
active = false,
route = "/",
text = "Home"
},
{
active = false,
route = "/counter",
text = "Counter"
},
{
active = true,
route = "/about",
text = "About"
}
];
?>
<?Shell?>
<?arg "About Me" ?>
<?arg pages ?>
<?arg_component() ?>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam possimus nisi ab nobis magni, error minus vero neque iusto beatae, quasi nostrum. Ut repudiandae expedita reprehenderit tenetur. Sunt, adipisci cumque!</p>
<?end?>
<?end?>
<?end?>

View File

@@ -1,29 +0,0 @@
<?page() route="/counter" ?>
<?code
var pages = [
{
active = false,
route = "/",
text = "Home"
},
{
active = true,
route = "/counter",
text = "Counter"
},
{
active = false,
route = "/about",
text = "About"
}
];
?>
<?Shell?>
<?arg "Counter" ?>
<?arg pages ?>
<?arg_component() ?>
<?Counter ?>
<?end?>
<?end?>
<?end?>
<?end?>

View File

@@ -1,28 +0,0 @@
<?page() route="/" ?>
<?code
var pages = [
{
active = true,
route = "/",
text = "Home"
},
{
active = false,
route = "/counter",
text = "Counter"
},
{
active = false,
route = "/about",
text = "About"
}
];
?>
<?Shell?>
<?arg "Main Page" ?>
<?arg pages ?>
<?arg_component() ?>
<p>1 John 4:4: You, dear children, are from God and have overcome them, because the one who is in you is greater than the one who is in the world.</p>
<?end?>
<?end?>
<?end?>

View File

@@ -13,20 +13,23 @@ func Components.Shell(title,pages,body)
<h1>%PROJECT_NAME%</h1>
<nav>
<ul>
<?code
each(var item : pages)
{
?>
<li><a <?code if(item.active) { ?> aria-current="page" <?code } ?> href="<?expr Net.Http.UrlPathEncode(item.route) ?>"><?expr Net.Http.HtmlEncode(item.text) ?></a></li>
<?code
}
?>
<each(var item : pages)>
<li>
<if(item.active)>
<true>
<a aria-current="page" href={item.route}>{item.text}</a>
</true>
<false>
<a aria-current="page" href={item.route}>{item.text}</a>
</false>
</if>
</li>
</each>
</ul>
</nav>
</header>
<h1><?expr Net.Http.HtmlEncode(title) ?></h1>
<?body?>
<?end?>
<h1>{title}</h1>
<raw(body)>
<footer>
<p>Created using <a href="https://crosslang.tesseslanguage.com/">CrossLang</a> and <a href="https://simplecss.org/">SimpleCSS</a></p>
</footer>

View File

@@ -7,7 +7,27 @@ func main(args)
ctx.WithMimeType("text/html").SendText(Pages.Index());
return true;
}
else if(ctx.Path == "/simple.min.css")
else if(ctx.Path == "/counter")
{
ctx.WithMimeType("text/html").SendText(Pages.Counter());
return true;
}
else if(ctx.Path == "/about")
{
ctx.WithMimeType("text/html").SendText(Pages.Index());
return true;
}
else if(ctx.Path == "/echo")
{
ctx.WithMimeType("text/html").SendText(Pages.Echo(ctx.QueryParams.TryGetFirst("text")));
return true;
}
else if(ctx.Path == "/image.png")
{
ctx.WithMimeType("image/png").SendBytes(embed("image.png"));
return true;
}
else if(ctx.Path == "/css/simple.min.css")
{
ctx.WithMimeType("text/css").SendBytes(embed("simple.min.css"));
return true;
@@ -17,5 +37,6 @@ func main(args)
ctx.WithMimeType("image/x-icon").SendBytes(embed("favicon.ico"));
return true;
}
return false;
},4206);
}

View File

@@ -196,6 +196,7 @@ func Tesses.CrossLang.BuildTool(pm)
}
else if(dep.Info.type == "compile_tool")
{
file_tools.Add({
Name = dep.Name,
Version = dep.Version
@@ -208,7 +209,7 @@ func Tesses.CrossLang.BuildTool(pm)
{
each(var file : FS.Local.EnumeratePaths(sourceDir))
{
if(FS.Local.RegularFileExists(file))
if(FS.Local.RegularFileExists(file) && file.GetExtension()==".tcross")
{
var src = {
FileName = file.ToString(),

View File

@@ -17,3 +17,25 @@ func Tesses.CrossLang.GetNameAndDescription(name)
return $"{name}: {description}";
}
func Tesses.CrossLang.GetNameAndDescriptionJson(name)
{
var strm = FS.Local.OpenFile(name,"rb");
var file = VM.LoadExecutable(strm);
strm.Close();
var name = file.Name;
var j = Json.Decode(file.Info);
var description = TypeOf(j.description) == "String" ? j.description : "";
if(j.type == "template")
name = TypeOf(j.template_name) == "String" ? j.template_name : name;
else if(j.type == "tool")
name = TypeOf(j.toolname) == "String" ? j.toolname : name;
return {
name,
description
};
}

View File

@@ -335,6 +335,7 @@ func main(args)
Console.WriteLine("FLAGS");
Console.WriteLine("--help: Shows this help");
Console.WriteLine("--list: Lists all templates");
Console.WriteLine("--list-json: List all templates (as json)");
Console.WriteLine("ARGUMENTS:");
Console.WriteLine("template_name: The name of the template");
Console.WriteLine("directory_for_project: The directory for the project, defaults to current directory");
@@ -352,6 +353,16 @@ func main(args)
}
return 0;
}
else if(flag == "list-json")
{
var items = [];
each(var item : FS.Local.EnumeratePaths(dir))
{
items.Add(Tesses.CrossLang.GetNameAndDescriptionJson(item));
}
Console.WriteLine(items);
return 0;
}
else if(flag == "help")
{
newHelp();
@@ -409,13 +420,21 @@ func main(args)
if(TypeOf(filesToMutate) == "Undefined") filesToMutate = [];
each(var f : projectDir.EnumeratePaths(srcDir))
func mutateDir(dir)
{
if(projectDir.RegularFileExists(f) && f.GetExtension() == ".tcross")
each(var f : projectDir.EnumeratePaths(dir))
{
filesToMutate.Add(f);
if(projectDir.RegularFileExists(f) && f.GetExtension() == ".tcross")
{
filesToMutate.Add(f);
}
else if(projectDir.DirectoryExists(f))
{
mutateDir(f);
}
}
}
mutateDir(srcDir);
each(var ent : filesToMutate)
{
@@ -429,6 +448,7 @@ func main(args)
FS.WriteAllText(projectDir, ent, src);
}
}
FS.WriteAllText(projectDir, "/cross.json", Json.Encode(proj,true));