Pattern Library Utilities

path

declaration
path

@fileOverview
Determines the category path structure

@author Scott Nath

var path = require('path');
var utility = require('./utility');

getCategoryPath

method
exports.getCategoryPath()

@param Type Description
patternObject Object individual pattern's data (from /pattern-name/pattern.yml)
options Object pattern-importer options

Determines the category directory structure from the pattern's data

exports.getCategoryPath = function (patternObject, options) {
  'use strict';

  var categoryObject = '';

  // grab the conversion data object
  if (options.convertCategoryTitles && options.convertCategoryTitlesData) {
    categoryObject = options.convertCategoryTitlesData;
  }

  // make sure we're dealing with an object
  patternObject = patternObject || {};

  // return the uncategorized directory name if no category in the pattern's object
  if (!patternObject.category) {
    return options.uncategorizedDir;
  }

  // check if we have a categoryObject
  if (categoryObject) {
    return categoryPathConverted(categoryObject, patternObject);
  }
  else {
    return categoryPathPlain(patternObject);
  }

};

categoryPathPlain

function
categoryPathPlain()

@param Type Description
patternObject Object individual pattern's data (from /pattern-name/pattern.yml)

Determines the category directory structure without any conversion

function categoryPathPlain(patternObject) {
  'use strict';

  // check for subcategory
  if (patternObject.subcategory) {
    return path.join(patternObject.category, patternObject.subcategory);
  }
  else {
    return patternObject.category;
  }
}

categoryPathConverted

function
categoryPathConverted()

@param Type Description
categoryObject Object object of category names and their conversion titles
patternObject Object individual pattern's data (from /pattern-name/pattern.yml)

Determines the category directory structure by converting names according to a category object

function categoryPathConverted(categoryObject, patternObject) {
  'use strict';

  // convert our category path using the categoryObject
  var categoryPath = utility.categoryNameConverter(categoryObject.categories, patternObject.category);

  // check for subcategory
  if (patternObject.subcategory) {
    var subcategoryPath = utility.categoryNameConverter(categoryObject.subcategories[categoryPath], patternObject.subcategory);
    return path.join(categoryPath, subcategoryPath);
  }
  else {
    return categoryPath;
  }
}