mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
WIP: Start on Package
class w/ TextMate- & Atom-specific subclasses
The `load` method on the superclass will provide a general template for loading the package's resource. Each subclass will be responsible for loading resources in a manner appropriate for the package type. There's some initial progress on loading TextMate settings as scoped properties, translating the TextMate scope selectors to CSS-style atom selectors.
This commit is contained in:
parent
515feca7a6
commit
a1d28a9f74
17
src/app/atom-package.coffee
Normal file
17
src/app/atom-package.coffee
Normal file
@ -0,0 +1,17 @@
|
||||
Package = require 'package'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class AtomPackage extends Package
|
||||
constructor: ->
|
||||
super
|
||||
@module = require(@path)
|
||||
@module.name = @name
|
||||
|
||||
load: ->
|
||||
try
|
||||
rootView.activatePackage(@module)
|
||||
extensionKeymapPath = require.resolve(fs.join(@name, "src/keymap"), verifyExistence: false)
|
||||
require extensionKeymapPath if fs.exists(extensionKeymapPath)
|
||||
catch e
|
||||
console.error "Failed to load package named '#{name}'", e.stack
|
@ -1,6 +1,8 @@
|
||||
TextMateBundle = require("text-mate-bundle")
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore'
|
||||
Package = require 'package'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
|
||||
messageIdCounter = 1
|
||||
originalSendMessageToBrowserProcess = atom.sendMessageToBrowserProcess
|
||||
@ -18,7 +20,7 @@ _.extend atom,
|
||||
_.unique(allPackageNames)
|
||||
|
||||
getAvailableTextMateBundles: ->
|
||||
@getAvailablePackages().filter (packageName) => @isTextMateBundle(packageName)
|
||||
@getAvailablePackages().filter (packageName) => TextMatePackage.testName(packageName)
|
||||
|
||||
loadPackages: (packageNames=@getAvailablePackages()) ->
|
||||
disabledPackages = config.get("core.disabledPackages") ? []
|
||||
@ -26,20 +28,7 @@ _.extend atom,
|
||||
@loadPackage(packageName) unless _.contains(disabledPackages, packageName)
|
||||
|
||||
loadPackage: (name) ->
|
||||
try
|
||||
if @isTextMateBundle(name)
|
||||
TextMateBundle.load(name)
|
||||
else
|
||||
packagePath = require.resolve(name, verifyExistence: false)
|
||||
throw new Error("No package found named '#{name}'") unless packagePath
|
||||
packagePath = fs.directory(packagePath)
|
||||
packageModule = require(packagePath)
|
||||
packageModule.name = name
|
||||
rootView.activatePackage(packageModule)
|
||||
extensionKeymapPath = require.resolve(fs.join(name, "src/keymap"), verifyExistence: false)
|
||||
require extensionKeymapPath if fs.exists(extensionKeymapPath)
|
||||
catch e
|
||||
console.error "Failed to load package named '#{name}'", e.stack
|
||||
Package.forName(name).load()
|
||||
|
||||
open: (args...) ->
|
||||
@sendMessageToBrowserProcess('open', args)
|
||||
@ -104,6 +93,3 @@ _.extend atom,
|
||||
if name is 'reply'
|
||||
[messageId, callbackIndex] = data.shift()
|
||||
@pendingBrowserProcessCallbacks[messageId]?[callbackIndex]?(data...)
|
||||
|
||||
isTextMateBundle: (packageName) ->
|
||||
/(\.|_|-)tmbundle$/.test(packageName)
|
||||
|
21
src/app/package.coffee
Normal file
21
src/app/package.coffee
Normal file
@ -0,0 +1,21 @@
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class Package
|
||||
@forName: (name) ->
|
||||
AtomPackage = require 'atom-package'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
|
||||
if TextMatePackage.testName(name)
|
||||
new TextMatePackage(name)
|
||||
else
|
||||
new AtomPackage(name)
|
||||
|
||||
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)
|
||||
|
||||
load: ->
|
||||
# WIP: Going to load scoped properties into `syntax` global here
|
||||
@getScopedProperties()
|
40
src/app/text-mate-package.coffee
Normal file
40
src/app/text-mate-package.coffee
Normal file
@ -0,0 +1,40 @@
|
||||
Package = require 'package'
|
||||
TextMateBundle = require 'text-mate-bundle'
|
||||
fs = require 'fs'
|
||||
plist = require 'plist'
|
||||
|
||||
module.exports =
|
||||
class TextMatePackage extends Package
|
||||
@testName: (packageName) ->
|
||||
/(\.|_|-)tmbundle$/.test(packageName)
|
||||
|
||||
@translateScopeSelector: (scopeSelector) ->
|
||||
scopeSelector.split(', ').map((commaFragment) ->
|
||||
commaFragment.split(' ').map((spaceFragment) ->
|
||||
spaceFragment.split('.').map((dotFragment) ->
|
||||
'.' + dotFragment
|
||||
).join('')
|
||||
).join(' ')
|
||||
).join(', ')
|
||||
|
||||
load: ->
|
||||
TextMateBundle.load(@name)
|
||||
super
|
||||
|
||||
constructor: ->
|
||||
super
|
||||
@preferencesPath = fs.join(@path, "Preferences")
|
||||
@syntaxesPath = fs.join(@path, "Syntaxes")
|
||||
|
||||
getScopedProperties: ->
|
||||
scopedProperties = []
|
||||
if fs.exists(@preferencesPath)
|
||||
for preferencePath in fs.list(@preferencesPath)
|
||||
plist.parseString fs.read(preferencePath), (e, data) ->
|
||||
if e
|
||||
console.warn "Failed to parse preference at path '#{preferencePath}'", e.stack
|
||||
else
|
||||
{ scope, settings } = data[0]
|
||||
selector = TextMatePackage.translateScopeSelector(scope)
|
||||
scopedProperties.push({selector: selector, properties: settings})
|
||||
scopedProperties
|
Loading…
Reference in New Issue
Block a user