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

Make combinerMJlist more configurable #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
63 changes: 46 additions & 17 deletions combiner/combineMJlist
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,60 @@
# Combine scripts in the MathJax project into single-file-load
# configuration files.
#
# Usage: ./combineMJlist proj-dir [files.lis]
# Usage: ./combineMJlist proj-dir lis-file [out-dir]
#
# proj-dir is the base directory of the MathJax project
# lis-file is the name of the .lis file that contains information about
# how to create this combined config file
# out-dir is optional, and gives the directory to which to write the
# final output file. It defaults to the 'config' directory inside
# the MathJax project.

use Cwd;
use FindBin;

$DIR = $FindBin::Bin;
$MJX = shift || getcwd;
$MJX = $ARGV[0];

my $name = $ARGV[1];
my $listfile = $name;
$name =~ s!.*/!!;
die "Usage: ./combineMJlist proj-dir lis-file [out-dir]\n" unless $name =~ m/\S/;

$name = $ARGV[0]; $name =~ s!.*/!!;
die "Usage: ./combineMJlist srcdir files.lis\n" unless $name =~ m/\S/;
die "Project directory must contain a config directory\n" unless -d "$MJX/config";

$outfile = "config/$name"; $outfile =~ s/\.[^.]*/.js/;
my $outdir = $MJX;
my $outfile = "config/$name";
$outfile =~ s/\.[^.]*/.js/;

# If the user supplied an output directory, then use that, and strip off
# the 'config/' prefix from $outfile
if ($ARGV[2]) {
$outdir = $ARGV[2];
$outfile =~ s/^config\///;
}

my $template = "$DIR/template.js";


$load_complete_path = "[MathJax]/$outfile";


open(my $LIST_FILE, "<", $listfile) or die "Can't open $listfile for reading";
@files = ();
while ($file = <>) {
chomp($file);
if ($file =~ m/\S/) {
push (@files,$file);
} else {
@config = <>;
chomp(@config);
last;
}
while ($file = <$LIST_FILE>) {
chomp($file);
if ($file =~ s/^LOAD-COMPLETE-PATH:\s*//) {
$load_complete_path = $file;
}
elsif ($file =~ m/\S/) {
push (@files,$file);
}
else {
@config = <$LIST_FILE>;
chomp(@config);
last;
}
}

$MMLorHTML = 0;
Expand All @@ -41,7 +70,7 @@ foreach $file (@files) {
$files = ' "'.join("\",\n \"",@list).'"';
$MMLorHTML = ("","\nMathJax.Hub.Config({delayJaxRegistration: true});\n")[$MMLorHTML];

open(CONFIG,"<","$DIR/template.js") || die "Can't open $DIR/template.js: $!\n";
open(CONFIG,"<","$template") || die "Can't open $template: $!\n";
@lines = <CONFIG>;
close(CONFIG);
$config = join("",@lines);
Expand All @@ -51,7 +80,7 @@ $config =~ s!%%% FILES %%%!$files!;
$config =~ s!%%% MMLorHTML %%%!$MMLorHTML!;

print "Creating $outfile\n";
open(CONFIG,">","$MJX/$outfile") || die "Can't write $MJX/$outfile: $!\n";
open(CONFIG,">","$outdir/$outfile") || die "Can't write $outdir/$outfile: $!\n";
print CONFIG $config;

if (scalar(@config)) {
Expand All @@ -70,7 +99,7 @@ foreach $file (@files) {
print CONFIG $lines;
}

print CONFIG "MathJax.Ajax.loadComplete(\"[MathJax]/$outfile\");\n";
print CONFIG "MathJax.Ajax.loadComplete(\"$load_complete_path\");\n";

close(CONFIG);

Expand Down