var taxonHelpers = require('../helpers/taxon-helpers.js');
var filterHelpers = require('../helpers/filter-helpers.js');

function TaxonPresenter (taxonSlug, request) {
  this.taxonSlug = taxonSlug; // the slug of the taxon in the Content Store
  this.selectedTab = request.query.tab;
  if (this.selectedTab == undefined) { this.selectedTab = 'guidance' }; //default view
  this.pageTitle = taxonHelpers.fetchCurrentTaxonTitle(this.taxonSlug);

  // Fetch appropriate taxonomy data
  this.childTaxons = taxonHelpers.fetchChildTaxons(this.taxonSlug);
  this.parentTaxon = taxonHelpers.fetchParentTaxon(this.taxonSlug);
  this.allContent  = taxonHelpers.fetchTaggedItems(this.taxonSlug);

  this.determineContentList = function () {
    switch (this.selectedTab) {
      case 'all':
        return this.allContent; break;
      default:
        return filterHelpers.sectionFilter(this.allContent, this.selectedTab);
    }
  };
  this.contentListToRender = this.determineContentList();

  this.curatedContent = this.contentListToRender.slice(0,6);
  this.latestContent  = this.contentListToRender.slice(0,3);
}

module.exports = TaxonPresenter;

var taxonHelpers = require('../helpers/taxon-helpers.js');
var filterHelpers = require('../helpers/filter-helpers.js');

function TaxonPresenter (taxonSlug, request) {
  this.taxonSlug = taxonSlug; // the slug of the taxon in the Content Store
  this.selectedTab = request.query.tab;
  if (this.selectedTab == undefined) { this.selectedTab = 'guidance' }; //default view
  this.pageTitle = taxonHelpers.fetchCurrentTaxonTitle(this.taxonSlug);

  // Fetch appropriate taxonomy data
  this.childTaxons = taxonHelpers.fetchChildTaxons(this.taxonSlug);
  this.parentTaxon = taxonHelpers.fetchParentTaxon(this.taxonSlug);
  this.allContent  = taxonHelpers.fetchTaggedItems(this.taxonSlug);

  this.determineContentList = function () {
    switch (this.selectedTab) {
      case 'all':
        return this.allContent; break;
      default:
        return filterHelpers.sectionFilter(this.allContent, this.selectedTab);
    }
  };
  this.contentListToRender = this.determineContentList();

  this.curatedContent = this.contentListToRender.slice(0,6);
  this.latestContent  = this.contentListToRender.slice(0,3);

  this.resolveViewTemplateName = function () {
    return request.path.replace(this.taxonSlug, '').replace(/^\//, '') + this.selectedTab;
  };
  this.viewTemplateName = this.resolveViewTemplateName();
}

module.exports = TaxonPresenter;

Add function to TaxonPresenter to resolve view template path from request
Add function to TaxonPresenter to resolve view template path from request

Still uses the selected tab for the template name, but now looks for the
template in a directory names after the base path.

e.g. - '/taxons/:taxonSlug' will render templates from 'app/views/taxons'
