Skip to content

A few rendering tweaks. #27

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

Open
wants to merge 4 commits into
base: develop
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
13 changes: 7 additions & 6 deletions lib/RenderApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ sub startup {

sanitizeHostURLs();

# Remove default public directory from static route.
pop @{ $self->static->paths };

print "Renderer is based at $main::basehref\n";
print "Problem attempts will be sent to $main::formURL\n";

Expand Down Expand Up @@ -199,12 +202,10 @@ sub sanitizeHostURLs {
$ENV{baseURL} = '';
} elsif ($ENV{baseURL} =~ m!\S!) {

# ENV{baseURL} is used to build routes, so configure as "/extension"
$ENV{baseURL} = "/$ENV{baseURL}";
warn "*** [CONFIG] baseURL should not end in a slash\n"
if $ENV{baseURL} =~ s!/$!!;
warn "*** [CONFIG] baseURL should begin with a slash\n"
unless $ENV{baseURL} =~ s!^//!/!;
# ENV{baseURL} is used to build routes, so configure as "/extension".
# Ensure ENV{baseURL} starts with a slash but doesn't end with a slash.
$ENV{baseURL} = "/$ENV{baseURL}" unless $ENV{baseURL} =~ m!^/!;
$ENV{baseURL} =~ s!/$!!;

# base href must end in a slash when not hosting at the root
$main::basehref =
Expand Down
1 change: 1 addition & 0 deletions lib/RenderApp/Controller/Render.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use WeBWorK::PreTeXt;
sub parseRequest {
my $c = shift;
my %params = %{ $c->req->params->to_hash };
$params{outputFormat} ||= $params{outputformat} || 'default';

my $originIP = $c->req->headers->header('X-Forwarded-For')
// '' =~ s!^\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*$!$1!r;
Expand Down
9 changes: 3 additions & 6 deletions lib/WeBWorK/FormatRenderedProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ sub formatRenderedProblem {

# Third party CSS
my @third_party_css = map { getAssetURL($formLanguage, $_->[0]) } (
[ 'css/bootstrap.css', ],
[ 'node_modules/jquery-ui-dist/jquery-ui.min.css', ],
['css/bootstrap.css'],
['node_modules/jquery-ui-dist/jquery-ui.min.css'],
['node_modules/@fortawesome/fontawesome-free/css/all.min.css'],
);

# Add CSS files requested by problems via ADD_CSS_FILE() in the PG file
# or via a setting of $ce->{pg}{specialPGEnvironmentVars}{extra_css_files}
# which can be set in course.conf (the value should be an anonomous array).
my @cssFiles;
# if (ref($ce->{pg}{specialPGEnvironmentVars}{extra_css_files}) eq 'ARRAY') {
# push(@cssFiles, { file => $_, external => 0 }) for @{ $ce->{pg}{specialPGEnvironmentVars}{extra_css_files} };
# }
if (ref($rh_result->{flags}{extra_css_files}) eq 'ARRAY') {
push @cssFiles, @{ $rh_result->{flags}{extra_css_files} };
}
Expand Down Expand Up @@ -87,7 +84,7 @@ sub formatRenderedProblem {
);

# Get the requested format. (outputFormat or outputformat)
my $formatName = $inputs_ref->{outputFormat} || 'default';
my $formatName = $inputs_ref->{outputFormat} || $inputs_ref->{outputformat} || 'default';

# Add JS files requested by problems via ADD_JS_FILE() in the PG file.
my @extra_js_files;
Expand Down
10 changes: 5 additions & 5 deletions lib/WeBWorK/RenderProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ sub standaloneRenderer {
showAttemptPreviews => 1, # display LaTeX version of submitted answer
showHints => $showHints, # default is to showHint (set in PG.pm)
showSolutions => $showSolutions,
showCorrectAnswers => $inputs_ref->{showCorrectAnswers} ? 2 : 0,
num_of_correct_ans => $inputs_ref->{numCorrect} || 0,
num_of_incorrect_ans => $inputs_ref->{numIncorrect} || 0,
showCorrectAnswers => $inputs_ref->{showCorrectAnswers} && $displayResults || 0,
Copy link
Member

Choose a reason for hiding this comment

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

This is still not right. The value of showCorrectAnswers should be numeric and should be one of 0, 1, or 2. This does not allow for a value of 2 which is the case that correct answers are shown without the button to reveal the correct answers.

num_of_correct_ans => $inputs_ref->{numCorrect} || 0,
num_of_incorrect_ans => $inputs_ref->{numIncorrect} || 0,
displayMode => $inputs_ref->{displayMode},
useMathQuill => !defined $inputs_ref->{entryAssist} || $inputs_ref->{entryAssist} eq 'MathQuill',
answerPrefix => $inputs_ref->{answerPrefix},
Expand All @@ -225,8 +225,8 @@ sub standaloneRenderer {
language => $inputs_ref->{language} // 'en',
language_subroutine => WeBWorK::Localize::getLoc($inputs_ref->{language} // 'en'),
templateDirectory => "$ENV{RENDER_ROOT}/",
htmlURL => 'pg_files/',
tempURL => 'pg_files/tmp/',
htmlURL => '/pg_files/',
tempURL => '/pg_files/tmp/',
debuggingOptions => {
show_resource_info => $inputs_ref->{show_resource_info},
view_problem_debugging_info => $inputs_ref->{view_problem_debugging_info}
Expand Down
17 changes: 9 additions & 8 deletions lib/WeBWorK/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sub getThirdPartyAssetURL {
. substr($dependencies->{$_}, 1) . '/'
. ($1 =~ s/(?:\.min)?\.(js|css)$/.min.$1/gr);
} else {
return Mojo::URL->new("${baseURL}$file")->query(version => $dependencies->{$_} =~ s/#/@/gr)->to_string;
return Mojo::URL->new("$baseURL/$file")->query(version => $dependencies->{$_})->to_string;
}
}
}
Expand Down Expand Up @@ -99,10 +99,10 @@ sub getAssetURL {
# If so, then either serve it from a CDN if requested, or serve it directly with the library version
# appended as a URL parameter.
if ($file =~ /^node_modules/) {
my $wwFile = getThirdPartyAssetURL($file, $thirdPartyWWDependencies, '', 0);
my $wwFile = getThirdPartyAssetURL($file, $thirdPartyWWDependencies, $ENV{baseURL}, 0);
return $wwFile if $wwFile;

my $pgFile = getThirdPartyAssetURL($file, $thirdPartyPGDependencies, 'pg_files/', 1);
my $pgFile = getThirdPartyAssetURL($file, $thirdPartyPGDependencies, "$ENV{baseURL}/pg_files", 0);
return $pgFile if $pgFile;
}

Expand All @@ -114,21 +114,22 @@ sub getAssetURL {
: undef;

# First check to see if this is a file in the webwork htdocs location with a rtl variant.
return "$staticWWAssets->{$rtlfile}"
return "$ENV{baseURL}/$staticWWAssets->{$rtlfile}"
if defined $rtlfile && defined $staticWWAssets->{$rtlfile};

# Next check to see if this is a file in the webwork htdocs location.
return "$staticWWAssets->{$file}" if defined $staticWWAssets->{$file};
return "$ENV{baseURL}/$staticWWAssets->{$file}" if defined $staticWWAssets->{$file};

# Now check to see if this is a file in the pg htdocs location with a rtl variant.
return "pg_files/$staticPGAssets->{$rtlfile}" if defined $rtlfile && defined $staticPGAssets->{$rtlfile};
return "$ENV{baseURL}/pg_files/$staticPGAssets->{$rtlfile}"
if defined $rtlfile && defined $staticPGAssets->{$rtlfile};

# Next check to see if this is a file in the pg htdocs location.
return "pg_files/$staticPGAssets->{$file}" if defined $staticPGAssets->{$file};
return "$ENV{baseURL}/pg_files/$staticPGAssets->{$file}" if defined $staticPGAssets->{$file};

# If the file was not found in the lists, then just use the given file and assume its path is relative to the
# render app public folder.
return "$file";
return "$ENV{baseURL}/$file";
}

1;
1 change: 0 additions & 1 deletion templates/RPCRenderFormats/default.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<html <%== $COURSE_LANG_AND_DIR %>>
<head>
<meta charset='utf-8'>
<base href="<%= $SITE_URL %>">
<title>
WeBWorK using host: <%= $SITE_URL %>,
format: <%= $formatName %>,
Expand Down
2 changes: 1 addition & 1 deletion templates/columns/editorIframe.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%= javascript 'node_modules/iframe-resizer/js/iframeResizer.min.js'
%= javascript "$ENV{baseURL}/node_modules/iframe-resizer/js/iframeResizer.min.js"

<div id="iframe-header" class='header iframe-header'>
<button type="button" id="render-button">Render contents of editor</button>
Expand Down
2 changes: 1 addition & 1 deletion templates/columns/editorUI.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%= javascript 'node_modules/@openwebwork/pg-codemirror-editor/dist/pg-codemirror-editor.js'
%= javascript "$ENV{baseURL}/node_modules/\@openwebwork/pg-codemirror-editor/dist/pg-codemirror-editor.js"
%= javascript 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'

<div id='edit-header' class='header'>
Expand Down
4 changes: 2 additions & 2 deletions templates/columns/filebrowser.html.ep
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%= stylesheet 'css/filebrowser.css'
%= javascript 'js/filebrowser.js'
%= stylesheet "$ENV{baseURL}/css/filebrowser.css"
%= javascript "$ENV{baseURL}/js/filebrowser.js"

<div class='header'>
Current directory path: </br>
Expand Down
2 changes: 1 addition & 1 deletion templates/columns/oplIframe.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%= javascript 'node_modules/iframe-resizer/js/iframeResizer.min.js'
%= javascript "$ENV{baseURL}/node_modules/iframe-resizer/js/iframeResizer.min.js"
%= stylesheet begin
.pgfile-header {
max-height: 30%;
Expand Down
6 changes: 3 additions & 3 deletions templates/columns/tags.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%= stylesheet 'css/tags.css'
%= stylesheet "$ENV{baesURL}/css/tags.css"

% my $taxo = '';
% if ( open(TAXONOMY, "<:encoding(utf8)", $c->app->home->child('tmp/tagging-taxonomy.json')) ) {
Expand Down Expand Up @@ -79,12 +79,12 @@
</div>
</div>
<div class = 'form-row'>
%= submit_button 'Save Tags'
%= submit_button 'Save Tags'
</div>
%= end
</div>

%= javascript begin
taxo = <%== $taxo %>;
%= end
%= javascript 'js/tags.js'
%= javascript "$ENV{baseURL}/js/tags.js"
5 changes: 2 additions & 3 deletions templates/layouts/navbar.html.ep
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<base href="<%= $main::basehref %>">
<title>WeBWorK Standalone Renderer</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
%= stylesheet 'css/navbar.css'
%= stylesheet "$ENV{baseURL}/css/navbar.css"
</head>
<body>
<div class="topnav" id="myTopnav">
Expand All @@ -29,6 +28,6 @@
</div>
</div>
<%= content %>
%= javascript 'js/navbar.js'
%= javascript "$ENV{baseURL}/js/navbar.js"
</body>
</html>
4 changes: 2 additions & 2 deletions templates/pages/flex.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%= stylesheet 'css/opl-flex.css'
%= stylesheet "$ENV{baseURL}/css/opl-flex.css"

<div class='container'>
<div class='left'>
Expand All @@ -16,4 +16,4 @@
<div class='content'>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion templates/pages/oplUI.html.ep
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%= stylesheet 'css/opl-flex.css'
%= stylesheet "$ENV{baseULR}/css/opl-flex.css"

<div class="container">
<div class="left">
Expand Down
2 changes: 1 addition & 1 deletion templates/pages/twocolumn.html.ep
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% layout 'navbar';
%= stylesheet 'css/twocolumn.css'
%= stylesheet "$ENV{baseURL}/css/twocolumn.css"
%= javascript 'https://cdn.jsdelivr.net/npm/[email protected]/base64.min.js'

<div class="row" style="margin-top: 47px;">
Expand Down