Skip to content

Commit 47a0952

Browse files
authored
Merge pull request #2 from drgrice1/update-to-pg-2.17
Update to pg 2.17
2 parents c7878b6 + 1486ff6 commit 47a0952

File tree

3,016 files changed

+1120
-1036037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,016 files changed

+1120
-1036037
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ render_app.conf
33
lib/WeBWorK/htdocs/tmp/renderer/gif/*
44
lib/WeBWorK/htdocs/tmp/renderer/images/*
55
lib/WeBWorK/htdocs/DATA/*.json
6-
lib/WeBWorK/htdocs/js/apps/Problem/problem.css
76
lib/WeBWorK/bin/*
87
webwork-open-problem-library/
98
private/
10-
tmp/
9+
tmp/*
1110
logs/*.log
1211
node_modules
1312
node_modules/*

.gitmodules

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "lib/PG"]
22
path = lib/PG
3-
url = https://github.com/drgrice1/pg.git
4-
branch = ww3-rendering-work-new
3+
url = https://github.com/openwebwork/pg.git
4+
branch = main

lib/PG

Submodule PG updated 239 files

lib/RenderApp.pm

+13-12
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ BEGIN {
55
use Mojo::File;
66
$main::dirname = Mojo::File::curfile->dirname;
77

8-
#RENDER_ROOT is required for initializing conf files
8+
# RENDER_ROOT is required for initializing conf files.
99
$ENV{RENDER_ROOT} = $main::dirname->dirname
1010
unless ( defined( $ENV{RENDER_ROOT} ) );
1111

12-
#WEBWORK_ROOT is required for PG/lib/WeBWorK/IO
13-
$ENV{WEBWORK_ROOT} = $main::dirname . '/WeBWorK'
14-
unless ( defined( $ENV{WEBWORK_ROOT} ) );
12+
# WEBWORK_ROOT is required for PG/lib/WeBWorK/IO.
13+
# PG_ROOT is required for PG/lib/PGEnvironment.pm.
14+
# These are hardcoded to avoid conflict with environment variables for webwork2.
15+
# There is no need for these to be configurable.
16+
$ENV{WEBWORK_ROOT} = $main::dirname . '/WeBWorK';
17+
$ENV{PG_ROOT} = $main::dirname . '/PG';
1518

16-
#used for reconstructing library paths from sym-links
19+
# Used for reconstructing library paths from sym-links.
1720
$ENV{OPL_DIRECTORY} = "webwork-open-problem-library";
1821
$WeBWorK::Constants::WEBWORK_DIRECTORY = $main::dirname . "/WeBWorK";
1922
$WeBWorK::Constants::PG_DIRECTORY = $main::dirname . "/PG";
@@ -60,7 +63,7 @@ sub startup {
6063

6164
# Handle optional CORS settings
6265
if (my $CORS_ORIGIN = $self->config('CORS_ORIGIN')) {
63-
die "CORS_ORIGIN ($CORS_ORIGIN) must be an absolute URL or '*'"
66+
die "CORS_ORIGIN ($CORS_ORIGIN) must be an absolute URL or '*'"
6467
unless ($CORS_ORIGIN eq '*' || $CORS_ORIGIN =~ /^https?:\/\//);
6568

6669
$self->hook(before_dispatch => sub {
@@ -108,12 +111,10 @@ sub startup {
108111
$r->post('/render-api/tags')->to('IO#setTags');
109112
}
110113

111-
# pass all requests via ww2_files through to lib/WeBWorK/htdocs
112-
my $staticPath = $WeBWorK::Constants::WEBWORK_DIRECTORY."/htdocs/";
113-
$r->any('/webwork2_files/*static' => sub {
114-
my $c = shift;
115-
$c->reply->file($staticPath.$c->stash('static'));
116-
});
114+
# Static file routes
115+
$r->any('/webwork2_files/CAPA_Graphics/*static')->to('StaticFiles#CAPA_graphics_file');
116+
$r->any('/webwork2_files/tmp/*static')->to('StaticFiles#temp_file');
117+
$r->any('/pg_files/*static')->to('StaticFiles#pg_file');
117118

118119
# any other requests fall through
119120
$r->any('/*fail' => sub {

lib/RenderApp/Controller/FormatRenderedProblem.pm

+34-29
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ FormatRenderedProblem.pm
2424

2525
package RenderApp::Controller::FormatRenderedProblem;
2626

27+
use warnings;
28+
use strict;
29+
2730
use lib "$WeBWorK::Constants::WEBWORK_DIRECTORY/lib";
2831
use lib "$WeBWorK::Constants::PG_DIRECTORY/lib";
2932
use MIME::Base64 qw( encode_base64 decode_base64);
3033
use WeBWorK::Utils::AttemptsTable; #import from ww2
3134
use WeBWorK::PG::ImageGenerator; # import from ww2
3235
use WeBWorK::Utils::LanguageAndDirection;
33-
use WeBWorK::Utils qw( wwRound); # required for score summary
36+
use WeBWorK::Utils qw(wwRound getAssetURL); # required for score summary
3437
use WeBWorK::Localize ; # for maketext
3538
our $UNIT_TESTS_ON = 0;
3639

@@ -46,7 +49,7 @@ sub format_hash_ref {
4649
sub new {
4750
my $invocant = shift;
4851
my $class = ref $invocant || $invocant;
49-
$self = { # Is this function redundant given the declarations within sub formatRenderedProblem?
52+
my $self = { # Is this function redundant given the declarations within sub formatRenderedProblem?
5053
return_object => {},
5154
encoded_source => {},
5255
sourceFilePath => '',
@@ -199,7 +202,7 @@ sub formatRenderedProblem {
199202
answersSubmitted => $self->{inputs_ref}{answersSubmitted}//0,
200203
answerOrder => $answerOrder//[],
201204
displayMode => $self->{inputs_ref}{displayMode},
202-
imgGen => $imgGen,
205+
imgGen => undef, # $imgGen,
203206
ce => '', #used only to build the imgGen
204207
showAnswerNumbers => 0,
205208
showAttemptAnswers => 0,
@@ -242,45 +245,47 @@ sub formatRenderedProblem {
242245

243246
# Add JS files requested by problems via ADD_JS_FILE() in the PG file.
244247
my $extra_js_files = '';
245-
if (ref($rh_result->{flags}{extra_js_files}) eq "ARRAY") {
248+
if (ref($rh_result->{flags}{extra_js_files}) eq 'ARRAY') {
246249
$rh_result->{js} = [];
247250
my %jsFiles;
248-
for (@{$rh_result->{flags}{extra_js_files}}) {
249-
# Avoid duplicates
250-
next if $jsFiles{$_->{file}};
251-
$jsFiles{$_->{file}} = 1;
252-
my $attributes = ref($_->{attributes}) eq "HASH" ? $_->{attributes} : {};
251+
for (@{ $rh_result->{flags}{extra_js_files} }) {
252+
next if $jsFiles{ $_->{file} };
253+
$jsFiles{ $_->{file} } = 1;
254+
my %attributes = ref($_->{attributes}) eq 'HASH' ? %{ $_->{attributes} } : ();
253255
if ($_->{external}) {
254-
push @{$rh_result->{js}}, $_->{file};
255-
$extra_js_files .= CGI::script({ src => $_->{file}, %$attributes}, '');
256-
} elsif (!$_->{external} && -f "$ENV{WEBWORK_ROOT}/htdocs/$_->{file}") {
257-
push @{$rh_result->{js}}, "$webwork_htdocs_url/$_->{file}";
258-
$extra_js_files .= CGI::script({src => "$webwork_htdocs_url/$_->{file}", %$attributes}, '');
256+
push @{ $rh_result->{js} }, $_->{file};
257+
$extra_js_files .= CGI::script({ src => $_->{file}, %attributes }, '');
259258
} else {
260-
$extra_js_files .= "<!-- $_->{file} is not available in htdocs/ on this server -->";
259+
my $url = getAssetURL($self->{inputs_ref}{language} // 'en', $_->{file});
260+
push @{ $rh_result->{js} }, $SITE_URL.$url;
261+
$extra_js_files .= CGI::script({ src => $url, %attributes }, '');
261262
}
262263
}
263264
}
264265

266+
# Add CSS files requested by problems via ADD_CSS_FILE() in the PG file
267+
# or via a setting of $self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}
268+
# (the value should be an anonomous array).
265269
my $extra_css_files = '';
266-
my %cssFiles;
267-
# Avoid duplicates
268-
if (ref($self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}) eq "ARRAY") {
269-
$cssFiles{$_} = 0 for @{$self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}};
270+
my @cssFiles;
271+
if (ref($self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files}) eq 'ARRAY') {
272+
push(@cssFiles, { file => $_, external => 0 }) for @{ $self->{ce}{pg}{specialPGEnvironmentVars}{extra_css_files} };
270273
}
271-
if (ref($rh_result->{flags}{extra_css_files}) eq "ARRAY") {
272-
$cssFiles{$_->{file}} = $_->{external} for @{$rh_result->{flags}{extra_css_files}};
274+
if (ref($rh_result->{flags}{extra_css_files}) eq 'ARRAY') {
275+
push @cssFiles, @{ $rh_result->{flags}{extra_css_files} };
273276
}
277+
my %cssFilesAdded; # Used to avoid duplicates
274278
$rh_result->{css} = [];
275-
for (keys(%cssFiles)) {
276-
if ($cssFiles{$_}) {
277-
push @{$rh_result->{css}}, $_;
278-
$extra_css_files .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$_\" />\n";
279-
} elsif (!$cssFiles{$_} && -f "$ENV{WEBWORK_ROOT}/htdocs/$_") {
280-
push @{$rh_result->{css}}, "$webwork_htdocs_url/$_";
281-
$extra_css_files .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$webwork_htdocs_url/$_\" />\n";
279+
for (@cssFiles) {
280+
next if $cssFilesAdded{ $_->{file} };
281+
$cssFilesAdded{ $_->{file} } = 1;
282+
if ($_->{external}) {
283+
push @{ $rh_result->{css} }, $_->{file};
284+
$extra_css_files .= CGI::Link({ rel => 'stylesheet', href => $_->{file} });
282285
} else {
283-
$extra_css_files .= "<!-- $_ is not available in htdocs/ on this server -->\n";
286+
my $url = getAssetURL($self->{inputs_ref}{language} // 'en', $_->{file});
287+
push @{ $rh_result->{css} }, $SITE_URL.$url;
288+
$extra_css_files .= CGI::Link({ href => $url, rel => 'stylesheet' });
284289
}
285290
}
286291

lib/RenderApp/Controller/Render.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ sub checkOutputs {
237237
}
238238
return
239239
"Output from rendering "
240-
. $outputs_ref->{sourceFilePath}
240+
. ($outputs_ref->{sourceFilePath} // '')
241241
. " contained errors: {"
242242
. join "}, {", @errs . "}";
243243
}
@@ -304,4 +304,4 @@ sub jwtFromRequest {
304304
return $c->render( text => $req_jwt );
305305
}
306306

307-
1;
307+
1;

lib/RenderApp/Controller/RenderProblem.pm

+1-26
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ sub standaloneRenderer {
368368
refreshMath2img => 1,
369369
processAnswers => $processAnswers,
370370
QUIZ_PREFIX => $inputs_ref->{answerPrefix} // '',
371+
useMathQuill => !defined $inputs_ref->{entryAssist} || $inputs_ref->{entryAssist} eq 'MathQuill' ? 1 : 0,
371372

372373
#use_site_prefix => 'http://localhost:3000',
373374
use_opaque_prefix => 0,
@@ -428,8 +429,6 @@ sub standaloneRenderer {
428429
['Problem failed during render - no PGcore received.'];
429430
}
430431

431-
insert_mathquill_responses( $inputs_ref, $pg );
432-
433432
my $out2 = {
434433
text => $pg->{body_text},
435434
header_text => $pg->{head_text},
@@ -523,30 +522,6 @@ sub generateJWTs {
523522
return ($sessionJWT, $answerJWT);
524523
}
525524

526-
# insert_mathquill_responses subroutine
527-
528-
# Add responses to each answer's response group that store the latex form of the students'
529-
# answers and add corresponding hidden input boxes to the page.
530-
531-
sub insert_mathquill_responses {
532-
my ( $form_data, $pg ) = @_;
533-
for my $answerLabel ( keys %{ $pg->{pgcore}{PG_ANSWERS_HASH} } ) {
534-
my $mq_opts = $pg->{pgcore}{PG_ANSWERS_HASH}{$answerLabel}{ans_eval}{rh_ans}{mathQuillOpts} // '';
535-
next if ( $mq_opts =~ /\s*disabled\s*/ );
536-
my $response_obj = $pg->{pgcore}{PG_ANSWERS_HASH}{$answerLabel}->response_obj;
537-
for my $response ( $response_obj->response_labels ) {
538-
next if ( ref( $response_obj->{responses}{$response} ) );
539-
my $name = "MaThQuIlL_$response";
540-
push( @{ $response_obj->{response_order} }, $name );
541-
$response_obj->{responses}{$name} = '';
542-
my $value = defined( $form_data->{$name} ) ? $form_data->{$name} : '';
543-
$pg->{body_text} .= CGI::hidden({
544-
-name => $name, -id => $name, -value => $value, data_mq_opts => "$mq_opts"
545-
});
546-
}
547-
}
548-
}
549-
550525
sub fake_user {
551526
my $user = {
552527
user_id => 'Motoko_Kusanagi',
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package RenderApp::Controller::StaticFiles;
2+
use Mojo::Base 'Mojolicious::Controller', -signatures;
3+
4+
use Mojo::File qw(path);
5+
6+
sub reply_with_file_if_readable ($c, $file) {
7+
if (-r $file) {
8+
return $c->reply->file($file);
9+
} else {
10+
return $c->render(data => 'File not found', status => 404);
11+
}
12+
}
13+
14+
# Route requests for webwork2_files/CAPA_Graphics to render root Contrib/CAPA/CAPA_Graphics
15+
sub CAPA_graphics_file ($c) {
16+
return $c->reply_with_file_if_readable($c->app->home->child('Contrib/CAPA/CAPA_Graphics', $c->stash('static')));
17+
}
18+
19+
# Route requests for webwork2_files to the render root tmp. The
20+
# only requests should be for files in the temporary directory.
21+
# FIXME: Perhaps this directory should be configurable.
22+
sub temp_file ($c) {
23+
$c->reply_with_file_if_readable($c->app->home->child('tmp', $c->stash('static')));
24+
}
25+
26+
# Route request to pg_files to lib/PG/htdocs.
27+
sub pg_file ($c) {
28+
$c->reply_with_file_if_readable(path($WeBWorK::Constants::PG_DIRECTORY, 'htdocs', $c->stash('static')));
29+
}
30+
31+
1;

lib/WeBWorK/VERSION

-4
This file was deleted.

0 commit comments

Comments
 (0)