<commit_before>'use strict';

var app = require('../../util/app');
var service = require('../../service');
var _ = require('lodash');
var debug = require('debug')('liveblog');


/**
 * A fragment containing all the figures used on the liveblog.
 */
function* liveblogFragment(next) {
  var data = _.zipObject(['stateOfPlay', 'votesVsSeats', 'seatResult'], yield Promise.all([
    service.stateOfPlay(5),
    service.votesVsSeats(),
    service.seatResult(),
  ]));

  console.log('data', data.seatResult);

  debug(JSON.stringify(data.votesVsSeats, null, 2));

  this.set('Cache-Control', // jshint ignore:line
    'public, max-age=10, stale-while-revalidate=3600, stale-if-error=3600');

  this.set('Surrogate-Control', 'max-age=60'); // jshint ignore:line

  yield this.render('liveblog-fragment', data); // jshint ignore:line

  yield next;
}


/**
 * A fragment containing only the figure used on the FT.com homepage (i.e. a modified 'state of play').
 */
function* ftcomFragment(next) {
  var data = {
    stateOfPlay: yield service.stateOfPlay(6)
  };

  // alter the template data to suit the homepage
  data.stateOfPlay.headline = 'UK GENERAL ELECTION';
  data.stateOfPlay.showRosette = true;
  var longerNames = {
    'Lab': 'Labour',
    'LD': 'Lib Dems',
    'Con': 'Conservatives'
  };
  data.stateOfPlay.parties.forEach(function (party) {
    party.label = longerNames[party.label] || party.label;
  });

  data.stateOfPlay.linkText = 'Election Live Blog »';
  data.stateOfPlay.linkURL = 'http://training.blogs.ft.com/westminster/liveblogs/2015-04-22-2/';

  debug(JSON.stringify(data.votesVsSeats, null, 2));

  this.set('Cache-Control', // jshint ignore:line
    'public, max-age=10, stale-while-revalidate=3600, stale-if-error=3600');

  this.set('Surrogate-Control', 'max-age=60'); // jshint ignore:line

  yield this.render('ftcom-fragment', data); // jshint ignore:line

  yield next;
}


/**
 * A mockup page that imitates the real liveblog, for testing components in situ.
 */
function* liveblogMockup(next) {
  yield this.render('liveblog-mockup'); // jshint ignore:line
  yield next;
}


/**
 * A mockup page that imitates the real FT.com homepage, for testing components in situ.
 */
function* ftcomMockup(next) {
  yield this.render('ftcom-mockup'); // jshint ignore:line
  yield next;
}




/**
 * A fragment for a single constituency result
 */
function* seatResultFragment(next) {
  this.set('Cache-Control', // jshint ignore:line
    'public, max-age=10, stale-while-revalidate=3600, stale-if-error=3600');

  this.set('Surrogate-Control', 'max-age=60'); // jshint ignore:line

  var seat = service.db.seats().findOne({id: this.params.seat});
  this.assert(seat, 404, 'Seat not found'); // jshint ignore:line

  yield this.render('seat-result-fragment', seat); // jshint ignore:line
  ;

  yield next;
}


module.exports = function main() {
  return app()
        .router()
        .get('liveblog-mockup', '/liveblog-mockup', liveblogMockup) // mockup page for testing functionality
        .get('liveblog-fragment', '/liveblog-fragment', liveblogFragment) // a fragment of all the widget fragments

        .get('ftcom-mockup', '/ftcom-mockup', ftcomMockup) // mockup page for testing functionality
        .get('ftcom-fragment', '/ftcom-fragment', ftcomFragment) // a fragment of all the widget fragments

        .get('ftcom-fragment', '/seat-result-fragment/:seat', seatResultFragment);
};
<commit_msg>use env vars to set ft.com homepage link text and url<commit_after>'use strict';

var app = require('../../util/app');
var service = require('../../service');
var _ = require('lodash');
var debug = require('debug')('liveblog');


/**
 * A fragment containing all the figures used on the liveblog.
 */
function* liveblogFragment(next) {
  var data = _.zipObject(['stateOfPlay', 'votesVsSeats', 'seatResult'], yield Promise.all([
    service.stateOfPlay(5),
    service.votesVsSeats(),
    service.seatResult(),
  ]));

  console.log('data', data.seatResult);

  debug(JSON.stringify(data.votesVsSeats, null, 2));

  this.set('Cache-Control', // jshint ignore:line
    'public, max-age=10, stale-while-revalidate=3600, stale-if-error=3600');

  this.set('Surrogate-Control', 'max-age=60'); // jshint ignore:line

  yield this.render('liveblog-fragment', data); // jshint ignore:line

  yield next;
}


/**
 * A fragment containing only the figure used on the FT.com homepage (i.e. a modified 'state of play').
 */
function* ftcomFragment(next) {
  var data = {
    stateOfPlay: yield service.stateOfPlay(6)
  };

  // alter the template data to suit the homepage
  data.stateOfPlay.headline = 'UK GENERAL ELECTION';
  data.stateOfPlay.showRosette = true;
  var longerNames = {
    'Lab': 'Labour',
    'LD': 'Lib Dems',
    'Con': 'Conservatives'
  };
  data.stateOfPlay.parties.forEach(function (party) {
    party.label = longerNames[party.label] || party.label;
  });

  data.stateOfPlay.linkText = process.env.FTCOM_HOMEPAGE_LINK_TEXT;
  data.stateOfPlay.linkURL = process.env.FTCOM_HOMEPAGE_LINK_URL;

  debug(JSON.stringify(data.votesVsSeats, null, 2));

  this.set('Cache-Control', // jshint ignore:line
    'public, max-age=10, stale-while-revalidate=3600, stale-if-error=3600');

  this.set('Surrogate-Control', 'max-age=60'); // jshint ignore:line

  yield this.render('ftcom-fragment', data); // jshint ignore:line

  yield next;
}


/**
 * A mockup page that imitates the real liveblog, for testing components in situ.
 */
function* liveblogMockup(next) {
  yield this.render('liveblog-mockup'); // jshint ignore:line
  yield next;
}


/**
 * A mockup page that imitates the real FT.com homepage, for testing components in situ.
 */
function* ftcomMockup(next) {
  yield this.render('ftcom-mockup'); // jshint ignore:line
  yield next;
}




/**
 * A fragment for a single constituency result
 */
function* seatResultFragment(next) {
  this.set('Cache-Control', // jshint ignore:line
    'public, max-age=10, stale-while-revalidate=3600, stale-if-error=3600');

  this.set('Surrogate-Control', 'max-age=60'); // jshint ignore:line

  var seat = service.db.seats().findOne({id: this.params.seat});
  this.assert(seat, 404, 'Seat not found'); // jshint ignore:line

  yield this.render('seat-result-fragment', seat); // jshint ignore:line
  ;

  yield next;
}


module.exports = function main() {
  return app()
        .router()
        .get('liveblog-mockup', '/liveblog-mockup', liveblogMockup) // mockup page for testing functionality
        .get('liveblog-fragment', '/liveblog-fragment', liveblogFragment) // a fragment of all the widget fragments

        .get('ftcom-mockup', '/ftcom-mockup', ftcomMockup) // mockup page for testing functionality
        .get('ftcom-fragment', '/ftcom-fragment', ftcomFragment) // a fragment of all the widget fragments

        .get('ftcom-fragment', '/seat-result-fragment/:seat', seatResultFragment);
};

{'fraction_non_alphanumeric': 0.1568257652691136, 'fraction_numerical': 0.013782097780356883, 'mean_word_length': 3.8243526941917425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '804712', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2215, 'n_words': 535}