Skip to content

Commit

Permalink
Links to inherited entries made more straightforward
Browse files Browse the repository at this point in the history
  • Loading branch information
inossidabile committed Nov 10, 2013
1 parent 2703b80 commit d02f59e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
41 changes: 33 additions & 8 deletions lib/entities/class.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,23 @@ module.exports = class Entities.Class extends require('../entity')
@_effectiveMethods

allMethods: ->
methods = @effectiveMethods()
methods = methods.concat mixin.effectiveInclusionMethods() for mixin in @includes
methods = methods.concat mixin.effectiveExtensionMethods() for mixin in @extends
methods = methods.concat mixin.effectiveConcernMethods() for mixin in @concerns
methods = @effectiveMethods().map (method) =>
{
entity: method
owner: @
}

resolvers =
includes: 'effectiveInclusionMethods'
extends: 'effectiveExtensionMethods'
concerns: 'effectiveConcernMethods'

for storage, resolver of resolvers
for mixin in @[storage]
for method in mixin[resolver]()
methods.push
entity: method
owner: mixin

methods

Expand All @@ -177,19 +190,31 @@ module.exports = class Entities.Class extends require('../entity')
entries = getter()

entries.filter (entry) ->
found[entry.name] = true unless found[entry.name]
found[entry.entity.name] = true unless found[entry.entity.name]

inheritedMethods: ->
@_inheritedMethods ||= @inherited =>
@parent.allMethods().concat(@parent.inheritedMethods())
@parent.allMethods().concat @parent.inheritedMethods()

inheritedVariables: ->
@_inheritedVariables ||= @inherited =>
@parent.variables.concat(@parent.inheritedVariables())
variables = @parent.variables.map (variable) =>
{
entity: variable
owner: @parent
}

variables.concat @parent.inheritedVariables()

inheritedProperties: ->
@_inheritedProperties ||= @inherited =>
@parent.properties.concat(@parent.inheritedProperties())
properties = @parent.properties.map (property) =>
{
entity: property
owner: @parent
}

properties.concat @parent.inheritedProperties()

inspect: ->
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Boris Staal"
}
],
"version": "2.0.0-rc.3",
"version": "2.0.0-rc.4",
"licenses": [
{
"type": "MIT",
Expand Down
9 changes: 6 additions & 3 deletions spec/lib/entities/class_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ describe 'Class', ->
it 'lists inherited methods', ->

environment = Environment.read('spec/_templates/complicateds/methods.coffee')
methods = environment.entities[12].inheritedMethods().map (x) -> x.inspect()
methods = environment.entities[12].inheritedMethods().map (x) -> x.entity.inspect()

expect(methods).toEqual(
[
{ name: 'x', kind: 'dynamic', bound: false, parameters: [ ] },
{ name: 'z', kind: 'dynamic', bound: false, parameters: [ ] }
{ name: 'z', kind: 'dynamic', bound: false, parameters: [ ] },
{ name: 'm', kind: 'dynamic', bound: false, parameters: [ ] },
{ name: 'cs', kind: 'static', bound: false, parameters: [ ] },
{ name: 'cd', kind: 'dynamic', bound: false, parameters: [ ] }
]
)

it 'lists inherited variables', ->

environment = Environment.read('spec/_templates/complicateds/variables.coffee')
variables = environment.entities[5].inheritedVariables().map (x) -> x.inspect()
variables = environment.entities[5].inheritedVariables().map (x) -> x.entity.inspect()

expect(variables).toEqual(
[
Expand Down
1 change: 1 addition & 0 deletions themes/default/lib/theme.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = class Theme.Theme
kind = 'extra' if entity instanceof Codo.Entities.Extra
kind = 'method' if entity.entity instanceof Codo.Meta.Method
kind = 'variable' if entity.entity instanceof Codo.Entities.Variable
kind = 'property' if entity.entity instanceof Codo.Entities.Property

switch kind
when 'file', 'extra'
Expand Down
6 changes: 3 additions & 3 deletions themes/default/templates/class.hamlc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
%a{href: @pathFor('class', @entity.parent, @path)}= @entity.parent.name
%p.inherited
- for property in @entity.inheritedProperties()
%a{href: "#{@pathFor('class', @entity.parent, @path)}##{@anchorFor(property)}"}= property.name
%a{href: @pathFor(property, undefined, @path)}= property.entity.name


- if @entity.variables.length > 0 || @entity.inheritedVariables().length > 0
Expand All @@ -115,7 +115,7 @@
%a{href: @pathFor('class', @entity.parent, @path)}= @entity.parent.name
%p.inherited
- for variable in @entity.inheritedVariables()
%a{href: "#{@pathFor('class', @entity.parent, @path)}##{@anchorFor(variable)}"}= variable.name
%a{href: @pathFor(variable, undefined, @path)}= variable.entity.name


- staticMethods = @entity.effectiveMethods().filter (m) -> m.kind == 'static'
Expand All @@ -139,7 +139,7 @@
%a{href: @pathFor('class', @entity.parent, @path)}= @entity.parent.name
%p.inherited
- for method in @entity.inheritedMethods()
%a{href: "#{@pathFor 'class', @entity.parent, @path}##{@anchorFor(method)}"}= method.shortSignature()
%a{href: @pathFor(method, undefined, @path)}= method.entity.shortSignature()

- if @entity.extends.length > 0
%h2
Expand Down

0 comments on commit d02f59e

Please sign in to comment.