From d02f59e6cf2251c58e4296a53352d0d4ffdb1a7c Mon Sep 17 00:00:00 2001 From: Boris Staal Date: Sun, 10 Nov 2013 13:07:00 +0700 Subject: [PATCH] Links to inherited entries made more straightforward --- lib/entities/class.coffee | 41 ++++++++++++++++++++++------ package.json | 2 +- spec/lib/entities/class_spec.coffee | 9 ++++-- themes/default/lib/theme.coffee | 1 + themes/default/templates/class.hamlc | 6 ++-- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/entities/class.coffee b/lib/entities/class.coffee index e28a31e..2e54bf6 100644 --- a/lib/entities/class.coffee +++ b/lib/entities/class.coffee @@ -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 @@ -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: -> { diff --git a/package.json b/package.json index fa5ff7b..47b4954 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "name": "Boris Staal" } ], - "version": "2.0.0-rc.3", + "version": "2.0.0-rc.4", "licenses": [ { "type": "MIT", diff --git a/spec/lib/entities/class_spec.coffee b/spec/lib/entities/class_spec.coffee index 9799b14..d059639 100644 --- a/spec/lib/entities/class_spec.coffee +++ b/spec/lib/entities/class_spec.coffee @@ -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( [ diff --git a/themes/default/lib/theme.coffee b/themes/default/lib/theme.coffee index 1e66a0b..8845987 100644 --- a/themes/default/lib/theme.coffee +++ b/themes/default/lib/theme.coffee @@ -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' diff --git a/themes/default/templates/class.hamlc b/themes/default/templates/class.hamlc index 8cb3773..56394a3 100644 --- a/themes/default/templates/class.hamlc +++ b/themes/default/templates/class.hamlc @@ -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 @@ -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' @@ -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