Rename extensions to packages

We now look at the `core.disabledPackages` config key. Rename the `src/extensions` directory to `src/packages`. The config object now talks about loading packages instead of extensions.
This commit is contained in:
Nathan Sobo
2012-12-18 20:03:21 -07:00
parent 37f0aa3f90
commit 4ce8583cb2
74 changed files with 15 additions and 15 deletions

View File

@@ -0,0 +1 @@
module.exports = require 'wrap-guide/src/wrap-guide'

View File

@@ -0,0 +1,72 @@
$ = require 'jquery'
RootView = require 'root-view'
describe "WrapGuide", ->
[rootView, editor, wrapGuide] = []
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
atom.loadPackage('wrap-guide')
rootView.attachToDom()
editor = rootView.getActiveEditor()
wrapGuide = rootView.find('.wrap-guide').view()
afterEach ->
rootView.deactivate()
describe "@initialize", ->
it "appends a wrap guide to all existing and new editors", ->
expect(rootView.panes.find('.pane').length).toBe 1
expect(rootView.panes.find('.underlayer > .wrap-guide').length).toBe 1
editor.splitRight()
expect(rootView.find('.pane').length).toBe 2
expect(rootView.panes.find('.underlayer > .wrap-guide').length).toBe 2
describe "@updateGuide", ->
it "positions the guide at the configured column", ->
width = editor.charWidth * wrapGuide.defaultColumn
expect(width).toBeGreaterThan(0)
expect(wrapGuide.position().left).toBe(width)
describe "when the font size changes", ->
it "updates the wrap guide position", ->
initial = wrapGuide.position().left
expect(initial).toBeGreaterThan(0)
rootView.trigger('window:increase-font-size')
expect(wrapGuide.position().left).toBeGreaterThan(initial)
describe "overriding getGuideColumn", ->
it "invokes the callback with the editor path", ->
editorPath = null
wrapGuide.getGuideColumn = (path) ->
editorPath = path
80
wrapGuide.updateGuide(editor)
expect(editorPath).toBe(require.resolve('fixtures/sample.js'))
it "invokes the callback with a default value", ->
column = null
wrapGuide.getGuideColumn = (path, defaultColumn) ->
editorPath = path
column = defaultColumn
defaultColumn
wrapGuide.updateGuide(editor)
expect(column).toBeGreaterThan(0)
# this is disabled because we no longer support passing config to an extension
# at load time. we need to convert it to use the global config vars.
xit "uses the function from the config data", ->
rootView.find('.wrap-guide').remove()
config =
getGuideColumn: ->
1
atom.loadPackage('wrap-guide', config)
wrapGuide = rootView.find('.wrap-guide').view()
expect(wrapGuide.getGuideColumn).toBe(config.getGuideColumn)
it "hides the guide when the column is less than 1", ->
wrapGuide.getGuideColumn = (path) ->
-1
wrapGuide.updateGuide(editor)
expect(wrapGuide).toBeHidden()

View File

@@ -0,0 +1,40 @@
{View} = require 'space-pen'
module.exports =
class WrapGuide extends View
@activate: (rootView, state, config) ->
requireStylesheet 'wrap-guide.css'
for editor in rootView.getEditors()
if rootView.parents('html').length
@appendToEditorPane(rootView, editor, config)
rootView.on 'editor-open', (e, editor) =>
@appendToEditorPane(rootView, editor, config)
@appendToEditorPane: (rootView, editor, config) ->
if underlayer = editor.pane()?.find('.underlayer')
underlayer.append(new WrapGuide(rootView, editor, config))
@content: ->
@div class: 'wrap-guide'
getGuideColumn: null
defaultColumn: 80
initialize: (@rootView, @editor, options = {}) =>
if typeof options.getGuideColumn is 'function'
@getGuideColumn = options.getGuideColumn
else
@getGuideColumn = (path, defaultColumn) -> defaultColumn
@observeConfig 'editor.fontSize', => @updateGuide(@editor)
@subscribe @editor, 'editor-path-change', => @updateGuide(@editor)
@subscribe @editor, 'before-remove', => @rootView.off('.wrap-guide')
updateGuide: (editor) ->
column = @getGuideColumn(editor.getPath(), @defaultColumn)
if column > 0
@css('left', "#{editor.charWidth * column}px").show()
else
@hide()