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

Render json with latex #107

Merged
merged 44 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2235fec
1.0
shreyash-x Jan 21, 2023
004e3f8
added isPlugin for run function
Aditya-debug15 Jan 21, 2023
9c0a5b1
Fixed bugs
shreyash-x Jan 24, 2023
3c71f79
Added combinations
shreyash-x Feb 7, 2023
f321708
Added break in switch
shreyash-x Feb 7, 2023
c1c278c
Disabled validation plugin when validation is disabled
shreyash-x Feb 7, 2023
353a3cc
Created npm package
shreyash-x Feb 19, 2023
ad2080a
package published
shreyash-x Mar 5, 2023
3191fed
Added feature for custom css/js in md
shreyash-x Mar 5, 2023
f934ae6
Added katex rendering for json
shreyash-x Mar 9, 2023
a98b1a7
Also added functionality for custom js/css modules
shreyash-x Mar 9, 2023
e56fe4d
code updated
Aditya-debug15 Mar 13, 2023
8364b3f
Added schema for js css modules
shreyash-x Mar 21, 2023
8b6e4e8
created a log file which contains error in assesment files
Aditya-debug15 Mar 21, 2023
1503b97
added assesment.log file
Aditya-debug15 Mar 21, 2023
ccaa9c9
added functionality to validate assesment files within recursive lear…
Aditya-debug15 Mar 22, 2023
17151fd
Fixed bug in expDesc validation
shreyash-x Mar 25, 2023
a565a74
Added windows support
shreyash-x Apr 7, 2023
6cbfd2d
Added windows support
shreyash-x Apr 7, 2023
6ca50dc
Logging library added, versioning in plugin added
shreyash-x Apr 7, 2023
17e3a48
added file name in logs
Aditya-debug15 Apr 11, 2023
a3ae7bf
Added line number and file name in logs
shreyash-x Apr 12, 2023
d7a3a85
Fixed bug in assesment
shreyash-x Apr 12, 2023
67c3bc8
spelling fixed in assessment
Aditya-debug15 Apr 13, 2023
bffc348
spelling fixed in assessment
Aditya-debug15 Apr 13, 2023
d2eca23
Fixed bug in args
shreyash-x Apr 13, 2023
73289ca
Fixed bug in args
shreyash-x Apr 13, 2023
605a616
Fixed bug in args
shreyash-x Apr 13, 2023
b9e6046
Fixed bug in args
shreyash-x Apr 13, 2023
5d9fec0
Fixed bug in args
shreyash-x Apr 13, 2023
73b27a2
Rename exp.js to Exp.js
shreyash-x Apr 13, 2023
64e65cc
Fixed bug in args
shreyash-x Apr 13, 2023
92fa43f
Merge branch 'render-json-with-latex' of https://github.com/virtual-l…
shreyash-x Apr 13, 2023
5e1abdc
Fixed bug in args
shreyash-x Apr 13, 2023
359a267
fixed bugs in plugin
shreyash-x Apr 13, 2023
330f191
Added debug flag
shreyash-x Apr 17, 2023
e4b1a91
added debug mode
Aditya-debug15 Apr 17, 2023
e18ccd1
Revert "fixed bugs in plugin"
shreyash-x Apr 17, 2023
755a902
Merge branch 'render-json-with-latex' of github.com:virtual-labs/ph3-…
Aditya-debug15 Apr 17, 2023
3d7bb17
added debug flag
Aditya-debug15 Apr 17, 2023
373d156
Added debug mode logs
shreyash-x Apr 19, 2023
9a7c24b
code refactored
Aditya-debug15 Apr 21, 2023
0b7e9e1
merged master with render-json-with-latex
Aditya-debug15 Apr 21, 2023
dfe466e
code refactored
Aditya-debug15 Apr 21, 2023
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 Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Lab = {
}

const Experiment = {
descriptor_name: "experiment-descriptor",
descriptor_name: "experiment-descriptor.json",
default_descriptor: "default-experiment-descriptor.json",
build_dir: "build",
exp_dir: "experiment",
Expand Down
73 changes: 47 additions & 26 deletions Experiment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require("path");
const fs = require("fs");
const {renderMarkdown} = require("./renderMarkdown");
const { renderMarkdown } = require("./renderer.js");
const process = require("process");
const shell = require("shelljs");

Expand All @@ -21,27 +21,21 @@ class Experiment {
this.descriptor = require(Experiment.descriptorPath(src));
}

static ui_template_path = path.resolve(Config.Experiment.ui_template_name);
static ui_template_path = path.resolve(__dirname,Config.Experiment.ui_template_name);

static static_content_path = path.resolve(
__dirname,
Config.Experiment.static_content_dir
);

static descriptorPath(src) {
return path.resolve(src, `${Config.Experiment.descriptor_name}.json`);
return path.resolve(src, Config.Experiment.descriptor_name);
}

static contributorsPath(src) {
return path.resolve(`${src}/experiment`, 'contributors.md');
}

clean() {
const bp = path.resolve(this.src, Config.Experiment.build_dir);
if (shell.test("-d", bp)) {
shell.rm("-rf", bp);
}
}

static registerPartials(hb) {
Config.Experiment.partials.forEach(([name, file]) => {
const partial_content = fs.readFileSync(
Expand All @@ -61,6 +55,21 @@ class Experiment {
shell.mkdir(path.resolve(this.src, Config.Experiment.build_dir));
shell.cp("-R", path.resolve(this.src, Config.Experiment.exp_dir), bp);
shell.cp("-R", path.resolve(Experiment.ui_template_path, "assets"), bp);

// Copy the Katex CSS and fonts to the build directory in katex_assets
shell.mkdir(path.resolve(bp, "katex_assets"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are panning to have an asset directory, maybe we can put the KaTeX assets inside /asset/katex directory

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have moved katex_assets to the assets directory

shell.cp(
"-R",
path.resolve("node_modules", "katex", "dist", "katex.min.css"),
path.resolve(bp, "katex_assets")
);
shell.cp(
"-R",
path.resolve("node_modules", "katex", "dist", "fonts"),
path.resolve(bp, "katex_assets")
);


shell.cp(
"-R",
path.resolve(Experiment.static_content_path, "feedback.md"),
Expand All @@ -73,17 +82,26 @@ class Experiment {
}
}

validate(build_options) {
const buildPath = Config.build_path(this.src);
const expPath = path.resolve(this.src, Config.Experiment.exp_dir);
if (build_options.isESLINT) {
shell.exec(
`npx eslint -c ${__dirname}/.eslintrc.js ${expPath} > ${buildPath}/eslint.log`
);
}
if (build_options.isExpDesc) {
shell.exec(
`node ${__dirname}/validation/validate.js -f ${this.descriptor} > ${buildPath}/validate.log`
);
}
}

name() {
const name_file = fs.readFileSync(
path.resolve(Config.build_path(this.src), "experiment-name.md")
);
return renderMarkdown(name_file.toString());
}

prebuild() {
const bp = Config.build_path(this.src);
shell.exec(`npx eslint -c ./.eslintrc.js ../experiment > ${bp}/eslint.log`);
shell.exec(`node ./validation/validate.js -f ../experiment-descriptor.json > ${bp}/validate.log`);
return renderMarkdown(name_file.toString());
}

build(hb, lab_data, options) {
Expand All @@ -96,19 +114,22 @@ class Experiment {
name: this.name(),
menu: explu.units,
src: this.src,
bp : Config.build_path(this.src) + "/",
bp: Config.build_path(this.src) + "/",
};

exp_info.plugins = Plugin.processExpScopePlugins(
exp_info,
hb,
lab_data,
options
);

if (options.plugins) {
exp_info.plugins = Plugin.processExpScopePlugins(
exp_info,
hb,
lab_data,
options
);
}
explu.build(exp_info, lab_data, options);
// post build
Plugin.processPostBuildPlugins(exp_info, options);
if (options.plugins) {
Plugin.processPostBuildPlugins(exp_info, options);
}
/*
This "tmp" directory is needed because when you have a sub-directory
with the same name, it can cause issue. So, we assume that there should
Expand Down
69 changes: 62 additions & 7 deletions Task.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require("path");
const fs = require("fs");
const {renderMarkdown} = require("./renderMarkdown");
const { renderJSON, renderMarkdown } = require("./renderer.js");
const process = require("process");
const Handlebars = require("handlebars");
const shell = require("shelljs");
Expand Down Expand Up @@ -30,13 +30,17 @@ class Task extends Unit {
basedir,
source,
target,
js_modules,
css_modules,
lu
) {
super(unit_type, label, exp_path, basedir);
this.lu = lu;
this.content_type = validContentType(content_type);
this.source = source;
this.target = target;
this.js_modules = js_modules || [];
this.css_modules = css_modules || [];
}

static unit_type = UnitTypes.TASK;
Expand All @@ -50,6 +54,8 @@ class Task extends Unit {
t["basedir"],
t["source"],
t["target"],
t["js_modules"],
t["css_modules"],
lu
);
}
Expand Down Expand Up @@ -102,6 +108,51 @@ class Task extends Unit {
);
}

isURL(source) {
try {
new URL(source);
return true;
} catch (e) {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log a statement here mentioning that ${source} is not a valid URL. Will help in case an intended URL has errors in it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A log statement is added

}
}

jsPath() {
let final_paths = [];
for (let js_path of this.js_modules) {
if (this.isURL(js_path)) {
final_paths.push(js_path);
continue;
}

const absolute_path = path.resolve(
path.join(Config.build_path(this.exp_path), this.basedir, js_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the path.resolve returns an error, in case the path mentioned is not a valid path in the system?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.resolve will return a relative path to that file, after that, we use fs.existsSync to check whether the file actually exists or not.

);
final_paths.push(
path.relative(path.dirname(this.targetPath()), absolute_path)
);
}
return final_paths;
}

cssPath() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both jsPath and cssPath can be the same function with final_path and js_path/css_path passed in as parameters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new function is created by the name finalPath that takes 1 parameter

let final_paths = [];
for (let css_path of this.css_modules) {
if (this.isURL(css_path)) {
final_paths.push(css_path);
continue;
}

const absolute_path = path.resolve(
path.join(Config.build_path(this.exp_path), this.basedir, css_path)
);
final_paths.push(
path.relative(path.dirname(this.targetPath()), absolute_path)
);
}
return final_paths;
}

buildPage(exp_info, lab_data, options) {
let assets_path = path.relative(
path.dirname(this.targetPath()),
Expand Down Expand Up @@ -134,6 +185,8 @@ class Task extends Unit {
isSimulation: false,
isAssesment: false,
assets_path: assets_path,
js_modules: this.jsPath(),
css_modules: this.cssPath(),
lab_data: lab_data,
exp_info: exp_info,
lab: lab_data.lab,
Expand Down Expand Up @@ -200,18 +253,19 @@ class Task extends Unit {
page_data.isAssesment = true;

if (shell.test("-f", this.sourcePath())) {
page_data.questions = require(this.sourcePath());
if (page_data.questions.version) {
let JSONdata = require(this.sourcePath());
JSONdata = renderJSON(JSON.stringify(JSONdata));
if (JSONdata.version) {
/**
* The below condition will only work if the version in the json is either 2 or 2.0, for any update in version
* it needs to be changed here accordingly
*/
if (page_data.questions.version == 2) {
page_data.isJsonVersion2 = page_data.questions.version;
if (JSONdata.version == 2) {
page_data.isJsonVersion2 = JSONdata.version;
}
page_data.questions = page_data.questions.questions;
page_data.questions = JSON.parse(JSONdata).questions;
}
page_data.questions_str = JSON.stringify(page_data.questions);
page_data.questions_str = JSONdata;
page_data.isJsonVersion = true;
} else {
const jsonpath = this.sourcePath();
Expand All @@ -233,6 +287,7 @@ class Task extends Unit {

const page_template = fs.readFileSync(
path.resolve(
__dirname,
Config.Experiment.ui_template_name,
"pages",
"content.handlebars"
Expand Down
104 changes: 103 additions & 1 deletion exp.js
Loading