Skip to content

Commit

Permalink
thread through config variable to JS templates; work on #193
Browse files Browse the repository at this point in the history
  • Loading branch information
kltm committed May 20, 2016
1 parent 12c536b commit da83df1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 79 deletions.
119 changes: 43 additions & 76 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,22 @@ $env_conf{AMIGO_JS_DEV_URL} =
$env_conf{AMIGO_STATIC_URL} . '/staging';

## A place for caching databases.
$env_conf{AMIGO_CACHE_DIR} =
$env_conf{AMIGO_WORKING_PATH} . '/cache';
$env_conf{AMIGO_CACHE_DIR} = $env_conf{AMIGO_WORKING_PATH} . '/cache';
safe_make_dir( $env_conf{AMIGO_CACHE_DIR} );
make_permissive( $env_conf{AMIGO_CACHE_DIR} );

## A place for log files.
$env_conf{AMIGO_LOG_DIR} =
$env_conf{AMIGO_WORKING_PATH} . '/log';
$env_conf{AMIGO_LOG_DIR} = $env_conf{AMIGO_WORKING_PATH} . '/log';
safe_make_dir( $env_conf{AMIGO_LOG_DIR} );
make_permissive( $env_conf{AMIGO_LOG_DIR} );

## Session top-level location.
$env_conf{AMIGO_SESSIONS_ROOT_DIR} =
$env_conf{AMIGO_WORKING_PATH} .'/sessions';
$env_conf{AMIGO_SESSIONS_ROOT_DIR} = $env_conf{AMIGO_WORKING_PATH} .'/sessions';
safe_make_dir( $env_conf{AMIGO_SESSIONS_ROOT_DIR});
make_permissive( $env_conf{AMIGO_SESSIONS_ROOT_DIR});

## A place for scratch files.
$env_conf{AMIGO_SCRATCH_DIR} =
$env_conf{AMIGO_WORKING_PATH} . '/sessions/scratch';
$env_conf{AMIGO_SCRATCH_DIR} = $env_conf{AMIGO_WORKING_PATH}.'/sessions/scratch';
safe_make_dir( $env_conf{AMIGO_SCRATCH_DIR} );
make_permissive( $env_conf{AMIGO_SCRATCH_DIR} );

Expand Down Expand Up @@ -275,18 +271,6 @@ my $golr_data_fname = 'javascript/npm/amigo2-instance-data/lib/data/golr.js';
golr_config_to_meta_js($golr_data_fname, \@yaml_confs);
ll("Created GOlr JavaScript data file: \"$golr_data_fname\".");

###
### Dump the YAML handler config into a representation that we can use
### (amigo.data.dispatch).
###

# ## Slurp all *config.yaml files at this location.
# my $handlers_yaml_path = $env_conf{AMIGO_ROOT} . '/conf/handlers.yaml';
# my $dispatch_data_fname = 'javascript/npm/amigo2-instance-data/lib/data/dispatch.js';
# handlers_yaml_to_dispatch_js($dispatch_data_fname, $handlers_yaml_path);
# ll("Created handlers data file: \"$dispatch_data_fname\".");
# #die "HERE!";

###
### Dump the synthetic environment (a la config.pl), plus some extras,
### into a representation that we can use (amigo.data.server).
Expand All @@ -311,20 +295,21 @@ my $xrefs_url = 'https://raw.githubusercontent.com/geneontology/go-site/master/m
xref_abbs_to_meta_js($xrefs_js_data_fname, $xrefs_url, 'js');
ll("Created GO XRefs JavaScript data file: \"$xrefs_js_data_fname\".");

# ## Dump out the discoverable stats, but only generate the statistics
# ## package if there is already amigo2.js files in the javascript
# ## staging area.
# my $amigo_stats_fname = 'javascript/npm/amigo2-instance-data/lib/data/statistics.js';
# golr_stats_to_js($amigo_stats_fname);
# ll("Created AmiGO JavaScript meta file: \"$amigo_stats_fname\".");
###
### Generate the definitions file from the amigo.yaml configurations.
###

my $amigo_defs_fname = 'javascript/npm/amigo2-instance-data/lib/data/definitions.js';
amigo_defs_to_js($amigo_defs_fname);
ll("Created AmiGO JavaScript definition file: \"$amigo_defs_fname\".");

###
### Copy over the rest of the templates into the live JS directory.
###

## We know that these remaining templates are just blanks (no data
## input from the outside work right now), so just copy them over.
my $remaining_js_templates = ['context.js', 'definitions.js', 'dispatch.js'];
my $remaining_js_templates = ['context.js', 'dispatch.js'];
my $tmpl_src = 'javascript/npm/amigo2-instance-data/generation-templates/';
my $tmpl_dst = 'javascript/npm/amigo2-instance-data/lib/data/';
foreach my $template (@$remaining_js_templates){
Expand Down Expand Up @@ -751,7 +736,6 @@ sub amigo_env_to_js {

## Bring in necessaries.
use AmiGO::JavaScript;

my $core = AmiGO::JavaScript->new();

## If the file is already there, blow it away.
Expand Down Expand Up @@ -886,54 +870,37 @@ sub amigo_env_to_js {
make_readable($file_str);
}

# ## TODO: This might be better served in the make file.
# ## file: <local_js_tree>/lib/amigo/data/statistics.js
# sub golr_stats_to_js {

# my $file_str = shift || die 'need target file';

# ## Get the static data. If it's not looking right or not there, use
# ## some empty default values.
# my $ann_src_str = `cat ./staging/ann-source.dat` || '[]';
# my $ann_ev_str = `cat ./staging/ann-evidence.dat` || '[]';
# my $ann_overview_str = `cat ./staging/ann-overview.dat` || '[[]]';
# chomp($ann_src_str);
# chomp($ann_ev_str);
# chomp($ann_overview_str);
# $ann_src_str = '[]' if ! $ann_src_str;
# $ann_ev_str = '[]' if ! $ann_ev_str;
# $ann_overview_str = '[[]]' if ! $ann_overview_str;

# # ## Make sure we can get our own libs.
# # use lib getcwd() . '/perl/lib';
# # ## Bring in necessaries.
# # use AmiGO::JavaScript;
# # my $core = AmiGO::JavaScript->new();

# ## If the file is already there, blow it away.
# unlink $file_str if -f $file_str;
# open(FILE, ">$file_str") or die "cannot open $file_str: $!";

# # $core->kvetch('file_str: ' . $file_str);
# # $core->kvetch('core: ' . $core);

# ## Template to string output.
# my $output = '';
# my $tt = Template->new();
# $tt->process('javascript/npm/amigo2-instance-data/generation-templates/statistics.js.tmpl',
# {
# ann_src => $ann_src_str,
# ann_ev => $ann_ev_str,
# ann_overview => $ann_overview_str,
# },
# \$output)
# || die $tt->error;
# print FILE $output;

# ## Close file.
# close(FILE);
# make_readable($file_str);
# }
## file: <local_js_tree>/lib/amigo/data/statistics.js
sub amigo_defs_to_js {

my $file_str = shift || die 'need target file';

## Bring in necessaries.
use AmiGO::JavaScript;
my $core = AmiGO::JavaScript->new();

## If the file is already there, blow it away.
unlink $file_str if -f $file_str;
open(FILE, ">$file_str") or die "cannot open $file_str: $!";

# $core->kvetch('file_str: ' . $file_str);
# $core->kvetch('core: ' . $core);

## Template to string output.
my $output = '';
my $tt = Template->new();
$tt->process('javascript/npm/amigo2-instance-data/generation-templates/definitions.js.tmpl',
{
download_limit => $core->amigo_env('AMIGO_DOWNLOAD_LIMIT'),
},
\$output)
|| die $tt->error;
print FILE $output;

## Close file.
close(FILE);
make_readable($file_str);
}


##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var definitions = {
* Returns:
* integer
*/
download_limit: 10000,
download_limit: [% download_limit %],
};

///
Expand Down
10 changes: 8 additions & 2 deletions javascript/npm/amigo2-instance-data/tests/static.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ describe('explore the structure of definitions', function(){
var a = new amigo();

it('data.definitions', function(){
assert.equal(a.data.definitions.download_limit, 10000,
'10k');
// Well...
assert.isNumber(a.data.definitions.download_limit,
'is a number: ' + a.data.definitions.download_limit);
// Sanity range.
assert.isAbove(a.data.definitions.download_limit, 100,
'is a > number ');
assert.isBelow(a.data.definitions.download_limit, 1000000,
'is a < number');
});
});

Expand Down

0 comments on commit da83df1

Please sign in to comment.