Skip to content

Commit

Permalink
Merge pull request #23 from esantelises/split-module-class-attribute-…
Browse files Browse the repository at this point in the history
…to-private-and-public

Split module classes attribute into public/private
  • Loading branch information
toddjordan authored Mar 14, 2017
2 parents d076542 + cbe3d42 commit 2a3e451
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 62 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions lib/add-sub-modules-parent.js

This file was deleted.

34 changes: 34 additions & 0 deletions lib/modules-transform.js
Original file line number Diff line number Diff line change
@@ -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)
}
41 changes: 0 additions & 41 deletions test/add-sub-modules-parent-test.js

This file was deleted.

94 changes: 94 additions & 0 deletions test/modules-transform-test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})

0 comments on commit 2a3e451

Please sign in to comment.