From cbe3d4233d5ae7d9fbd5f323f4794f5de9869ed9 Mon Sep 17 00:00:00 2001 From: esantelises Date: Tue, 14 Mar 2017 10:10:04 -0400 Subject: [PATCH] split module class attribute into public/private classes --- index.js | 6 +- lib/add-sub-modules-parent.js | 18 ------ lib/modules-transform.js | 34 +++++++++++ test/add-sub-modules-parent-test.js | 41 ------------- test/modules-transform-test.js | 94 +++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 62 deletions(-) delete mode 100644 lib/add-sub-modules-parent.js create mode 100644 lib/modules-transform.js delete mode 100644 test/add-sub-modules-parent-test.js create mode 100644 test/modules-transform-test.js diff --git a/index.js b/index.js index 64a21ac..df5055d 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ let fetch = require('./lib/fetch') let readDocs = require('./lib/read-docs') let addSinceTags = require('./lib/add-since-tags') let addInheritedItems = require('./lib/add-inherited-items') -let addSubModulesParent = require('./lib/add-sub-modules-parent') +let transformModules = require('./lib/modules-transform') let putClassesInCouch = require('./lib/classes-in-couch') let createVersionIndex = require('./lib/create-version-index') let normalizeEmberDependencies = require('./lib/normalize-ember-dependencies') @@ -36,8 +36,8 @@ function transformProjectFiles (projectName) { console.log('reading docs for ' + projectName) let promise = RSVP.resolve(readDocs(projectName)) .then((stuff) => { - console.log('adding sub modules parent for ' + projectName) - return addSubModulesParent(stuff) + console.log('transforming modules for ' + projectName) + return transformModules(stuff) }).then((stuff) => { console.log('adding since tags for ' + projectName) return addSinceTags(stuff) diff --git a/lib/add-sub-modules-parent.js b/lib/add-sub-modules-parent.js deleted file mode 100644 index 0f023ea..0000000 --- a/lib/add-sub-modules-parent.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' - -let _ = require('lodash') -let RSVP = require('rsvp') - -module.exports = function addSubModulesParent (docSets) { - docSets.forEach(function (versionData) { - let modules = _.values(versionData.data.modules) - - modules.forEach(function (mod) { - if (mod.is_submodule) { - mod.parent = mod.module - } - }) - }) - - return RSVP.resolve(docSets) -} diff --git a/lib/modules-transform.js b/lib/modules-transform.js new file mode 100644 index 0000000..7f3197e --- /dev/null +++ b/lib/modules-transform.js @@ -0,0 +1,34 @@ +'use strict' + +let _ = require('lodash') +let RSVP = require('rsvp') + +function addSubModulesParentAttribute (moduleObj) { + moduleObj.parent = moduleObj.is_submodule ? moduleObj.module : null +} + +function isPrivate (klass) { + return klass.access === 'private' || klass.deprecated === true +} + +function addPrivatePublicClassesAttributes (module, classes) { + module.publicclasses = [] + module.privateclasses = [] + Object.keys(module.classes).forEach((className) => { + isPrivate(classes[className]) ? module.privateclasses.push(className) : module.publicclasses.push(className) + }) + delete module.classes +} + +module.exports = function transformModules (docSets) { + docSets.forEach(function (versionData) { + let modules = _.values(versionData.data.modules) + let classes = versionData.data.classes + modules.forEach((mod) => { + addSubModulesParentAttribute(mod) + addPrivatePublicClassesAttributes(mod, classes) + }) + }) + + return RSVP.resolve(docSets) +} diff --git a/test/add-sub-modules-parent-test.js b/test/add-sub-modules-parent-test.js deleted file mode 100644 index 3d25574..0000000 --- a/test/add-sub-modules-parent-test.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict' - -let addSubModulesParent = require('../lib/add-sub-modules-parent') -let assert = require('chai').assert -let _ = require('lodash') - -describe('addSubModulesParent', function () { - beforeEach(function () { - this.yuiDocSets = _.range(3).map(i => { - return { - version: 'v1.0.' + i, - data: { - modules: [ - { - is_submodule: 1, - module: 'foo' - }, - { - is_submodule: 1, - module: 'foo' - }, - { - is_submodule: 0, - module: 'bar' - } - ] - } - } - }) - addSubModulesParent(this.yuiDocSets) - }) - - it('adds a parent attribute to sub modules', function () { - this.yuiDocSets.forEach(docSet => { - let subModules = _.filter(docSet.data.modules, (mod) => (mod.is_submodule)) - subModules.forEach((moduleItem) => { - assert.equal(moduleItem.parent, 'foo') - }) - }) - }) -}) diff --git a/test/modules-transform-test.js b/test/modules-transform-test.js new file mode 100644 index 0000000..0129154 --- /dev/null +++ b/test/modules-transform-test.js @@ -0,0 +1,94 @@ +'use strict' + +let transformModules = require('../lib/modules-transform') +let assert = require('chai').assert +let _ = require('lodash') + +describe('transformModules', function () { + beforeEach(function () { + this.yuiDocSets = _.range(3).map(i => { + return { + version: 'v1.0.' + i, + data: { + modules: [ + { + is_submodule: 1, + module: 'foo', + classes: { + 'Testing.class.private-1': 1, + 'Testing.class.public-2': 1, + 'Testing.class.private-3': 1, + 'Testing.class.public-4': 1, + 'Testing.class.deprecated-3': 1 + } + }, + { + is_submodule: 1, + module: 'foo', + classes: { + 'Testing.class.private-1': 1 + } + }, + { + is_submodule: 0, + module: 'bar', + classes: { + 'Testing.class.private-1': 1, + 'Testing.class.public-2': 1 + } + } + ], + classes: { + 'Testing.class.private-1': { + access: 'private', + deprecated: false + }, + 'Testing.class.public-2': { + access: 'public', + deprecated: false + }, + 'Testing.class.private-3': { + access: 'private', + deprecated: false + }, + 'Testing.class.public-4': { + access: 'public', + deprecated: false + }, + 'Testing.class.deprecated-3': { + access: 'public', + deprecated: true + } + } + } + } + }) + transformModules(this.yuiDocSets) + }) + + it('adds a parent attribute to sub modules', function () { + this.yuiDocSets.forEach(docSet => { + let subModules = _.filter(docSet.data.modules, (mod) => (mod.is_submodule)) + subModules.forEach((moduleItem) => { + assert.equal(moduleItem.parent, 'foo') + }) + }) + }) + + it('publicclasses/privateclasses attributes are set correctly', function () { + this.yuiDocSets.forEach(docSet => { + let modules = docSet.data.modules + assert.deepEqual(modules[0].publicclasses, ['Testing.class.public-2', 'Testing.class.public-4']) + assert.deepEqual(modules[0].privateclasses, ['Testing.class.private-1', 'Testing.class.private-3', 'Testing.class.deprecated-3']) + assert.isUndefined(modules[0].classes) + + assert.deepEqual(modules[1].publicclasses, []) + assert.deepEqual(modules[1].privateclasses, ['Testing.class.private-1']) + assert.isUndefined(modules[1].classes) + + assert.deepEqual(modules[2].publicclasses, ['Testing.class.public-2']) + assert.deepEqual(modules[2].privateclasses, ['Testing.class.private-1']) + assert.isUndefined(modules[2].classes) + }) + }) +})