-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from esantelises/split-module-class-attribute-…
…to-private-and-public Split module classes attribute into public/private
- Loading branch information
Showing
5 changed files
with
131 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
}) |