When loading a package, honor the 'keymaps' manifest in package.json

Also, add a spec to cover the loading of keymaps in `atom-spec` and
reset the `keymap`'s internal data after each spec gets run to prevent
test pollution with keymaps.
This commit is contained in:
Nathan Sobo
2013-01-03 15:10:11 -07:00
parent 6442a4ba9f
commit a9bb4ea163
11 changed files with 104 additions and 16 deletions

View File

@@ -3,29 +3,42 @@ fs = require 'fs'
module.exports =
class AtomPackage extends Package
metadata: null
keymapsDirPath: null
constructor: (@name) ->
super
@module = require(@path)
@module.name = @name
@keymapsDirPath = fs.join(@path, 'keymaps')
if @requireModule
@module = require(@path)
@module.name = @name
load: ->
try
@loadMetadata()
@loadKeymaps()
@loadStylesheets()
rootView.activatePackage(@module)
rootView.activatePackage(@module) if @module
catch e
console.error "Failed to load package named '#{@name}'", e.stack
loadMetadata: ->
if metadataPath = fs.resolveExtension(fs.join(@path, "package"), ['cson', 'json'])
@metadata = fs.readObject(metadataPath)
loadKeymaps: ->
for keymapPath in @getKeymapPaths()
keymap.load(keymapPath)
getKeymapPaths: ->
keymapsDirPath = fs.join(@path, 'keymaps')
if fs.exists keymapsDirPath
fs.list keymapsDirPath
if keymaps = @metadata?.keymaps
keymaps.map (relativePath) =>
fs.resolve(@keymapsDirPath, relativePath, ['cson', 'json', ''])
else
[]
if fs.exists(@keymapsDirPath)
fs.list(@keymapsDirPath)
else
[]
loadStylesheets: ->
for stylesheetPath in @getStylesheetPaths()

View File

@@ -11,10 +11,21 @@ class Package
else
new AtomPackage(name).load()
name: null
path: null
requireModule: null
module: null
constructor: (@name) ->
@path = require.resolve(@name, verifyExistence: false)
throw new Error("No package found named '#{@name}'") unless @path
@path = fs.directory(@path) unless fs.isDirectory(@path)
if fs.isDirectory(@path)
@requireModule = false
else
@requireModule = true
@path = fs.directory(@path)
load: ->
for grammar in @getGrammars()