mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Load deserializers from files specified in package.json
This commit is contained in:
parent
6bc35f96df
commit
ade1ef7a4c
7
spec/fixtures/packages/package-with-deserializers/package.json
vendored
Normal file
7
spec/fixtures/packages/package-with-deserializers/package.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "package-with-deserializers",
|
||||
"version": "1.0.0",
|
||||
"atom-deserializers": {
|
||||
"TheDeserializerName": "./the-deserializer.js"
|
||||
}
|
||||
}
|
6
spec/fixtures/packages/package-with-deserializers/the-deserializer.js
vendored
Normal file
6
spec/fixtures/packages/package-with-deserializers/the-deserializer.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = function (state) {
|
||||
return {
|
||||
wasDeserializedBy: 'TheDeserializer',
|
||||
state: state
|
||||
}
|
||||
}
|
@ -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", ->
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user