codo
Version:
A CoffeeScript documentation generator.
130 lines (99 loc) • 3.86 kB
text/coffeescript
Entity = require '../entity'
Method = require './method'
Variable = require './variable'
MetaMethod = require '../meta/method'
Entities = require '../_entities'
Winston = require 'winston'
module.exports = class Entities.Mixin extends Entity
: "Mixin"
: (node) ->
node.constructor.name == 'Assign' && node.value?.base?.properties?
: (node) ->
node.documentation?.mixin && super(node)
: (node) ->
node.constructor.name == 'Assign' &&
node.value?.constructor.name == 'Value' &&
(
node.variable.base.value == 'ClassMethods' ||
node.variable.base.value == 'InstanceMethods'
)
constructor: (, , ) ->
[, ] =
= .documentation
= []
= []
= []
= []
= []
for property in .value.base.properties
# Recognize assigned code on the mixin
= true if .isConcernSection(property)
if
= []
= []
name = .split('.')
= name.pop()
= ?.namespace or name.join('.')
if .options.debug
Winston.info "Creating new Mixin Entity"
Winston.info " name: " +
Winston.info " documentation: " +
linkify: ->
super
,
if
for property in .value.base.properties
# Recognize concerns as inner mixins
if property.value?.constructor.name is 'Value'
switch property.variable.base.value
when 'ClassMethods'
, property
when 'InstanceMethods'
, property
grabMethods: (container, node) ->
for property in node.value.base.properties
if property.entities?
for entity in property.entities
# Foo =
# foo: ->
container.push entity if entity instanceof Method
aggregateEffectiveMethods: (kind) ->
methods = []
overrides = {}
overrides.kind = kind if kind?
for method in
methods.push(MetaMethod.fromMethodEntity method, overrides)
if .methods
for method in .methods
methods.push(MetaMethod.fromDocumentationMethod method, overrides)
methods
effectiveMethods: ->
return if
||=
effectiveInclusionMethods: ->
||=
effectiveExtensionMethods: ->
||=
effectiveConcernMethods: ->
return if ?
= []
for method in
.push(MetaMethod.fromMethodEntity method, kind: 'static')
for method in
.push(MetaMethod.fromMethodEntity method, kind: 'dynamic')
if .methods
for method in .methods
.push(MetaMethod.fromDocumentationMethod method)
inspect: ->
{
file: .path
name:
concern:
documentation: ?.inspect()
selfish:
methods: .map (x) -> x.inspect()
classMethods: ?.map (x) -> x.inspect()
instanceMethods: ?.map (x) -> x.inspect()
variables: .map (x) -> x.inspect()
}