Allow scoped-properties to be added/removed by name

Also:
  - remove "global" properties
  - clear scoped properties between specs
This commit is contained in:
Corey Johnson & Nathan Sobo
2013-03-26 12:45:19 -06:00
committed by Nathan Sobo
parent 368e10a9f5
commit c8ec73d2f0
3 changed files with 29 additions and 15 deletions

View File

@@ -22,7 +22,6 @@ class Syntax
@grammarsByFileType = {}
@grammarsByScopeName = {}
@grammarOverridesByPath = {}
@globalProperties = {}
@scopedPropertiesIndex = 0
@scopedProperties = []
@nullGrammar = new NullGrammar
@@ -101,18 +100,24 @@ class Syntax
@grammarsByScopeName[scopeName]
addProperties: (args...) ->
selector = args.shift() if args.length > 1
properties = args.shift()
name = args.shift() if args.length > 2
[selector, properties] = args
if selector
@scopedProperties.unshift(
selector: selector,
properties: properties,
specificity: Specificity(selector),
index: @scopedPropertiesIndex++
)
else
_.extend(@globalProperties, properties)
@scopedProperties.unshift(
name: name
selector: selector,
properties: properties,
specificity: Specificity(selector),
index: @scopedPropertiesIndex++
)
removeProperties: (name) ->
for properties in @scopedProperties.filter((properties) -> properties.name is name)
_.remove(@scopedProperties, properties)
clearProperties: ->
@scopedProperties = []
@scopedPropertiesIndex = 0
getProperty: (scope, keyPath) ->
for object in @propertiesForScope(scope, keyPath)
@@ -128,7 +133,7 @@ class Syntax
while element
matchingProperties.push(@matchingPropertiesForElement(element, candidates)...)
element = element.parentNode
matchingProperties.concat([@globalProperties])
matchingProperties
matchingPropertiesForElement: (element, candidates) ->
matchingScopedProperties = candidates.filter ({selector}) ->