Load deserializers from files specified in package.json

This commit is contained in:
Max Brunsfeld 2015-11-18 13:59:17 -08:00
parent 6bc35f96df
commit ade1ef7a4c
4 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,7 @@
{
"name": "package-with-deserializers",
"version": "1.0.0",
"atom-deserializers": {
"TheDeserializerName": "./the-deserializer.js"
}
}

View File

@ -0,0 +1,6 @@
module.exports = function (state) {
return {
wasDeserializedBy: 'TheDeserializer',
state: state
}
}

View File

@ -79,6 +79,16 @@ describe "PackageManager", ->
expect(loadedPackage.name).toBe "package-with-main"
it "registers any deserializers specified in the package's package.json", ->
atom.packages.loadPackage("package-with-deserializers")
state = {deserializer: 'TheDeserializerName', a: 'b'}
expect(atom.deserializers.deserialize(state)).toEqual {
wasDeserializedBy: 'TheDeserializer'
state: state
}
describe "::unloadPackage(name)", ->
describe "when the package is active", ->
it "throws an error", ->

View File

@ -84,6 +84,7 @@ class Package
@loadKeymaps()
@loadMenus()
@loadStylesheets()
@loadDeserializers()
@settingsPromise = @loadSettings()
@requireMainModule() unless @mainModule? or @activationShouldBeDeferred()
catch error
@ -253,6 +254,12 @@ class Package
@stylesheets = @getStylesheetPaths().map (stylesheetPath) =>
[stylesheetPath, @themeManager.loadStylesheet(stylesheetPath, true)]
loadDeserializers: ->
for name, implementationPath of @metadata['atom-deserializers']
deserialize = require(path.join(@path, implementationPath))
atom.deserializers.add({name, deserialize})
return
getStylesheetsPath: ->
path.join(@path, 'styles')